JobsApplyController.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. <?php
  2. namespace App\Admin\Controllers\Person;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\Jobs;
  5. use App\Models\MemberInfo;
  6. use App\Models\PersonalJobsApply;
  7. use App\Models\Resume;
  8. use App\Models\Subsite;
  9. use App\Repositories\JobsRepository;
  10. use App\Repositories\PersonJobsApplyRepository;
  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. class JobsApplyController extends Controller
  18. {
  19. use HasResourceActions;
  20. /**
  21. * Index interface.
  22. *
  23. * @param Content $content
  24. * @return Content
  25. */
  26. public function index(Content $content)
  27. {
  28. return $content
  29. ->header('申请职位')
  30. ->description('列表')
  31. ->body($this->grid());
  32. }
  33. /**
  34. * Show interface.
  35. *
  36. * @param mixed $id
  37. * @param Content $content
  38. * @return Content
  39. */
  40. public function show($id, Content $content)
  41. {
  42. return $content
  43. ->header('申请职位')
  44. ->description('详细')
  45. ->body($this->detail($id));
  46. }
  47. /**
  48. * Edit interface.
  49. *
  50. * @param mixed $id
  51. * @param Content $content
  52. * @return Content
  53. */
  54. public function edit($id, Content $content)
  55. {
  56. return $content
  57. ->header('申请职位')
  58. ->description('编辑')
  59. ->body($this->editForm($id)->edit($id));
  60. }
  61. /**
  62. * Create interface.
  63. *
  64. * @param Content $content
  65. * @return Content
  66. */
  67. public function create(Content $content)
  68. {
  69. return $content
  70. ->header('申请职位')
  71. ->description('创建')
  72. ->body($this->createForm());
  73. }
  74. /**
  75. * Make a grid builder.
  76. *
  77. * @return Grid
  78. */
  79. protected function grid()
  80. {
  81. $grid = new Grid(new PersonalJobsApply);
  82. $grid->model()->when(get_subsite_id()>0, function ($query) {
  83. $query->whereHas('resumes', function ($query) {
  84. $query->where('subsite_id', get_subsite_id());
  85. });
  86. })->orderBy('id', 'desc');
  87. $grid->id('ID');
  88. $grid->jobs_name('职位名称')->width(200);
  89. $grid->company_name('公司名称')->width(200);
  90. $grid->resume_name('简历名称')->width(150);
  91. $grid->is_reply('反馈状态')->display(function ($is_reply) {
  92. switch ($is_reply) {
  93. case 1:
  94. $is_reply = '企业未查看';
  95. break;
  96. case 2:
  97. $is_reply = '待反馈';
  98. break;
  99. case 3:
  100. $is_reply = '合适';
  101. break;
  102. case 4:
  103. $is_reply = '不合适';
  104. break;
  105. case 5:
  106. $is_reply = '待定';
  107. break;
  108. case 6:
  109. $is_reply = '未接通';
  110. break;
  111. default:
  112. $is_reply = '企业未查看';
  113. break;
  114. }
  115. return $is_reply;
  116. });
  117. $grid->column('members.subsite_id', '所属分站')->display(function ($subsite_id) {
  118. if ($subsite_id) {
  119. $Subsite = Subsite::find($subsite_id);
  120. return isset($Subsite->sitename) ? $Subsite->sitename : '未知';
  121. }
  122. return '总站';
  123. })->width(150);
  124. $grid->created_at('申请时间')->sortable();
  125. $grid->updated_at('更新时间')->sortable();
  126. $grid->actions(function ($actions) use ($grid) {
  127. if (Admin::user()->can('person_apply_jobs_delete')) {
  128. $actions->disableDelete(false);
  129. }
  130. });
  131. if (Admin::user()->can('person_apply_jobs_delete')) {
  132. $grid->tools(function ($tools) {
  133. $tools->batch(function ($batch) {
  134. $batch->disableDelete(false);
  135. });
  136. });
  137. $grid->disableRowSelector(false);
  138. }
  139. $grid->filter(function ($filter) {
  140. $filter->disableIdFilter();
  141. $filter->where(function ($query) {
  142. switch ($this->input) {
  143. case 1:
  144. $query->whereRaw(" is_reply =".$this->input);
  145. break;
  146. case 2:
  147. $query->whereRaw(" is_reply =".$this->input);
  148. break;
  149. case 3:
  150. $query->whereRaw(" is_reply =".$this->input);
  151. break;
  152. case 4:
  153. $query->whereRaw(" is_reply =".$this->input);
  154. break;
  155. case 5:
  156. $query->whereRaw(" is_reply =".$this->input);
  157. break;
  158. case 6:
  159. $query->whereRaw(" is_reply =".$this->input);
  160. break;
  161. }
  162. }, '申请反馈', 'inter')->select([
  163. 1=>'企业未查看',
  164. 2=>'待反馈',
  165. 3=>'合适',
  166. 4=>'不合适',
  167. 5=>'待定',
  168. 6=>'未接通',
  169. ]);
  170. $filter->where(function ($query) {
  171. switch ($this->input) {
  172. case 3:
  173. $date = date('Y-m-d H:i:s', strtotime('-3 day'));
  174. $query->whereRaw(" created_at >='".$date."'");
  175. break;
  176. case 7:
  177. $date = date('Y-m-d H:i:s', strtotime('-7 day'));
  178. $query->whereRaw(" created_at >='".$date."'");
  179. break;
  180. case 30:
  181. $date = date('Y-m-d H:i:s', strtotime('-30 day'));
  182. $query->whereRaw(" created_at >='".$date."'");
  183. break;
  184. case 180:
  185. $date = date('Y-m-d H:i:s', strtotime('-180 day'));
  186. $query->whereRaw(" created_at >='".$date."'");
  187. break;
  188. case 365:
  189. $date = date('Y-m-d H:i:s', strtotime('-365 day'));
  190. $query->whereRaw(" created_at >='".$date."'");
  191. break;
  192. }
  193. }, '申请时间', 'apply')->select([
  194. 3=>'三天内',
  195. 7=>'一周内',
  196. 30=>'一月内',
  197. 180=>'半年内',
  198. 365=>'一年内',
  199. ]);
  200. $filter->like('company_name', '公司名称');
  201. $filter->like('resume_name', '简历名称 ');
  202. $filter->equal('personal_uid', '个人会员ID ');
  203. if(get_subsite_id()==0){
  204. $filter->equal('members.subsite_id', '所属分站')->select(array_column(get_all_subsite(), 'sitename', 'id'));
  205. }
  206. });
  207. return $grid;
  208. }
  209. /**
  210. * Make a show builder.
  211. *
  212. * @param mixed $id
  213. * @return Show
  214. */
  215. protected function detail($id)
  216. {
  217. $show = new Show(PersonalJobsApply::findOrFail($id));
  218. $show->id('ID');
  219. $show->jobs_name('职位名称');
  220. $show->company_name('公司名称');
  221. $show->resume_name('简历名称');
  222. $show->is_reply('反馈状态')->as(function ($is_reply) {
  223. switch ($is_reply) {
  224. case 1:
  225. $is_reply = '企业未查看';
  226. break;
  227. case 2:
  228. $is_reply = '待反馈';
  229. break;
  230. case 3:
  231. $is_reply = '合适';
  232. break;
  233. case 4:
  234. $is_reply = '不合适';
  235. break;
  236. case 5:
  237. $is_reply = '待定';
  238. break;
  239. case 6:
  240. $is_reply = '未接通';
  241. break;
  242. default:
  243. $is_reply = '企业未查看';
  244. break;
  245. }
  246. return $is_reply;
  247. });
  248. $show->members('所属分站')->as(function ($members) {
  249. if ($members->subsite_id) {
  250. $Subsite = Subsite::find($members->subsite_id);
  251. return isset($Subsite->sitename) ? $Subsite->sitename : '未知';
  252. }
  253. return '总站';
  254. });
  255. $show->created_at('添加时间');
  256. $show->updated_at('更新时间');
  257. return $show;
  258. }
  259. /**
  260. * Make a form builder.
  261. *
  262. * @return Form
  263. */
  264. protected function form()
  265. {
  266. $form = new Form(new PersonalJobsApply);
  267. $form->display('id');
  268. $form->display('created_at');
  269. $form->display('updated_at');
  270. return $form;
  271. }
  272. /**
  273. * Make a form builder.
  274. *
  275. * @return Form
  276. */
  277. protected function editForm($id)
  278. {
  279. $form = new Form(new PersonalJobsApply);
  280. $form->setAction(route('admin.personal.addPoints'));
  281. $MembersHandsel = MembersHandsel::findOrFail($id);
  282. $utype = $MembersHandsel->utype;
  283. $points = MembersHandsel::find($id)->membersPoints()->where('utype', $utype)->first();
  284. $form->display('points_num', '会员积分')->with(function () use ($points) {
  285. return $points->points;
  286. });
  287. $form->radio('points_type', '操作积分')->options([1 => '增加', 2=> '减少'])->default(1);
  288. $form->number('many_point', '增减积分')->default(0)->min(0);
  289. $form->text('explain', '操作说明');
  290. $form->switch('ismany', '是否收费?');
  291. $form->number('amount', '收费金额')->default(0)->min(0);
  292. $form->hidden('points_id')->default($points->id);
  293. $form->footer(function ($footer) {
  294. // 去掉`重置`按钮
  295. $footer->disableReset();
  296. // 去掉`查看`checkbox
  297. $footer->disableViewCheck();
  298. // 去掉`继续编辑`checkbox
  299. $footer->disableEditingCheck();
  300. // 去掉`继续创建`checkbox
  301. $footer->disableCreatingCheck();
  302. });
  303. $form->tools(function (Form\Tools $tools) {
  304. // 去掉`删除`按钮
  305. $tools->disableDelete();
  306. });
  307. return $form;
  308. }
  309. protected function createForm()
  310. {
  311. $form = new Form(new PersonalJobsApply);
  312. $form->display('id');
  313. $form->display('created_at');
  314. $form->display('updated_at');
  315. return $form;
  316. }
  317. /**
  318. * Store a newly created resource in storage.
  319. *
  320. * @return mixed
  321. */
  322. public function store()
  323. {
  324. return $this->createForm()->store();
  325. }
  326. /**
  327. * Update the specified resource in storage.
  328. *
  329. * @param int $id
  330. *
  331. * @return \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response
  332. */
  333. public function update($id)
  334. {
  335. return $this->editForm()->update($id);
  336. }
  337. public function applyJobs(Content $content)
  338. {
  339. $id = request()->id;
  340. $uid = request()->uid;
  341. $resume = Resume::where(['id'=>$id])->first();
  342. $member = MemberInfo::where(['uid'=>$uid])->first();
  343. return $content
  344. ->header('职位匹配')
  345. ->description('列表')
  346. ->body(view('admin.jobs.find_jobs')->with(['grid'=>$this->gridApply(),'resume'=>$resume,'member'=>$member]));
  347. }
  348. /**
  349. * Make a grid builder.
  350. *
  351. * @return Grid
  352. */
  353. protected function gridApply()
  354. {
  355. $grid = new Grid(new Jobs);
  356. $grid->model()->where('valid',1)->where('display',1)->whereIn('audit', getJobsStatus())->orderBy('id', 'desc');
  357. $grid->id('ID');
  358. $grid->jobs_name('职位名称');
  359. $grid->company_name('公司名称');
  360. $grid->audit('审核状态')->display(function ($audit) {
  361. switch ($audit) {
  362. case 1:
  363. $audit = '<span style="color: #00a65a;">审核通过</span>';
  364. break;
  365. case 2:
  366. $audit = '<span>审核中</span>';
  367. break;
  368. case 3:
  369. $audit = '<span style="color: red;">审核未通过</span>';
  370. break;
  371. default:
  372. $audit = '<span>审核中</span>';
  373. break;
  374. }
  375. return $audit;
  376. });
  377. $grid->column('categoryScale.demand', '公司规模');
  378. $grid->column('categoryTrade.demand', '所属行业');
  379. $grid->column('categoryEducation.demand', '职位要求');
  380. $grid->column('categoryWage.demand', '薪资待遇');
  381. $grid->created_at('添加时间')->sortable();
  382. $grid->updated_at('更新时间')->sortable();
  383. $grid->disableCreateButton();
  384. $grid->disableExport();
  385. $grid->disableActions();
  386. $grid->tools(function ($tools) {
  387. $but = <<<EOT
  388. <div class="btn-group" data-toggle="buttons">
  389. <label class="btn btn-google btn-sm" id="Apply" title="投递">
  390. <i class="fa fa-audio-description"></i>
  391. <input type="radio" class="user-gender">投递
  392. </label>
  393. </div>
  394. EOT;
  395. $tools->append($but);
  396. });
  397. $grid->filter(function ($filter) {
  398. // 去掉默认的id过滤器
  399. $filter->disableIdFilter();
  400. $filter->column(1/2, function ($filter) {
  401. $filter->like('jobs_name', '职位名称');
  402. });
  403. $filter->column(1/2, function ($filter) {
  404. $filter->like('company_name', '公司名称');
  405. });
  406. });
  407. return $grid;
  408. }
  409. public function applyCompanyJobs(PersonJobsApplyRepository $personJobsApplyRepository, JobsRepository $jobsRepository)
  410. {
  411. $jobs_id = request()->jobs_id;
  412. $resume_id = request()->resume_id;
  413. $resume_name = request()->resume_name;
  414. $personal_uid = request()->personal_uid;
  415. if (empty($jobs_id)) {
  416. return json_encode(['code'=>0,'info'=>'职位信息不存在!']);
  417. }
  418. $resume = Resume::find($resume_id);
  419. if (!$resume) {
  420. return json_encode(['code'=>0,'info'=>'简历不存在!']);
  421. }
  422. $resume_display = config('aix.personal_set.per_set.show_set.resume_display');
  423. if ($resume_display!=2) {
  424. if ($resume->audit!=2) {
  425. return json_encode(['code'=>0,'info'=>'审核中或审核未通过的简历无法投递!']);
  426. }
  427. } else {
  428. if ($resume->audit==0) {
  429. return json_encode(['code'=>0,'info'=>'审核未通过的简历无法投递!']);
  430. }
  431. }
  432. if ($resume->display!=1) {
  433. return json_encode(['code'=>0,'info'=>'简历已关闭,无法投递!']);
  434. }
  435. $defaultPre = config('aix.personal_set.per_set.per_set.apply_job_min_percent');
  436. if ($defaultPre) {
  437. if ($resume->complete_percent<$defaultPre) {
  438. return json_encode(['code'=>0,'info'=>'您的简历完整度小于'.$defaultPre.'%,无法投递!']);
  439. }
  440. }
  441. $todayCount = $personJobsApplyRepository->getTodayCount($resume->uid);
  442. if ($todayCount>=config('aix.personal_set.per_set.per_set.apply_jobs_max')) {
  443. return json_encode(['code'=>0,'info'=>"您每天可以投递".config('aix.personal_set.per_set.per_set.apply_jobs_max')."个职位,今天已投递了{$todayCount}个"]);
  444. }
  445. $id = array_filter(explode(',', $jobs_id));
  446. $displayJobs = $jobsRepository->getDisplayJobs($id, 2);
  447. if (!empty($displayJobs)) {
  448. $disJobs = array_diff($id, array_column($displayJobs, 'id'));
  449. if (empty($disJobs)) {
  450. return json_encode(['code'=>0,'info'=>'您投递的职位已关闭!']);
  451. }
  452. $id = $disJobs;
  453. }
  454. $jobsApply = $personJobsApplyRepository->personApplyByTime(
  455. $id,
  456. $resume->uid,
  457. config('aix.personal_set.per_set.per_set.apply_job_space')
  458. );
  459. if (!empty($jobsApply)) {
  460. $disApply = array_diff($id, array_column($jobsApply, 'jobs_id'));
  461. if (empty($disApply)) {
  462. return json_encode(['code'=>0,'info'=>'您已经申请过这个职位了!']);
  463. }
  464. $id = $disApply;
  465. }
  466. $jobs = $jobsRepository->getJobs($id);
  467. $arr = [];
  468. foreach ($jobs as $key => $val) {
  469. $arr[$key]['resume_id'] = $resume_id;
  470. $arr[$key]['resume_name'] = $resume_name;
  471. $arr[$key]['personal_uid'] = $personal_uid;
  472. $arr[$key]['jobs_id'] = $val->id;
  473. $arr[$key]['jobs_name'] = $val->jobs_name;
  474. $arr[$key]['company_id'] = $val->company_id;
  475. $arr[$key]['company_name'] = $val->company_name;
  476. $arr[$key]['is_apply'] = 2;
  477. $arr[$key]['created_at'] = date('Y-m-d H:i:s', time());
  478. $arr[$key]['updated_at'] = date('Y-m-d H:i:s', time());
  479. }
  480. $res = PersonalJobsApply::insert($arr);
  481. if ($res) {
  482. return json_encode(['code'=>1,'info'=>'投递成功!']);
  483. } else {
  484. return json_encode(['code'=>0,'info'=>'投递失败!']);
  485. }
  486. }
  487. }