PersonalTalentsController.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. <?php
  2. namespace App\Admin\Controllers\PersonalTalents;
  3. use App\Admin\Exports\PersonalTalents\PersonalTalentsExport;
  4. use App\Models\Admin\AdminUser;
  5. use App\Models\Category;
  6. use App\Models\Company;
  7. use App\Models\PersonalTalents;
  8. use App\Models\PersonalTalentsLog;
  9. use App\Http\Controllers\Controller;
  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 App\Repositories\CategoryRepository;
  17. use App\Repositories\CategoryMajorRepository;
  18. use App\Services\Person\ResumeService;
  19. use Encore\Admin\Widgets\Table;
  20. use Illuminate\Http\Request;
  21. class PersonalTalentsController extends Controller
  22. {
  23. use HasResourceActions;
  24. protected $CategoryRepository;
  25. protected $CategoryMajorRepository;
  26. protected $ResumeService;
  27. protected $role_id_1 = 30;
  28. public function __construct(CategoryRepository $CategoryRepository, CategoryMajorRepository $CategoryMajorRepository, ResumeService $ResumeService)
  29. {
  30. $this->CategoryRepository = $CategoryRepository;
  31. $this->CategoryMajorRepository = $CategoryMajorRepository;
  32. $this->ResumeService = $ResumeService;
  33. }
  34. /**
  35. * Index interface.
  36. *
  37. * @param Content $content
  38. * @return Content
  39. */
  40. public function index(Content $content)
  41. {
  42. $grid = $this->grid()->render();
  43. return $content
  44. ->header('人才服务')
  45. ->description('人才服务列表')
  46. // ->body($this->grid());
  47. ->body(view('admin.personalTalents.index')->with('grid', $grid));
  48. }
  49. /**
  50. * Show interface.
  51. *
  52. * @param mixed $id
  53. * @param Content $content
  54. * @return Content
  55. */
  56. public function show($id, Content $content)
  57. {
  58. return $content
  59. ->header('人才服务')
  60. ->description('人才服务详情')
  61. ->body($this->detail($id));
  62. }
  63. /**
  64. * Edit interface.
  65. *
  66. * @param mixed $id
  67. * @param Content $content
  68. * @return Content
  69. */
  70. public function edit($id, Content $content)
  71. {
  72. return $content
  73. ->header('人才服务')
  74. ->description('人才服务编辑')
  75. ->body($this->editForm($id)->edit($id));
  76. }
  77. /**
  78. * Create interface.
  79. *
  80. * @param Content $content
  81. * @return Content
  82. */
  83. public function create(Content $content)
  84. {
  85. return $content
  86. ->header('Create')
  87. ->description('description')
  88. ->body($this->form());
  89. }
  90. /**
  91. * Make a grid builder.
  92. *
  93. * @return Grid
  94. */
  95. protected function grid()
  96. {
  97. $grid = new Grid(new PersonalTalents);
  98. $grid->model()->orderBy('id', 'desc');
  99. $grid->rc_username('会员名称');
  100. $grid->rc_level('人才等级')->display(function () {
  101. if ($this->ifconform == 1) {
  102. return $this->rc_level;
  103. } elseif ($this->ifconform == 2) {
  104. return '不符合人才标准';
  105. }
  106. });
  107. $grid->rc_where('人才来源')->display(function () {
  108. if ($this->rc_where == 1) {
  109. return '自主申报';
  110. } elseif ($this->rc_where == 2) {
  111. return '企业申报';
  112. } elseif ($this->rc_where == 3) {
  113. return '信息采集';
  114. }
  115. });
  116. $grid->rc_audit('审核状态')->display(function () {
  117. if ($this->rc_audit == 1) {
  118. return '<span style="color: #009900">认证通过</span><a class="logview" data-id='.$this->id.'><i class="fa fa-eye"></i></a>';
  119. } elseif ($this->rc_audit == 2) {
  120. return '<span style="color:#FF6600">预判</span><a class="logview" data-id='.$this->id.'><i class="fa fa-eye"></i></a>';
  121. } elseif ($this->rc_audit == 3) {
  122. return '<span style="color:#666666">认证不通过</span><a class="logview" data-id='.$this->id.'><i class="fa fa-eye"></i></a>';
  123. }
  124. });
  125. if (Admin::user()->id == 1) {
  126. $states = [
  127. '1' => ['value' => 1, 'text' => '已完结', 'color' => 'primary'],
  128. '0' => ['value' => 0, 'text' => '未完结', 'color' => 'default'],
  129. ];
  130. $grid->if_finish('完结状态')->switch($states);
  131. }
  132. $grid->created_at('添加时间');
  133. $grid->if_agree('推送简历')->display(function () {
  134. if ($this->if_agree == 1) {
  135. return '<span style="color: #009900">同意</span>';
  136. } elseif ($this->if_agree == 2) {
  137. return '<span style="color:#666666">不同意</span>';
  138. } elseif ($this->if_agree == 0) {
  139. return '<span style="color:#FF6600">待定</span>';
  140. }
  141. });
  142. $grid->column('admin_user.name', '所属客服')->display(function ($name) {
  143. return $name ? $name : '<span style="color:#FF6600">待分配</span>';
  144. });
  145. /*批量删除*/
  146. $grid->tools(function ($tools) {
  147. $admin_user = <<<EOT
  148. <div class="btn-group" data-toggle="buttons">
  149. <label class="btn btn-google btn-sm" id="admin_user" title="分配客服">
  150. <i class="fa fa-audio-description"></i>
  151. <input type="radio" class="user-gender">分配客服
  152. </label>
  153. </div>
  154. EOT;
  155. $admin_user_result = AdminUser::where('id', 3)->get();
  156. if ($admin_user_result) {
  157. $tools->append($admin_user);
  158. }
  159. $tools->batch(function ($batch) {
  160. $batch->disableDelete(false);
  161. });
  162. });
  163. $grid->disableExport(false); //显示导出按钮
  164. $grid->exporter(new PersonalTalentsExport()); //传入自己在第1步创建的导出类
  165. $grid->disableCreateButton(true);
  166. $grid->actions(function ($actions) {
  167. $actions->disableEdit();
  168. $actions->disableDelete();
  169. $actions->disableView();
  170. if ($actions->row['if_finish'] != 1) {
  171. $actions->append("<button class='btn btn-primary btn-xs levelSet' data-code=" . $actions->row['id'] . ">人才审核</button>");
  172. $actions->append('<button class="btn btn-primary btn-xs" title="录入进度" onclick="window.open(\'' . route('personalTalentsLog.create',
  173. ['id' => $actions->row['id']]) . '\')">录入进度</button>');
  174. }
  175. $actions->append('<button class="btn btn-primary btn-xs" title="查看进度" onclick="window.open(\'' . route('personalTalentsLog.list',
  176. ['id' => $actions->row['id']]) . '\')">查看进度</button>');
  177. if ($actions->row['if_agree'] == 1) {
  178. $actions->append('<button class="btn btn-primary btn-xs" title="推送简历" onclick="window.open(\'' . route('push.set',
  179. ['id' => $actions->row['id'], 'uid' => $actions->row['uid']]) . '\')">推送简历</button>');
  180. } else {
  181. $actions->append("<button class='btn btn-primary btn-xs agreeSet' data-code=" . $actions->row['id'] . ">设置推送</button>");
  182. }
  183. });
  184. $grid->filter(function ($filter) {
  185. $filter->column(1 / 2, function ($filter) {
  186. $filter->like('rc_username', '姓名');
  187. $filter->equal('rc_where', '人才来源')->select([1 => '自主申报', 2 => '企业申报', 3 => '信息申报']);
  188. $filter->equal('rc_audit', '审核状态')->select([1 => '认证通过', 2 => '预判', 3 => '认证不通过']);
  189. $filter->equal('if_agree', '推送简历')->select([0 => '待确定', 1 => '同意', 2 => '不同意']);
  190. });
  191. $filter->column(1 / 2, function ($filter) {
  192. $admin_user_result = AdminUser::where('admin_role_users.role_id', 30)->leftJoin('admin_role_users', 'admin_role_users.user_id', '=', 'admin_users.id');
  193. if ($admin_user_result) {
  194. $admin_user_arr = AdminUser::where('admin_role_users.role_id', 30)->leftJoin('admin_role_users', 'admin_role_users.user_id', '=', 'admin_users.id')->pluck('admin_users.name', 'admin_users.id');
  195. $filter->equal('admin_id', '客服')->select($admin_user_arr);
  196. }
  197. $RC_categoryArr = array_column($this->CategoryRepository->getCategoryByAlias(['alias' => 'RC_category'])->toArray(), 'demand', 'id');
  198. $filter->equal('rc_level_id', '人才等级')->select($RC_categoryArr);
  199. $filter->equal('if_finish', '完结状态')->select([1 => '已完结', 0 => '未完结']);
  200. });
  201. });
  202. return $grid;
  203. }
  204. /**
  205. * Make a show builder.
  206. *
  207. * @param mixed $id
  208. * @return Show
  209. */
  210. protected function detail($id)
  211. {
  212. $show = new Show(PersonalTalents::findOrFail($id));
  213. $show->id('ID');
  214. $show->name('学校名称');
  215. $show->address('学校地址');
  216. $show->created_at('创建时间');
  217. $show->updated_at('修改时间');
  218. return $show;
  219. }
  220. /**
  221. * Make a form builder.
  222. *
  223. * @return Form
  224. */
  225. protected function form()
  226. {
  227. $form = new Form(new PersonalTalents);
  228. $form->display('ID');
  229. $form->display('Created at');
  230. $form->display('Updated at');
  231. return $form;
  232. }
  233. public function personalTalentsLog(Request $request)
  234. {
  235. $id = $request->id;
  236. $headers = ['content'=>'日志内容', 'log_time'=>'操作时间', 'auth_man'=>'操作人员'];
  237. $data = [];
  238. $res = PersonalTalentsLog::where(['talents_id'=>$id])->orderBy('id', 'desc')->get();
  239. if (!$res) {
  240. $rows = $data;
  241. } else {
  242. foreach ($res as $k => $v) {
  243. $data[$k]['content'] = $v['content'];
  244. $data[$k]['log_time'] = $v['created_at'];
  245. $data[$k]['auth_man'] = $v['auth_man'];
  246. }
  247. $rows = $data;
  248. }
  249. $table = new Table($headers, $rows);
  250. return ['html'=>$table->render(),'detail'=>'日志信息'];
  251. }
  252. // 人才审核
  253. public function levelSet(Request $request)
  254. {
  255. $id = $request->id;
  256. $form = new \Encore\Admin\Widgets\Form();
  257. $form->action(route('level.set.update'));
  258. $form->disableReset();
  259. $form->hidden('id', 'ID')->default($id);
  260. $RC_categoryArr = array_column($this->CategoryRepository->getCategoryByAlias(['alias' => 'RC_category'])->toArray(), 'demand', 'id');
  261. $form->select('rc_level_id', '人才等级')->options(
  262. $RC_categoryArr
  263. )->rules([
  264. 'required',
  265. ])->setMustMark();
  266. $form->radio('rc_audit', '人才认证状态')->options([1 => '认证通过', 3 => '认证未通过']);
  267. return json_encode(['html' => $form->render(), 'detail' => '人才审核']);
  268. }
  269. // 人才审核
  270. public function levelSetUpdate(Request $request)
  271. {
  272. $id = $request->id;
  273. $arr = array_filter(explode(',', $id));
  274. if (empty($arr)) {
  275. admin_toastr('请勾选需要人才审核的会员', 'error');
  276. return back();
  277. }
  278. $rc_level_id = $request->rc_level_id;
  279. if (empty($rc_level_id)) {
  280. admin_toastr('人才等级不能为空', 'error');
  281. return back();
  282. }
  283. $rc_level = Category::where('id', $rc_level_id)->first();
  284. if (!$rc_level) {
  285. admin_toastr('参数错误', 'error');
  286. return back();
  287. }
  288. $role_arr = [];
  289. if (!empty(Admin::user()->roles)) {
  290. foreach (Admin::user()->roles as $key => $val) {
  291. $role_arr[] = $val->id;
  292. }
  293. }
  294. if (!in_array($this->role_id_1, $role_arr)) {
  295. admin_toastr('人才客服才可以操作', 'error');
  296. return back();
  297. }
  298. //判断是否为此人才的所属客服在操作
  299. $adminid = PersonalTalents::where(array('id' => $id))->value('admin_id');
  300. if ($adminid != Admin::user()->id) {
  301. admin_toastr('此人才的客服才可以操作', 'error');
  302. return back();
  303. }
  304. $time = time();
  305. $data = array();
  306. $data['rc_level_id'] = $rc_level_id;
  307. $data['rc_level'] = $rc_level->demand;
  308. $data['rc_sort'] = $rc_level->order;
  309. $data['audit_time'] = $time;//审核时间
  310. $data['rc_audit'] = $request->rc_audit;
  311. if(!empty($rc_level)){
  312. $data['ifconform'] = 1;
  313. }
  314. try {
  315. PersonalTalents::where('id', $id)->update($data);
  316. $log = array();
  317. if ($request->audit == 1) {
  318. $authinfo = "认证通过";
  319. } else {
  320. $authinfo = "认证不通过";
  321. }
  322. $log['talents_id'] = $id;
  323. $log['log_class'] = 2;//日志类型
  324. $log['content'] = Admin::user()->username . "将人才认证为'" . $rc_level->demand . "',审核状态设置为'" . $authinfo . "'";
  325. $log['log_time'] = time();
  326. $log['auth_man'] = Admin::user()->username;
  327. PersonalTalentsLog::create($log);
  328. admin_toastr('审核成功', 'success');
  329. return back();
  330. } catch (\Exception $e) {
  331. admin_toastr('审核失败', 'error');
  332. return back();
  333. }
  334. }
  335. public function adminUserSet(Request $request)
  336. {
  337. $id = $request->id;
  338. $form = new \Encore\Admin\Widgets\Form();
  339. $form->action(route('adminUser.set.update'));
  340. $form->disableReset();
  341. $form->hidden('id', 'ID')->default($id);
  342. $form->select('admin_id', '客服名称')->options(
  343. AdminUser::where('admin_role_users.role_id', 30)->leftJoin('admin_role_users', 'admin_role_users.user_id', '=', 'admin_users.id')->pluck('admin_users.name', 'admin_users.id')
  344. )->rules([
  345. 'required',
  346. ])->setMustMark();
  347. return json_encode(['html' => $form->render(), 'detail' => '分配客服']);
  348. }
  349. public function adminUserSetUpdate(Request $request)
  350. {
  351. $id = $request->id;
  352. $arr = array_filter(explode(',', $id));
  353. if (empty($arr)) {
  354. admin_toastr('请勾选需要分配客服的会员', 'error');
  355. return back();
  356. }
  357. $admin_user_id = $request->admin_id;
  358. if (empty($admin_user_id)) {
  359. admin_toastr('客服不能为空', 'error');
  360. return back();
  361. }
  362. if (Admin::user()->id != 1) {
  363. admin_toastr('高级管理员才可以操作', 'error');
  364. return back();
  365. }
  366. try {
  367. $time = time();
  368. $admin_user = AdminUser::find($admin_user_id);
  369. foreach ($arr as $key => $val) {
  370. $info = array();
  371. PersonalTalents::where('id', $val)->update(array('admin_id' => $admin_user_id));
  372. //填入日志
  373. $info['talents_id'] = $val;
  374. $info['log_class'] = 3;//日志类型高级管理员分配客服
  375. $info['content'] = Admin::user()->username . "将此人才的客服更改为客服人员‘" . $admin_user->username . "’";
  376. $info['log_time'] = $time;
  377. $info['auth_man'] = Admin::user()->username;
  378. PersonalTalentsLog::create($info);
  379. }
  380. admin_toastr('分配成功', 'success');
  381. return back();
  382. } catch (\Exception $e) {
  383. admin_toastr('分配失败', 'error');
  384. return back();
  385. }
  386. }
  387. // 设置推送
  388. public function agreeSet(Request $request)
  389. {
  390. $id = $request->id;
  391. $form = new \Encore\Admin\Widgets\Form();
  392. $form->action(route('agree.set.update'));
  393. $form->disableReset();
  394. $form->hidden('id', 'ID')->default($id);
  395. $form->radio('rc_agree', '推送简历')->options([1 => '同意', 2 => '不同意']);
  396. $form->textarea('agree_content', '备注');
  397. return json_encode(['html' => $form->render(), 'detail' => '设置推送']);
  398. }
  399. // 设置推送
  400. public function agreeSetUpdate(Request $request)
  401. {
  402. $id = $request->id;
  403. $arr = array_filter(explode(',', $id));
  404. if (empty($arr)) {
  405. admin_toastr('请选择需要推送的会员', 'error');
  406. return back();
  407. }
  408. $rc_agree = $request->rc_agree;
  409. if (empty($rc_agree)) {
  410. admin_toastr('参数有误', 'error');
  411. return back();
  412. }
  413. try {
  414. PersonalTalents::where('id', $id)->update(array('if_agree' => $rc_agree));
  415. $log = array();
  416. //存入日志
  417. if ($rc_agree == 1) {
  418. $agree = '同意';
  419. } elseif ($rc_agree == 2) {
  420. $agree = '不同意';
  421. }
  422. $log['talents_id'] = $id;
  423. $log['log_class'] = 6;//日志类型
  424. $content = $request->agree_content;
  425. if ($content != '') {
  426. $log['content'] = Admin::user()->username . "设置此人才" . $agree . '推送简历' . ',备注:' . $content;
  427. } else {
  428. $log['content'] = Admin::user()->username . "设置此人才" . $agree . '推送简历';
  429. }
  430. $log['log_time'] = time();
  431. $log['auth_man'] = Admin::user()->username;
  432. PersonalTalentsLog::create($log);
  433. admin_toastr('操作成功', 'success');
  434. return back();
  435. } catch (\Exception $e) {
  436. admin_toastr('操作失败', 'error');
  437. return back();
  438. }
  439. }
  440. // 推送简历
  441. public function pushSet(Content $content)
  442. {
  443. $id = request()->id;
  444. $form = new Form(new PersonalTalents);
  445. $form->setAction(route('push.set.update'));
  446. $form->disableReset();
  447. $form->hidden('ids')->default($id);
  448. $form->multipleSelect('company_id', '企业名称')->options(
  449. Company::where('audit', 1)->pluck('companyname', 'id')->all()
  450. )->rules([
  451. 'required',
  452. ])->setMustMark();
  453. return $content
  454. ->header('推送简历')
  455. ->description('创建')
  456. ->body($form);
  457. }
  458. // 推送简历
  459. public function pushSetUpdate(Request $request)
  460. {
  461. $data = $request->all();
  462. $arr = array_filter(explode(',', $data['ids']));
  463. if (empty($arr)) {
  464. admin_toastr('请选择需要推送的会员', 'error');
  465. return back();
  466. }
  467. if (empty($data['company_id'])) {
  468. admin_toastr('请选择要推送的企业名称', 'error');
  469. return back();
  470. }
  471. $company_id_arr = [];
  472. $company_name_arr = [];
  473. foreach ($data['company_id'] as $key => $val) {
  474. if (!empty($val)) {
  475. $company_id_arr[] = $val;
  476. $company_name_arr[] = Company::where('id', $val)->value('companyname');
  477. }
  478. }
  479. try {
  480. $this->ResumeService->resumeEntrustByAdmin($company_id_arr,$data['ids'],Admin::user()->username);
  481. admin_toastr('推送成功', 'success');
  482. } catch (\Exception $e) {
  483. admin_toastr('职位不匹配,推送失败!', 'error');
  484. }
  485. return redirect(admin_base_path("personalTalents/personaltalents"));
  486. }
  487. }