JobfairoutPutJobsController.php 14 KB

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