QuanzhidaController.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <?php
  2. namespace App\Admin\Controllers\Content;
  3. use App\Admin\Extensions\Form\ValidateForm;
  4. use App\Http\Controllers\Controller;
  5. use App\Models\Category;
  6. use App\Models\Quanzhida;
  7. use App\Models\TalentHouse;
  8. use App\Models\TalentHouseApply;
  9. use Encore\Admin\Controllers\HasResourceActions;
  10. use Encore\Admin\Form;
  11. use Encore\Admin\Grid;
  12. use Encore\Admin\Layout\Content;
  13. use Illuminate\Http\Request;
  14. use Illuminate\Support\Facades\DB;
  15. class QuanzhidaController extends Controller
  16. {
  17. use HasResourceActions;
  18. /**
  19. * Index interface.
  20. *
  21. * @param Content $content
  22. * @return Content
  23. */
  24. public function index(Content $content)
  25. {
  26. return $content
  27. ->header('泉职大')
  28. ->description(' ')
  29. ->body(view('admin.content.quanzhida')->with(['grid' => $this->grid()]));
  30. }
  31. /**
  32. * Edit interface.
  33. *
  34. * @param mixed $id
  35. * @param Content $content
  36. * @return Content
  37. */
  38. public function edit($id, Content $content)
  39. {
  40. return $content
  41. ->header('岗位')
  42. ->description(' ')
  43. ->body($this->editForm($id)->edit($id));
  44. }
  45. /**
  46. * Create interface.
  47. *
  48. * @param Content $content
  49. * @return Content
  50. */
  51. public function create(Content $content)
  52. {
  53. return $content
  54. ->header('岗位')
  55. ->description(' ')
  56. ->body($this->form());
  57. }
  58. /**
  59. * Make a grid builder.
  60. *
  61. * @return Grid
  62. */
  63. protected function grid()
  64. {
  65. $grid = new Grid(new Quanzhida());
  66. $grid->model()->orderBy('updated_at', 'DESC');
  67. $grid->id('ID');
  68. $grid->company_name('公司名称');
  69. $grid->job_name('岗位名称');
  70. $grid->industry('行业领域');
  71. $grid->created_at('创建时间');
  72. //新增按钮
  73. $grid->disableCreateButton(false);
  74. //批量删除
  75. $grid->tools(function ($tools) {
  76. $tools->batch(function ($batch) {
  77. $batch->disableDelete(false);
  78. });
  79. });
  80. $grid->actions(function ($actions) {
  81. $actions->disableEdit(false);
  82. $actions->disableDelete(false);
  83. });
  84. $grid->filter(function ($filter) {
  85. $filter->disableIdFilter();
  86. $filter->like('company_name', '公司名称');
  87. $filter->like('job_name', '岗位名称');
  88. });
  89. return $grid;
  90. }
  91. /**
  92. * Make a form builder.
  93. *
  94. * @return Form
  95. */
  96. protected function form()
  97. {
  98. $form = new ValidateForm(new Quanzhida());
  99. $form->text('company_name', '公司名称')->rules('required|max:100', ['required' => '公司名称不能为空。', 'max' => '公司名称不能大于100。'])->setWidth(4)->setMustMark();
  100. $form->text('job_name', '岗位名称')->rules('required|max:60', ['required' => '岗位名称不能为空。', 'max' => '岗位名称不能大于60。'])->setWidth(4)->setMustMark();
  101. $form->number('wage_min', '最小薪资')->rules('required', ['required' => '最小薪资不能为空。若未确定,请填0'])->setWidth(4)->setMustMark();
  102. $form->number('wage_max', '最大薪资')->rules('required', ['required' => '最大薪资不能为空。若未确定,请填0'])->setWidth(4)->setMustMark();
  103. $form->text('industry', '所属行业领域')->rules('required|max:60', ['required' => '所属行业领域不能为空。', 'max' => '所属行业领域不能大于60。'])->setWidth(4)->setMustMark();
  104. $education = Category::where('alias','AIX_education')->pluck('demand','id');
  105. $education[0] = '不限';
  106. $form->select('education', '学历')->setWidth(4)->options($education)->setMustMark();
  107. $experience = Category::where('alias','AIX_experience')->pluck('demand','id');
  108. $experience[0] = '不限';
  109. $form->select('experience', '工作经验')->setWidth(4)->options($experience)->setMustMark();
  110. $form->text('region', '工作地点')->rules('required|max:60', ['required' => '工作地点不能为空。', 'max' => '工作地点不能大于60。'])->setWidth(4)->setMustMark();
  111. $form->footer(function ($footer) {
  112. $footer->disableViewCheck();
  113. $footer->disableEditingCheck();
  114. $footer->disableCreatingCheck();
  115. $footer->disableReset();
  116. });
  117. return $form;
  118. }
  119. protected function editForm($id)
  120. {
  121. $form = new ValidateForm(new Quanzhida());
  122. $form->text('company_name', '公司名称')->rules('required|max:100', ['required' => '公司名称不能为空。', 'max' => '公司名称不能大于100。'])->setWidth(4)->setMustMark();
  123. $form->text('job_name', '岗位名称')->rules('required|max:60', ['required' => '岗位名称不能为空。', 'max' => '岗位名称不能大于60。'])->setWidth(4)->setMustMark();
  124. $form->number('wage_min', '最小薪资')->rules('required', ['required' => '最小薪资不能为空。若未确定,请填0'])->setWidth(4)->setMustMark();
  125. $form->number('wage_max', '最大薪资')->rules('required', ['required' => '最大薪资不能为空。若未确定,请填0'])->setWidth(4)->setMustMark();
  126. $form->text('industry', '所属行业领域')->rules('required|max:60', ['required' => '所属行业领域不能为空。', 'max' => '所属行业领域不能大于60。'])->setWidth(4)->setMustMark();
  127. $education = Category::where('alias','AIX_education')->pluck('demand','id');
  128. $education[0] = '不限';
  129. $form->select('education', '学历')->setWidth(4)->options($education)->setMustMark();
  130. $experience = Category::where('alias','AIX_experience')->pluck('demand','id');
  131. $experience[0] = '不限';
  132. $form->select('experience', '工作经验')->setWidth(4)->options($experience)->setMustMark();
  133. $form->text('region', '工作地点')->rules('required|max:60', ['required' => '工作地点不能为空。', 'max' => '工作地点不能大于60。'])->setWidth(4)->setMustMark();
  134. $form->footer(function ($footer) {
  135. $footer->disableViewCheck();
  136. $footer->disableEditingCheck();
  137. $footer->disableCreatingCheck();
  138. $footer->disableReset();
  139. });
  140. $form->tools(function (Form\Tools $tools) {
  141. $tools->disableDelete();
  142. $tools->disableView();
  143. });
  144. return $form;
  145. }
  146. public function update($id)
  147. {
  148. return $this->editForm($id)->update($id);
  149. }
  150. public function destroy($id)
  151. {
  152. if ($this->form()->destroy($id)) {
  153. $data = [
  154. 'status' => true,
  155. 'message' => trans('admin.delete_succeeded'),
  156. ];
  157. } else {
  158. $data = [
  159. 'status' => false,
  160. 'message' => trans('admin.delete_failed'),
  161. ];
  162. }
  163. return response()->json($data);
  164. }
  165. /**
  166. * 导出
  167. */
  168. public function export(Request $request)
  169. {
  170. //数据获取
  171. $id = $request->id;
  172. $status = $request->status;
  173. $house = TalentHouse::find($id);
  174. $query = TalentHouseApply::with(['house', 'idcard'])
  175. ->where('house_id', $id)
  176. ->where('is_back', 2)
  177. ->where('is_draft', 2)
  178. ->orderByRaw(DB::raw("FIELD(talent_level,'第一层次','第二层次','第三层次','第四层次','第五层次','第六层次','第七层次') asc"));
  179. if ($status == 1) {
  180. $filename = $house['name'] . '审核不通过名单.xls';
  181. $query = $query->whereIn('status', [1, 3, 4]);
  182. } else {
  183. $filename = $house['name'] . '审核通过名单.xls';
  184. $query = $query->where('status', 2);
  185. }
  186. $data = $query->get();
  187. if ($data->isEmpty()) {
  188. return '暂无数据';
  189. }
  190. //数据处理
  191. $status = ['', '待审核', '审核通过', '审核驳回', '审核不通过'];
  192. $marry = ['未知', '未婚', '已婚', '离异', '丧偶'];
  193. $type = ['', '优秀人才', '集成电路优秀人才'];
  194. $no = 1;
  195. foreach ($data as $row) {
  196. $family = empty($row->family) ? '' : json_decode($row->family, true);
  197. if (!empty($family)) {
  198. $relation = [];
  199. $child = [];
  200. $id_card = [];
  201. foreach ($family as $v) {
  202. $relation[] = $v['relation'];
  203. $child[] = $v['realname'];
  204. $id_card[] = $v['idcard'];
  205. }
  206. $row['relation'] = implode('/', $relation);
  207. $row['relation_name'] = implode('/', $child);
  208. $row['relation_id_card'] = implode('/', $id_card);
  209. }
  210. $row['no'] = $no;
  211. $no++;
  212. $row['marry_text'] = $marry[$row['marry']];
  213. $row['type_text'] = $type[$row['type']];
  214. }
  215. header("Content-type: application/vnd.ms-excel; charset=utf-8");
  216. header("Content-Disposition: attachment; filename=$filename");
  217. $view = view('admin.content.export_house_result')->with(['data' => $data, 'house' => $house, 'status' => $status]);
  218. $str = response($view)->getContent();
  219. echo $str;
  220. exit;
  221. }
  222. }