ResumePhotoController.php 15 KB

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