JobfairPutJobsController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. <?php
  2. namespace App\Admin\Controllers\Jobfair;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\AuditReason;
  5. use App\Models\Company;
  6. use App\Models\Jobfair\Jobfair;
  7. use App\Models\Jobfair\JobfairJob;
  8. use App\Models\Jobfair\JobfairPutJob;
  9. use App\Models\Pms;
  10. use App\Models\Subsite;
  11. use Encore\Admin\Controllers\HasResourceActions;
  12. use Encore\Admin\Facades\Admin;
  13. use Encore\Admin\Form;
  14. use Encore\Admin\Grid;
  15. use Encore\Admin\Layout\Content;
  16. use Encore\Admin\Show;
  17. use Illuminate\Http\Request;
  18. use App\Admin\Exports\Jobfair\PutJobsExport;
  19. use Illuminate\Support\Facades\Cache;
  20. class JobfairPutJobsController extends Controller
  21. {
  22. use HasResourceActions;
  23. /**
  24. * Index interface.
  25. *
  26. * @param Content $content
  27. * @return Content
  28. */
  29. public function index(Content $content,Request $request)
  30. {
  31. $company_id = isset($request->company_id) ? $request->company_id : false;
  32. $grid=$this->grid($company_id)->render();
  33. return $content
  34. ->header('参会职位')
  35. ->description('')
  36. ->body(view('admin.jobfair.put_jobs')->with(['grid'=>$grid]));
  37. }
  38. /**
  39. * Show interface.
  40. *
  41. * @param mixed $id
  42. * @param Content $content
  43. * @return Content
  44. */
  45. public function show($id, Content $content)
  46. {
  47. return $content
  48. ->header('参会职位详情')
  49. ->description('')
  50. ->body($this->detail($id));
  51. }
  52. /**
  53. * Edit interface.
  54. *
  55. * @param mixed $id
  56. * @param Content $content
  57. * @return Content
  58. */
  59. public function edit($id, Content $content)
  60. {
  61. return $content
  62. ->header('参会职位编辑')
  63. ->description('')
  64. ->body($this->form()->edit($id));
  65. }
  66. /**
  67. * Create interface.
  68. *
  69. * @param Content $content
  70. * @return Content
  71. */
  72. public function create(Content $content)
  73. {
  74. return $content
  75. ->header('参会职位创建')
  76. ->description('description')
  77. ->body($this->form());
  78. }
  79. /**
  80. * Make a grid builder.
  81. *
  82. * @return Grid
  83. */
  84. protected function grid($company_id)
  85. {
  86. $grid = new Grid(new JobfairPutJob);
  87. $grid->model()->when(get_subsite_id()>0, function ($query) {
  88. $query->whereHas('jobfair_company',function($query){
  89. $query->whereHas('subsites', function ($query) {
  90. $query->where('subsite_id', get_subsite_id())->where('subsites.effective', 1);
  91. });
  92. });
  93. })
  94. ->when($company_id==true,function ($query) use ($company_id){
  95. $query->where('company_id',$company_id);
  96. })->whereHas('jobs')
  97. ->orderBy('jobfair_id', 'desc')
  98. ->orderBy('updated_at', 'desc');
  99. $grid->jobs_name('职位名称')->display(function ($jobs_name) {
  100. return '<a href="'.route('jobfair.show.quarters',$this->id) .'" target="_blank">'.$jobs_name.'</a>';
  101. })->width(200);
  102. $grid->company_name('发布公司')->display(function ($company_name) {
  103. return '<a href="'. route('jobs.company',['id'=>$this->company_id]).'" target="_blank">'.$company_name.'</a>';
  104. })->width(200);
  105. $grid->column('jobfairs.title', '招聘会标题')->display(function ($title) {
  106. return "<a href='". route('jobfair.show.com',$this->jobfair_id)."' target='_blank'>".$title."</a>";
  107. })->width(200);
  108. $grid->audit('审核状态')->display(function () {
  109. if ($this->jobs->audit==1) {
  110. return'<span style="color: #009900">审核通过</span>';
  111. } elseif ($this->jobs->audit==3) {
  112. return'<span style="color:#666666">审核未通过</span>';
  113. } else {
  114. return'<span style="color:#FF6600">等待审核</span>';
  115. }
  116. });
  117. $grid->amount('人数')->display(function ($amount){
  118. return $amount ? $amount : '若干';
  119. });
  120. $grid->district_cn('工作地区')->width(150);
  121. if(get_subsite_open()){
  122. $grid->column('jobfairs.subsite_id', '所属分站')->display(function ($subsite_id) {
  123. if ($subsite_id) {
  124. $Subsite = Subsite::find($subsite_id);
  125. return isset($Subsite->sitename) ? $Subsite->sitename : '未知';
  126. }
  127. return '总站';
  128. });
  129. }
  130. $grid->created_at('创建时间');
  131. $grid->actions(function ($actions) use ($grid) {
  132. if (Admin::user()->can('jobfair_put_jobs_delete')) {
  133. $actions->disableDelete(false);
  134. }
  135. });
  136. if (Admin::user()->can('jobfair_put_jobs_delete')) {
  137. $grid->tools(function ($tools) {
  138. $tools->batch(function ($batch) {
  139. $batch->disableDelete(false);
  140. });
  141. });
  142. $grid->disableRowSelector(false);
  143. }
  144. if (Admin::user()->can('jobfair_put_jobs_export')) {
  145. $grid->disableExport(false); //显示导出按钮
  146. $grid->exporter(new PutJobsExport()); //传入自己在第1步创建的导出类
  147. }
  148. // $grid->tools(function ($tools) {
  149. // if (Admin::user()->can('jobfair_put_jobs_audit')) {
  150. // $but = <<<EOT
  151. //<div class="btn-group" data-toggle="buttons">
  152. // <label class="btn btn-google btn-sm" id="Audit_Put_Jobs" title="审核职位">
  153. // <i class="fa fa-audio-description"></i>
  154. // <input type="radio" class="user-gender">审核职位
  155. // </label>
  156. //</div>
  157. //EOT;
  158. // $tools->append($but);
  159. // }
  160. // });
  161. $grid->filter(function ($filter) {
  162. // 去掉默认的id过滤器
  163. $filter->disableIdFilter();
  164. $filter->column(1/2, function ($filter) {
  165. $filter->like('jobs_name', '职位名称');
  166. $filter->equal('jobfair_id', '招聘会')->select(Jobfair::select('title', 'id')->when(get_subsite_id()>0,function ($query){
  167. $query->whereHas('subsites', function ($query) {
  168. $query->where('subsite_jobfairs.subsite_id', get_subsite_id())->where('subsites.effective', 1);
  169. });
  170. })->pluck('title', 'id')->all());
  171. $filter->where(function ($query) {
  172. switch ($this->input) {
  173. case 3:
  174. $query->whereRaw("updated_at>='".date('Y-m-d H:i:s', strtotime('-3 day'))."'");
  175. break;
  176. case 7:
  177. $query->whereRaw("updated_at>='".date('Y-m-d H:i:s', strtotime('-7 day'))."'");
  178. break;
  179. case 30:
  180. $query->whereRaw("updated_at>='".date('Y-m-d H:i:s', strtotime('-30 day'))."'");
  181. break;
  182. }
  183. }, '刷新时间', 'updated_at')->select([
  184. 3=>'三天内',
  185. 7=>'一周内',
  186. 30=>'一月内',
  187. ]);
  188. if(get_subsite_id() == 0 && get_subsite_open()){
  189. $filter->equal('jobfairs.subsite_id', '所属分站')->select(array_column(get_all_subsite(), 'sitename', 'id'));
  190. }
  191. });
  192. $filter->column(1/2, function ($filter) {
  193. $filter->like('company_name', '公司名称');
  194. $filter->where(function ($query) {
  195. switch ($this->input) {
  196. case 1:
  197. $query->whereHas('jobs',function ($query){
  198. $query->where('audit',1);
  199. });
  200. break;
  201. case 2:
  202. $query->whereHas('jobs',function ($query){
  203. $query->where('audit',2);
  204. });
  205. break;
  206. case 3:
  207. $query->whereHas('jobs',function ($query){
  208. $query->where('audit',3);
  209. });
  210. break;
  211. }
  212. }, '审核状态', 'audit')->select([
  213. 1=>'审核通过',
  214. 2=>'等待审核',
  215. 3=>'审核未通过',
  216. ]);
  217. $filter->where(function ($query) {
  218. switch ($this->input) {
  219. case 1:
  220. $query->whereHas('jobs',function ($query){
  221. $query->where('display','1')->where('audit',1);
  222. });
  223. break;
  224. case 2:
  225. $query->whereHas('jobs',function ($query){
  226. $query->where('display','2')->orWhere('audit','<>',1);
  227. });
  228. break;
  229. }
  230. }, '显示状态', 'display')->select([
  231. 1=>'显示',
  232. 2=>'关闭',
  233. ]);
  234. });
  235. });
  236. return $grid;
  237. }
  238. /**
  239. * Make a show builder.
  240. *
  241. * @param mixed $id
  242. * @return Show
  243. */
  244. protected function detail($id)
  245. {
  246. $show = new Show(JobfairPutJob::findOrFail($id));
  247. $show->id('ID');
  248. $show->jobs_name('职位名称')->as(function ($jobs_name) {
  249. return $jobs_name;
  250. });
  251. $show->company_name('发布公司')->as(function ($company_name) {
  252. return $company_name;
  253. });
  254. $show->jobfairs()->title('招聘会标题')->as(function ($jobfairs) {
  255. return $jobfairs->title;
  256. });
  257. $show->audit('审核状态')->as(function () {
  258. if ($this->jobs->audit==1) {
  259. return '审核通过';
  260. } elseif ($this->jobs->audit==3) {
  261. return '审核未通过';
  262. } else {
  263. return '等待审核';
  264. }
  265. });
  266. $show->display('显示状态')->as(function () {
  267. if ($this->jobs->audit==1 && $this->jobs->display==1) {
  268. return '显示';
  269. } else {
  270. return '关闭';
  271. }
  272. });
  273. $show->amount('人数')->as(function ($amount) {
  274. return $amount;
  275. });
  276. $show->district('工作地区')->as(function ($district_cn) {
  277. return $district_cn;
  278. });
  279. $show->jobfairs()->subsite('所属分站')->as(function ($jobfairs) {
  280. if ($jobfairs->subsite_id) {
  281. $Subsite = Subsite::find($jobfairs->subsite_id);
  282. return isset($Subsite->sitename) ? $Subsite->sitename : '未知';
  283. }
  284. return '总站';
  285. });
  286. $show->jobs_content('职位描述')->setEscape(false);
  287. $show->created_at('创建时间');
  288. $show->updated_at('更新时间');
  289. return $show;
  290. }
  291. /**
  292. * Make a form builder.
  293. *
  294. * @return Form
  295. */
  296. protected function form()
  297. {
  298. $form = new Form(new JobfairPutJob);
  299. $form->display('ID');
  300. $form->display('Created at');
  301. $form->display('Updated at');
  302. return $form;
  303. }
  304. public function auditPutJobs(Request $request)
  305. {
  306. $id = $request->id;
  307. $form = new \Encore\Admin\Widgets\Form();
  308. $form->action(route('jobfair.auditPutR'));
  309. $form->disableReset();
  310. $form->hidden('id', 'ID')->default($id);
  311. $form->radio('audit', '审核')->options([1=>'审核通过',3=>'审核未通过'])->default(1);
  312. $form->textarea('remark', '备注');
  313. $form->html('<label style="color: rgb(0, 153, 0)"><input type="checkbox" name="pms_notice" value="1" checked="checked">站内信通知</label>');
  314. return json_encode(['html'=>$form->render(),'detail'=>'审核职位']);
  315. }
  316. public function auditPutR(Request $request)
  317. {
  318. $id = $request->id;
  319. $audit = $request->audit;
  320. $remark = $request->remark;
  321. $pms_notice = $request->pms_notice;
  322. $arr = array_filter(explode(',', $id));
  323. if (empty($id)) {
  324. admin_toastr('数据异常', 'error');
  325. return back();
  326. }
  327. $job_ids = JobfairPutJob::whereIn('id', $arr)->pluck('job_id');
  328. $result = JobfairJob::whereIn('id', $job_ids)->update(['audit'=>$audit]);
  329. foreach ($arr as $k => $v){
  330. $job = JobfairPutJob::where('id', $v)->first();
  331. Cache::put($job->jobfair_id.'-'.$job->company_id, time(),72000);
  332. }
  333. $data=[];
  334. foreach ($arr as $k => $v) {
  335. $data[$k]['type'] = 12;
  336. $data[$k]['type_id'] = $v;
  337. $data[$k]['status'] = $audit;
  338. $data[$k]['reason'] = $remark;
  339. $data[$k]['audit_man'] = Admin::user()->username;
  340. $data[$k]['created_at'] = date('Y-m-d H:i:s', time());
  341. $data[$k]['updated_at'] = date('Y-m-d H:i:s', time());
  342. }
  343. AuditReason::insert($data);
  344. if ($pms_notice) {
  345. if ($audit==3) {
  346. $stat='审核不通过';
  347. } elseif ($audit==1) {
  348. $stat = '审核通过';
  349. } else {
  350. $stat='待审核';
  351. }
  352. $reus=JobfairPutJob::whereIn('id', $arr)->get();
  353. $ds = [];
  354. foreach ($reus as $k => $v) {
  355. $ds[$k]['utype'] = 1;
  356. $ds[$k]['msgtype'] = 1;
  357. $ds[$k]['msgfromuid'] = Admin::user()->id;
  358. $ds[$k]['msgfrom'] = Admin::user()->username;
  359. $ds[$k]['msgtoname'] = $v->company_name ? $v->company_name : 'admin';
  360. $ds[$k]['msgtouid'] = $v->company_id ? $v->company_id : 0;
  361. $ds[$k]['message'] = $remark ? '参会职位(id:'.array_values($arr)[$k].')'.$stat.'<备注:'.$remark.'>' : '参会职位(id:'.array_values($arr)[$k].')'.$stat;
  362. $ds[$k]['created_at'] = date('Y-m-d H:i:s', time());
  363. $ds[$k]['updated_at'] = date('Y-m-d H:i:s', time());
  364. }
  365. Pms::insert($ds);
  366. }
  367. if ($result) {
  368. admin_toastr('审核成功', 'success');
  369. } else {
  370. admin_toastr('审核失败', 'error');
  371. }
  372. return back();
  373. }
  374. }