ResumePhotoController.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. <?php
  2. namespace App\Admin\Controllers\Person;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\AuditReason;
  5. use App\Models\MemberInfo;
  6. use App\Models\Pms;
  7. use App\Models\Resume;
  8. use App\Models\Subsite;
  9. use App\Validators\Rules\MobileRule;
  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. class ResumePhotoController extends Controller
  18. {
  19. use HasResourceActions;
  20. protected $resumeController;
  21. public function __construct(ResumeController $resumeController)
  22. {
  23. $this->resumeController = $resumeController;
  24. }
  25. /**
  26. * Index interface.
  27. *
  28. * @param Content $content
  29. * @return Content
  30. */
  31. public function index(Content $content, Request $request)
  32. {
  33. return $content
  34. ->header('简历照片')
  35. ->description('')
  36. ->body(view('admin.resumePhoto.photo')->with(['grid'=>$this->grid($request)]));
  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('创建')
  77. ->body($this->form());
  78. }
  79. /**
  80. * Make a grid builder.
  81. *
  82. * @return Grid
  83. */
  84. protected function grid($request)
  85. {
  86. $grid = new Grid(new MemberInfo);
  87. $grid->model()->when(get_subsite_id()>0, function ($query) {
  88. $query->whereHas('members', function ($query) {
  89. $query->where('subsite_id', get_subsite_id());
  90. });
  91. })->where('photo', 1)->orderByRaw("FIELD(photo_audit, 1,2,0)")->orderBy('updated_at', 'desc');
  92. $grid->images('姓名')->display(function ($images) {
  93. if ($images) {
  94. return '<span class="vtip" title="<img src='.upload_asset($images).' width=120 height=120>">
  95. <img class="avatar small" src="'.upload_asset($images).'" align="absmiddle" style="width: 36px;height: 36px;">
  96. </span>&nbsp;&nbsp;&nbsp;'.$this->realname;
  97. } else {
  98. return '<span class="vtip" ></span>&nbsp;&nbsp;&nbsp;'. $this->realname;
  99. }
  100. })->width(200);
  101. $grid->sex_cn('性别')->width(100);
  102. $grid->birthday('出生日期')->width(100);
  103. $grid->photo_audit('照片审核')->display(function ($photo_audit) {
  104. if ($photo_audit==0) {
  105. return'<span style="color:#666666">审核未通过</span><a style="margin-left: 5px;" ls="'.$this->id.'" class="audit_log"><i class="fa fa-eye"></i></a>';
  106. } elseif ($photo_audit==2) {
  107. return'<span style="color: #009900">审核通过</span><a style="margin-left: 5px;" ls="'.$this->id.'" class="audit_log"><i class="fa fa-eye"></i></a>';
  108. } else {
  109. return'<span style="color:#FF6600">等待审核</span><a style="margin-left: 5px;" ls="'.$this->id.'" class="audit_log"><i class="fa fa-eye"></i></a>';
  110. }
  111. });
  112. $grid->education_cn('最高学历')->width(150);
  113. $grid->experience_cn('工作经验')->width(150);
  114. $grid->phone('手机')->width(150);
  115. $grid->email('邮箱')->width(150);
  116. if(get_subsite_open()){
  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. }
  125. $grid->created_at('添加时间')->sortable();
  126. $grid->updated_at('更新时间')->sortable();
  127. $grid->disableCreateButton();
  128. $grid->disableExport();
  129. $grid->actions(function ($actions) use ($grid) {
  130. if (Admin::user()->can('perosn_business')) {
  131. $actions->append('<button class="btn btn-primary btn-xs business" ls="'.$actions->row['uid'].'" ld="'.$actions->row['realname'].'" title="业务" >业务</button>');
  132. }
  133. if (Admin::user()->can('person_resume_photo_audit')) {
  134. $actions->append("<button class='btn btn-primary btn-xs jobaudit' data-code=".$actions->row['id'].">审核</button>");
  135. }
  136. /* if (Admin::user()->can('person_resume_photo_delete')) {
  137. $actions->disableDelete(false);
  138. }*/
  139. });
  140. /* if (Admin::user()->can('person_resume_photo_delete')) {
  141. $grid->tools(function ($tools) {
  142. $tools->batch(function ($batch) {
  143. $batch->disableDelete(false);
  144. });
  145. });
  146. $grid->disableRowSelector(false);
  147. }*/
  148. $grid->tools(function ($tools) {
  149. if (Admin::user()->can('person_resume_photo_audit')) {
  150. $but = <<<EOT
  151. <div class="btn-group" data-toggle="buttons">
  152. <label class="btn btn-google btn-sm" id="audit_photo" 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. if (Admin::user()->can('person_resume_image_delete')) {
  161. $but = <<<EOT
  162. <div class="btn-group" data-toggle="buttons">
  163. <label class="btn btn-google btn-sm" id="DeleteImg" title="删除头像">
  164. <i class="fa fa-audio-description"></i>
  165. <input type="radio" class="user-gender">删除头像
  166. </label>
  167. </div>
  168. EOT;
  169. $tools->append($but);
  170. }
  171. });
  172. $grid->filter(function ($filter) {
  173. // 去掉默认的id过滤器
  174. $filter->disableIdFilter();
  175. $filter->column(1/2, function ($filter) {
  176. $filter->like('phone', '手机');
  177. $filter->like('email', '邮箱');
  178. $filter->equal('photo_audit', '审核状态')->select([
  179. 0=>'审核未通过',
  180. 1=>'等待审核',
  181. 2=>'审核通过',
  182. ]);
  183. if(get_subsite_id()==0 && get_subsite_open()){
  184. $filter->equal('members.subsite_id', '所属分站')->select(array_column(get_all_subsite(), 'sitename', 'id'));
  185. }
  186. });
  187. $filter->column(1/2, function ($filter) {
  188. // 关联关系查询
  189. $filter->like('realname', '姓名');
  190. $filter->equal('sex_cn', '性别');
  191. $filter->equal('birthday', '出生日期');
  192. $filter->equal('education_cn', '最高学历');
  193. });
  194. });
  195. return $grid;
  196. }
  197. /**
  198. * Make a show builder.
  199. *
  200. * @param mixed $id
  201. * @return Show
  202. */
  203. protected function detail($id)
  204. {
  205. $show = new Show(MemberInfo::findOrFail($id));
  206. $show->id('Id');
  207. $show->realname('姓名');
  208. $show->sex_cn('性别');
  209. $show->birthday('出生日期');
  210. $show->photo_audit('照片审核')->as(function ($photo_audit) {
  211. if ($photo_audit==0) {
  212. return '审核未通过';
  213. } elseif ($photo_audit==2) {
  214. return '审核通过';
  215. } else {
  216. return '等待审核';
  217. }
  218. });
  219. $show->education_cn('最高学历');
  220. $show->experience_cn('工作经验');
  221. $show->phone('手机');
  222. $show->email('邮箱');
  223. $show->members()->subsite_id('所属分站')->as(function ($subsite_id) {
  224. if ($subsite_id->subsite_id) {
  225. $Subsite = Subsite::find($subsite_id->subsite_id);
  226. return isset($Subsite->sitename) ? $Subsite->sitename : '未知';
  227. }
  228. return '总站';
  229. });
  230. $show->created_at('Created at');
  231. $show->updated_at('Updated at');
  232. return $show;
  233. }
  234. /**
  235. * Make a form builder.
  236. *
  237. * @return Form
  238. */
  239. protected function form()
  240. {
  241. $form = new Form(new Resume);
  242. $form->text('name', 'Name');
  243. $form->email('email', 'Email');
  244. $form->password('password', 'Password');
  245. $form->text('remember_token', 'Remember token');
  246. return $form;
  247. }
  248. /**
  249. * 审核图片
  250. * return json
  251. */
  252. public function auditPhoto(Request $request)
  253. {
  254. $id = $request->id;
  255. $form = new \Encore\Admin\Widgets\Form();
  256. $form->action(route('admin.personal.auditP'));
  257. $form->disableReset();
  258. $form->hidden('id', 'ID')->default($id);
  259. $form->radio('audit', '头像')->options([2=>'审核通过',0=>'审核未通过'])->default(2);
  260. $form->textarea('remark', '备注');
  261. $form->html('<label style="color: rgb(0, 153, 0)"><input type="checkbox" name="pms_notice" value="1" checked="checked">站内信通知</label>');
  262. return json_encode(['html'=>$form->render(),'detail'=>'审核头像']);
  263. }
  264. public function auditP(Request $request)
  265. {
  266. $id = $request->id;
  267. $audit = $request->audit;
  268. $remark = $request->remark;
  269. $pms_notice = $request->pms_notice;
  270. $arr = array_filter(explode(',', $id));
  271. if (empty($arr)) {
  272. admin_toastr('数据异常', 'error');
  273. return back();
  274. }
  275. $result = MemberInfo::whereIn('id', $arr)->update(['photo_audit'=>$audit]);
  276. foreach ($arr as $k => $v) {
  277. $data[$k]['type'] = 2;
  278. $data[$k]['type_id'] = $v;
  279. $data[$k]['status'] = $audit;
  280. $data[$k]['reason'] = $remark;
  281. $data[$k]['audit_man'] = Admin::user()->username;
  282. $data[$k]['created_at'] = date('Y-m-d H:i:s', time());
  283. $data[$k]['updated_at'] = date('Y-m-d H:i:s', time());
  284. }
  285. $this->auditReason($data);
  286. $reus = MemberInfo::with(['members'])->whereIn('id', $arr)->get();
  287. $resume_uid = [];
  288. if ($audit==0) {
  289. $stat='审核未通过';
  290. } elseif ($audit==2) {
  291. $stat = '审核通过';
  292. } else {
  293. $stat='等待审核';
  294. }
  295. $mobile = [];
  296. foreach ($reus as $res) {
  297. if (isset($res->members->mobile)) {
  298. if (validator_check($res->members->mobile, new MobileRule())) {
  299. $mobile[] = $res->members->mobile;
  300. }
  301. }
  302. }
  303. $mobile = array_unique($mobile);
  304. $sms_id = $audit ? 'sms_resume_photoallow' : 'sms_resume_photonotallow';
  305. foreach ($reus as $key => $val) {
  306. $ds[$key]['msgtype'] = 1;
  307. $ds[$key]['msgfromuid'] = Admin::user()->id;
  308. $ds[$key]['msgfrom'] = Admin::user()->username;
  309. $ds[$key]['msgtoname'] = $val->members->username;
  310. $ds[$key]['msgtouid'] = $val->uid;
  311. $resume_uid[] = $val->uid;
  312. if ($val->members->username) {
  313. $username_title = '('.$val->members->username.')';
  314. } else {
  315. $username_title = '';
  316. }
  317. $ds[$key]['message'] = $remark ? '简历头像'.$username_title.$stat.'<备注:'.$remark.'>' : '简历头像'.$username_title.$stat;
  318. $ds[$key]['created_at'] = date('Y-m-d H:i:s', time());
  319. $ds[$key]['updated_at'] = date('Y-m-d H:i:s', time());
  320. }
  321. if ($pms_notice) {
  322. Pms::insert($ds);
  323. }
  324. if ($result) {
  325. $this->resumeController->resumeSms($sms_id, $mobile);
  326. if ($resume_uid) {
  327. event_search_update(Resume::class, [['whereIn','uid', $resume_uid]], 'update');
  328. }
  329. admin_toastr('审核成功', 'success');
  330. } else {
  331. admin_toastr('审核失败', 'error');
  332. }
  333. return back();
  334. }
  335. /**
  336. * CREAT 审核日志.
  337. * @param $type
  338. * @param $status
  339. * @param $reason
  340. * @param $audit_man
  341. * return arr
  342. */
  343. public function auditReason($data)
  344. {
  345. AuditReason::insert($data);
  346. }
  347. public function deleteIma(Request $request)
  348. {
  349. $id = $request->id;
  350. $form = new \Encore\Admin\Widgets\Form();
  351. $form->action(route('admin.personal.deleteImage'));
  352. $form->disableReset();
  353. $form->hidden('id', 'ID')->default($id);
  354. $form->html('<div>删除头像会使简历完整度下降,是否删除?</div>');
  355. return json_encode(['html'=>$form->render(),'detail'=>'删除头像']);
  356. }
  357. public function deleteImage(Request $request)
  358. {
  359. $id = $request->id;
  360. $arr = array_filter(explode(',', $id));
  361. if (empty($arr)) {
  362. admin_toastr('数据异常', 'error');
  363. return back();
  364. }
  365. \DB::beginTransaction();
  366. try {
  367. MemberInfo::whereIn('id',$arr)->update(['images'=>'','photo'=>0,'photo_audit'=>1]);
  368. $resume_uid = MemberInfo::whereIn('id', $arr)->pluck('uid')->toArray();
  369. if ($resume_uid) {
  370. $resume = Resume::whereIn('uid',$resume_uid)->get();
  371. if(!$resume->isEmpty()){
  372. foreach ($resume as $resumes){
  373. if ($resumes->complete_percent-5>0) {
  374. if ($resumes->complete_percent-5>=70 && $resumes->complete_percent-5<90) {
  375. Resume::where(['id'=>$resumes->id])
  376. ->update(['complete_percent'=>$resumes->complete_percent-5,'level'=>2]);
  377. } elseif ($resumes->complete_percent-5>=90 && $resumes->complete_percent-15<=100) {
  378. Resume::where(['id'=>$resumes->id])
  379. ->update(['complete_percent'=>$resumes->complete_percent-5,'level'=>1]);
  380. } else {
  381. Resume::where(['id'=>$resumes->id])
  382. ->update(['complete_percent'=>$resumes->complete_percent-5,'level'=>0]);
  383. }
  384. }
  385. }
  386. }
  387. event_search_update(Resume::class, [['whereIn','uid', $resume_uid]], 'update');
  388. }
  389. \DB::commit();
  390. admin_toastr('删除成功', 'success');
  391. } catch (\Exception $e) {
  392. \DB::rollback();
  393. admin_toastr('删除失败', 'error');
  394. }
  395. return back();
  396. }
  397. }