JobfairDishonestyController.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. namespace App\Admin\Controllers\Jobfair;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\Jobfair\JobfairCompany;
  5. use Encore\Admin\Controllers\HasResourceActions;
  6. use Encore\Admin\Facades\Admin;
  7. use Encore\Admin\Form;
  8. use Encore\Admin\Grid;
  9. use Encore\Admin\Layout\Content;
  10. use Encore\Admin\Show;
  11. class JobfairDishonestyController extends Controller
  12. {
  13. use HasResourceActions;
  14. /**
  15. * Index interface.
  16. *
  17. * @param Content $content
  18. * @return Content
  19. */
  20. public function index(Content $content)
  21. {
  22. return $content
  23. ->header('不诚信记录')
  24. ->description('')
  25. ->body($this->grid());
  26. }
  27. /**
  28. * Show interface.
  29. *
  30. * @param mixed $id
  31. * @param Content $content
  32. * @return Content
  33. */
  34. public function show($id, Content $content)
  35. {
  36. return $content
  37. ->header('不诚信记录详情')
  38. ->description('')
  39. ->body($this->detail($id));
  40. }
  41. /**
  42. * Edit interface.
  43. *
  44. * @param mixed $id
  45. * @param Content $content
  46. * @return Content
  47. */
  48. public function edit($id, Content $content)
  49. {
  50. return $content
  51. ->header('不诚信记录编辑')
  52. ->description('')
  53. ->body($this->form()->edit($id));
  54. }
  55. /**
  56. * Create interface.
  57. *
  58. * @param Content $content
  59. * @return Content
  60. */
  61. public function create(Content $content)
  62. {
  63. return $content
  64. ->header('不诚信记录创建')
  65. ->description('')
  66. ->body($this->form());
  67. }
  68. /**
  69. * Make a grid builder.
  70. *
  71. * @return Grid
  72. */
  73. protected function grid()
  74. {
  75. $grid = new Grid(new JobfairCompany);
  76. $grid->model()->with(['companys','jobfair'])->whereHas('companys')->whereHas('jobfair',function ($query) {
  77. $query->where('holddate_start','<',strtotime("-30 seconds"));
  78. })->where('type', '<>', 4)->where('audit',1)
  79. // ->groupBy('company_id', 'jobfair_id')
  80. ->orderBy('id', 'desc');
  81. $grid->column('companys.companyname', '公司名称')->width(200);
  82. $grid->column('jobfair.title', '招聘会名称')->width(200);
  83. $grid->column('jobfair.holddate_start', '招聘会开始时间')->display(function ($holddate_start) {
  84. return date('Y-m-d H:i:s', $holddate_start);
  85. });
  86. $grid->column('jobfair.holddate_end', '招聘会结束时间')->display(function ($holddate_end) {
  87. return date('Y-m-d H:i:s', $holddate_end);
  88. });
  89. $grid->type('行为')->display(function ($type) {
  90. if ($type==0) {
  91. return '未签到';
  92. } elseif ($type==1) {
  93. return '迟到';
  94. } elseif ($type==2) {
  95. return '早退';
  96. } elseif ($type==3) {
  97. return '迟到/早退';
  98. } else {
  99. return '未签到';
  100. }
  101. });
  102. $grid->signed_time('签到时间')->display(function ($signed_time) {
  103. return $signed_time ? date('Y-m-d H:i:s', $signed_time) : '';
  104. });
  105. $grid->over_time('注销时间')->display(function ($over_time) {
  106. return $over_time ? date('Y-m-d H:i:s', $over_time) : '';
  107. });
  108. $grid->disableCreateButton();
  109. $grid->disableExport();
  110. $grid->actions(function ($actions) use ($grid) {
  111. if (Admin::user()->can('jobfair_dishonesty_delete')) {
  112. $actions->disableDelete(false);
  113. }
  114. });
  115. if (Admin::user()->can('jobfair_dishonesty_delete')) {
  116. $grid->tools(function ($tools) {
  117. $tools->batch(function ($batch) {
  118. $batch->disableDelete(false);
  119. });
  120. });
  121. $grid->disableRowSelector(false);
  122. }
  123. $grid->filter(function ($filter) {
  124. $filter->like('companys.companyname', '公司名称');
  125. $filter->like('jobfair.title', '招聘会名称');
  126. });
  127. return $grid;
  128. }
  129. /**
  130. * Make a show builder.
  131. *
  132. * @param mixed $id
  133. * @return Show
  134. */
  135. protected function detail($id)
  136. {
  137. $show = new Show(JobfairCompany::findOrFail($id));
  138. $show->id('ID');
  139. $show->companys()->companyname('公司名称')->as(function ($companys){
  140. return $companys->companyname;
  141. });
  142. $show->jobfair()->title('招聘会名称')->as(function ($jobfair){
  143. return $jobfair->title;
  144. });
  145. $show->jobfair()->holddate_start('招聘会开始时间')->as(function ($jobfair) {
  146. return date('Y-m-d H:i:s', $jobfair->holddate_start);
  147. });
  148. $show->jobfair()->holddate_end('招聘会结束时间')->as(function ($jobfair) {
  149. return date('Y-m-d H:i:s', $jobfair->holddate_end);
  150. });
  151. $show->type('行为')->as(function ($type) {
  152. if ($type==0) {
  153. return '未签到';
  154. } elseif ($type==1) {
  155. return '迟到';
  156. } elseif ($type==2) {
  157. return '早退';
  158. } elseif ($type==3) {
  159. return '迟到/早退';
  160. } else {
  161. return '未签到';
  162. }
  163. });
  164. $show->signed_time('签到时间')->as(function ($signed_time) {
  165. return $signed_time ? date('Y-m-d H:i:s', $signed_time) : '';
  166. });
  167. $show->over_time('注销时间')->as(function ($over_time) {
  168. return $over_time ? date('Y-m-d H:i:s', $over_time) : '';
  169. });
  170. $show->created_at('创建时间');
  171. $show->updated_at('更新时间');
  172. return $show;
  173. }
  174. /**
  175. * Make a form builder.
  176. *
  177. * @return Form
  178. */
  179. protected function form()
  180. {
  181. $form = new Form(new JobfairCompany);
  182. $form->display('ID');
  183. $form->display('Created at');
  184. $form->display('Updated at');
  185. return $form;
  186. }
  187. public function destroy($id)
  188. {
  189. $ids = array();
  190. if ($id) {
  191. $ids = explode(',', $id);
  192. }
  193. if (!$ids) {
  194. return admin_toastr('请勾选需要删除的职位', 'error');
  195. }
  196. \DB::beginTransaction();
  197. try {
  198. JobfairCompany::whereIn('id', $ids)->update(['type'=>4]);
  199. $data = [
  200. 'status' => true,
  201. 'message' => '删除成功!',
  202. ];
  203. \DB::commit();
  204. return response()->json($data);
  205. } catch (\Exception $e) {
  206. \DB::rollback();
  207. $data = [
  208. 'status' => false,
  209. 'message' => '删除失败!',
  210. ];
  211. return response()->json($data);
  212. }
  213. }
  214. }