JobfairBlacklistController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <?php
  2. namespace App\Admin\Controllers\Jobfair;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\Company;
  5. use App\Models\Jobfair\JobfairBlacklist;
  6. use App\Models\Jobfair\JobfairCompany;
  7. use Encore\Admin\Controllers\HasResourceActions;
  8. use Encore\Admin\Facades\Admin;
  9. use Encore\Admin\Form;
  10. use Encore\Admin\Grid;
  11. use Encore\Admin\Layout\Content;
  12. use Encore\Admin\Show;
  13. use Illuminate\Http\Request;
  14. class JobfairBlacklistController extends Controller
  15. {
  16. use HasResourceActions;
  17. /**
  18. * Index interface.
  19. *
  20. * @param Content $content
  21. * @return Content
  22. */
  23. public function index(Content $content)
  24. {
  25. return $content
  26. ->header('黑名单列表')
  27. ->description('')
  28. ->body(view('admin.jobfair.jobfair_blacklist')->with(['content'=>$this->grid()]));
  29. }
  30. /**
  31. * Show interface.
  32. *
  33. * @param mixed $id
  34. * @param Content $content
  35. * @return Content
  36. */
  37. public function show($id, Content $content)
  38. {
  39. return $content
  40. ->header('黑名单详情')
  41. ->description('')
  42. ->body($this->detail($id));
  43. }
  44. /**
  45. * Edit interface.
  46. *
  47. * @param mixed $id
  48. * @param Content $content
  49. * @return Content
  50. */
  51. public function edit($id, Content $content)
  52. {
  53. return $content
  54. ->header('黑名单编辑')
  55. ->description('')
  56. ->body($this->form()->edit($id));
  57. }
  58. /**
  59. * Create interface.
  60. *
  61. * @param Content $content
  62. * @return Content
  63. */
  64. public function create(Content $content)
  65. {
  66. return $content
  67. ->header('黑名单创建')
  68. ->description('')
  69. ->body(view('admin.jobfair.jobfair_blacklist_add')->with(['content'=>$this->createForm()]));
  70. }
  71. /**
  72. * Make a grid builder.
  73. *
  74. * @return Grid
  75. */
  76. protected function grid()
  77. {
  78. $grid = new Grid(new JobfairBlacklist);
  79. $grid->model()->whereHas('companys');
  80. $grid->column('companys.companyname', '公司名称')->width(200);
  81. $grid->status('状态')->display(function ($status) {
  82. if ($status==1) {
  83. return '<span style="color:#FF6600;">等待解除</span>';
  84. } else {
  85. return '<span style="color: #009900;">已解除</span>';
  86. }
  87. });
  88. $grid->type('类型')->display(function ($type) {
  89. if ($type==1) {
  90. return '系统拉黑';
  91. } else {
  92. return '手动拉黑';
  93. }
  94. });
  95. $grid->details('备注');
  96. $grid->add_time('拉黑时间')->display(function ($add_time) {
  97. return $add_time ? date('Y-m-d H:i:s', $add_time) : '';
  98. });
  99. $grid->remove_time('解除时间')->display(function ($remove_time) {
  100. return $remove_time ? date('Y-m-d H:i:s', $remove_time) : '';
  101. });
  102. $grid->operator('操作人');
  103. $grid->disableExport();
  104. $grid->actions(function ($actions) {
  105. if (Admin::user()->can('jobfair_blacklist_unsealing')) {
  106. if ($actions->row['status']==1) {
  107. $name = '解封';
  108. $status = 2;
  109. $actions->append('<button class="btn btn-primary btn-xs business blackList" ls="'.$status.'" ld="'.$actions->row['id'].'" title="'.$name.'" >'.$name.'</button>');
  110. }
  111. }
  112. });
  113. $grid->tools(function ($tools) use ($grid) {
  114. if (Admin::user()->can('jobfair_blacklist_unsealing')) {
  115. $but = <<<EOT
  116. <div class="btn-group" data-toggle="buttons">
  117. <label class="btn btn-google btn-sm" id="Audit" title="批量解封">
  118. <i class="fa fa-audio-description"></i>
  119. <input type="radio" class="user-gender">批量解封
  120. </label>
  121. </div>
  122. EOT;
  123. $tools->append($but);
  124. }
  125. });
  126. if (Admin::user()->can('jobfair_blacklist_unsealing')) {
  127. $grid->disableRowSelector(false);
  128. }
  129. $grid->filter(function ($filter) {
  130. $filter->like('companys.companyname', '公司名称');
  131. $filter->equal('status', '状态')->select([
  132. 1 => '等待解除',
  133. 2 => '已解除',
  134. ]);
  135. $filter->equal('type', '类型')->select([
  136. 1 => '系统拉黑',
  137. 2 => '手动拉黑',
  138. ]);
  139. });
  140. if (Admin::user()->can('jobfair_blacklist_create')) {
  141. $grid->disableCreateButton(false);
  142. }
  143. return $grid;
  144. }
  145. /**
  146. * Make a show builder.
  147. *
  148. * @param mixed $id
  149. * @return Show
  150. */
  151. protected function detail($id)
  152. {
  153. $show = new Show(JobfairBlacklist::findOrFail($id));
  154. $show->id('ID');
  155. $show->companys()->companyname('公司名称')->as(function ($companys){
  156. return $companys->companyname;
  157. });
  158. $show->status('状态')->as(function ($status) {
  159. if ($status==1) {
  160. return '等待解除';
  161. } else {
  162. return '已解除';
  163. }
  164. });
  165. $show->type('类型')->as(function ($type) {
  166. if ($type==1) {
  167. return '系统拉黑';
  168. } else {
  169. return '手动拉黑';
  170. }
  171. });
  172. $show->details('备注');
  173. $show->add_time('拉黑时间')->as(function ($add_time) {
  174. return $add_time ? date('Y-m-d H:i:s', $add_time) : '';
  175. });
  176. $show->remove_time('解除时间')->as(function ($remove_time) {
  177. return $remove_time ? date('Y-m-d H:i:s', $remove_time) : '';
  178. });
  179. $show->operator('操作人');
  180. $show->created_at('Created at');
  181. $show->updated_at('Updated at');
  182. return $show;
  183. }
  184. /**
  185. * Make a form builder.
  186. *
  187. * @return Form
  188. */
  189. protected function form()
  190. {
  191. $form = new Form(new JobfairBlacklist);
  192. $form->display('ID');
  193. $form->display('Created at');
  194. $form->display('Updated at');
  195. return $form;
  196. }
  197. protected function createForm()
  198. {
  199. $form = new \Encore\Admin\Widgets\Form();//表单使用admin提供的表单
  200. $form->action(route('blacklist.add'));
  201. $JobfairCompany = JobfairCompany::select('company_id')->groupBy('company_id')->get()->toArray();
  202. $companyArr = array_column($JobfairCompany, 'company_id');
  203. $Company = Company::whereIn('id', $companyArr)->select('id', 'companyname')->get()->toArray();
  204. $needAyy = array_column($Company, 'companyname', 'id');
  205. $form->select('company_id', '企业名称')->options($needAyy)->rules([
  206. 'required',
  207. ])->setMustMark();;
  208. $form->textarea('details', '备注')->rules([
  209. 'required',
  210. ])->setMustMark();;
  211. $form->disableReset();
  212. return $form->render();
  213. }
  214. public function blacklistAdd(Request $request)
  215. {
  216. $request->validate([
  217. 'company_id' => 'required',
  218. 'details' => 'required',
  219. ]);
  220. $company_id = $request->company_id;
  221. $details = $request->details;
  222. $JobfairBlacklist = JobfairBlacklist::where(['company_id'=>$company_id])->first();
  223. if ($JobfairBlacklist) {
  224. $blackCompany = JobfairBlacklist::where(['company_id'=>$company_id,'remove_time'=>0,'status'=>1])->first();
  225. if ($blackCompany) {
  226. admin_toastr('该参会企业已在黑名单之列!', 'error');
  227. return back();
  228. }
  229. $result = JobfairBlacklist::where(['company_id'=>$company_id])->update(
  230. ['remove_time'=>0,'status'=>1,'operator'=>admin::user()->username,'details'=>$details]
  231. );
  232. } else {
  233. $result = JobfairBlacklist::create(
  234. ['company_id'=>$company_id,'type'=>2,'details'=>$details,'add_time'=>time(),'operator'=>admin::user()->username]
  235. );
  236. }
  237. if ($result) {
  238. admin_toastr('操作成功!!', 'success');
  239. return redirect(route('blacklist.index'));
  240. } else {
  241. admin_toastr('操作失败!', 'error');
  242. return back();
  243. }
  244. }
  245. public function blacklistDelete(Request $request)
  246. {
  247. $id = $request->id;
  248. $form = new \Encore\Admin\Widgets\Form();
  249. $form->action(route('blacklist.deleted'));
  250. $form->disableReset();
  251. $form->hidden('id', 'ID')->default($id);
  252. $form->textarea('details', '备注');
  253. return json_encode(['html'=>$form->render(),'detail'=>'参会企业解封']);
  254. }
  255. public function blacklistD(Request $request)
  256. {
  257. $blackArr = [];
  258. $company_id = [];
  259. $id = $request->id;
  260. $details = $request->details;
  261. $arr = array_filter(explode(',', $id));
  262. if (empty($id)) {
  263. admin_toastr('数据异常!', 'error');
  264. return back();
  265. }
  266. if (empty($details)) {
  267. admin_toastr('请填写备注!', 'error');
  268. return back();
  269. }
  270. $JobfairBlacklist = JobfairBlacklist::whereIn('id', $arr)->get();
  271. if ($JobfairBlacklist->isEmpty()) {
  272. admin_toastr('数据异常!', 'error');
  273. return back();
  274. } else {
  275. foreach ($JobfairBlacklist as $key => $val) {
  276. if ($val->remove_time==0&&$val->status==1) {
  277. $blackArr[] = $val->id;
  278. $company_id[]=$val->company_id;
  279. }
  280. }
  281. }
  282. \DB::beginTransaction();
  283. try {
  284. JobfairBlacklist::whereIn('id', $blackArr)
  285. ->update(['details'=>$details, 'remove_time'=>time(), 'operator'=>admin::user()->username, 'status'=>2]);
  286. if ($company_id) {
  287. JobfairCompany::whereIn('company_id', $company_id)
  288. ->where('created_at', '<', date('Y-m-d H:i:s', time()))->update(['black_status'=>1]);
  289. }
  290. \DB::commit();
  291. admin_toastr('操作成功!!', 'success');
  292. return redirect(route('blacklist.index'));
  293. } catch (\Exception $e) {
  294. \DB::rollback();
  295. admin_toastr('操作失败!', 'error');
  296. return back();
  297. }
  298. }
  299. }