123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432 |
- <?php
- namespace App\Admin\Controllers\Person;
- use App\Http\Controllers\Controller;
- use App\Models\AuditReason;
- use App\Models\MemberInfo;
- use App\Models\Pms;
- use App\Models\Resume;
- use App\Models\Subsite;
- use App\Validators\Rules\MobileRule;
- use Encore\Admin\Controllers\HasResourceActions;
- use Encore\Admin\Facades\Admin;
- use Encore\Admin\Form;
- use Encore\Admin\Grid;
- use Encore\Admin\Layout\Content;
- use Encore\Admin\Show;
- use Illuminate\Http\Request;
- class ResumePhotoController extends Controller
- {
- use HasResourceActions;
- protected $resumeController;
- public function __construct(ResumeController $resumeController)
- {
- $this->resumeController = $resumeController;
- }
- /**
- * Index interface.
- *
- * @param Content $content
- * @return Content
- */
- public function index(Content $content, Request $request)
- {
- return $content
- ->header('简历照片')
- ->description('')
- ->body(view('admin.resumePhoto.photo')->with(['grid'=>$this->grid($request)]));
- }
- /**
- * Show interface.
- *
- * @param mixed $id
- * @param Content $content
- * @return Content
- */
- public function show($id, Content $content)
- {
- return $content
- ->header('简历照片')
- ->description('详细')
- ->body($this->detail($id));
- }
- /**
- * Edit interface.
- *
- * @param mixed $id
- * @param Content $content
- * @return Content
- */
- public function edit($id, Content $content)
- {
- return $content
- ->header('简历照片')
- ->description('编辑')
- ->body($this->form()->edit($id));
- }
- /**
- * Create interface.
- *
- * @param Content $content
- * @return Content
- */
- public function create(Content $content)
- {
- return $content
- ->header('简历照片')
- ->description('创建')
- ->body($this->form());
- }
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid($request)
- {
- $grid = new Grid(new MemberInfo);
- $grid->model()
- /*->when(get_subsite_id()>0, function ($query) {
- $query->whereHas('members', function ($query) {
- $query->where('subsite_id', get_subsite_id());
- });
- })*/
- ->where('photo', 1)->orderByRaw("FIELD(photo_audit, 1,2,0)")->orderBy('updated_at', 'desc');
- $grid->images('姓名')->display(function ($images) {
- if ($images) {
- return '<span class="vtip" title="<img src='.upload_asset($images).' width=120 height=120>">
- <img class="avatar small" src="'.upload_asset($images).'" align="absmiddle" style="width: 36px;height: 36px;">
- </span> '.$this->realname;
- } else {
- return '<span class="vtip" ></span> '. $this->realname;
- }
- })->width(200);
- $grid->sex_cn('性别')->width(100);
- $grid->birthday('出生日期')->width(100);
- $grid->photo_audit('照片审核')->display(function ($photo_audit) {
- if ($photo_audit==0) {
- return'<span style="color:#666666">审核未通过</span><a style="margin-left: 5px;" ls="'.$this->id.'" class="audit_log"><i class="fa fa-eye"></i></a>';
- } elseif ($photo_audit==2) {
- return'<span style="color: #009900">审核通过</span><a style="margin-left: 5px;" ls="'.$this->id.'" class="audit_log"><i class="fa fa-eye"></i></a>';
- } else {
- return'<span style="color:#FF6600">等待审核</span><a style="margin-left: 5px;" ls="'.$this->id.'" class="audit_log"><i class="fa fa-eye"></i></a>';
- }
- });
- $grid->education_cn('最高学历')->width(150);
- $grid->experience_cn('工作经验')->width(150);
- $grid->phone('手机')->width(150);
- $grid->email('邮箱')->width(150);
- if(get_subsite_open()){
- $grid->column('members.subsite_id', '所属分站')->display(function ($subsite_id) {
- if ($subsite_id) {
- $Subsite = Subsite::find($subsite_id);
- return isset($Subsite->sitename) ? $Subsite->sitename : '未知';
- }
- return '总站';
- })->width(150);
- }
- $grid->created_at('添加时间')->sortable();
- $grid->updated_at('更新时间')->sortable();
- $grid->disableCreateButton();
- $grid->disableExport();
- $grid->actions(function ($actions) use ($grid) {
- if (Admin::user()->can('perosn_business')) {
- $actions->append('<button class="btn btn-primary btn-xs business" ls="'.$actions->row['uid'].'" ld="'.$actions->row['realname'].'" title="业务" >业务</button>');
- }
- if (Admin::user()->can('person_resume_photo_audit')) {
- $actions->append("<button class='btn btn-primary btn-xs jobaudit' data-code=".$actions->row['id'].">审核</button>");
- }
- /* if (Admin::user()->can('person_resume_photo_delete')) {
- $actions->disableDelete(false);
- }*/
- });
- /* if (Admin::user()->can('person_resume_photo_delete')) {
- $grid->tools(function ($tools) {
- $tools->batch(function ($batch) {
- $batch->disableDelete(false);
- });
- });
- $grid->disableRowSelector(false);
- }*/
- $grid->tools(function ($tools) {
- if (Admin::user()->can('person_resume_photo_audit')) {
- $but = <<<EOT
- <div class="btn-group" data-toggle="buttons">
- <label class="btn btn-google btn-sm" id="audit_photo" title="审核头像">
- <i class="fa fa-audio-description"></i>
- <input type="radio" class="user-gender">审核头像
- </label>
- </div>
- EOT;
- $tools->append($but);
- }
- if (Admin::user()->can('person_resume_image_delete')) {
- $but = <<<EOT
- <div class="btn-group" data-toggle="buttons">
- <label class="btn btn-google btn-sm" id="DeleteImg" title="删除头像">
- <i class="fa fa-audio-description"></i>
- <input type="radio" class="user-gender">删除头像
- </label>
- </div>
- EOT;
- $tools->append($but);
- }
- });
- $grid->filter(function ($filter) {
- // 去掉默认的id过滤器
- $filter->disableIdFilter();
- $filter->column(1/2, function ($filter) {
- $filter->like('phone', '手机');
- $filter->like('email', '邮箱');
- $filter->equal('photo_audit', '审核状态')->select([
- 0=>'审核未通过',
- 1=>'等待审核',
- 2=>'审核通过',
- ]);
- if(get_subsite_id()==0 && get_subsite_open()){
- $filter->equal('members.subsite_id', '所属分站')->select(array_column(get_all_subsite(), 'sitename', 'id'));
- }
- });
- $filter->column(1/2, function ($filter) {
- // 关联关系查询
- $filter->like('realname', '姓名');
- $filter->equal('sex_cn', '性别');
- $filter->equal('birthday', '出生日期');
- $filter->equal('education_cn', '最高学历');
- });
- });
- return $grid;
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- * @return Show
- */
- protected function detail($id)
- {
- $show = new Show(MemberInfo::findOrFail($id));
- $show->id('Id');
- $show->realname('姓名');
- $show->sex_cn('性别');
- $show->birthday('出生日期');
- $show->photo_audit('照片审核')->as(function ($photo_audit) {
- if ($photo_audit==0) {
- return '审核未通过';
- } elseif ($photo_audit==2) {
- return '审核通过';
- } else {
- return '等待审核';
- }
- });
- $show->education_cn('最高学历');
- $show->experience_cn('工作经验');
- $show->phone('手机');
- $show->email('邮箱');
- $show->members()->subsite_id('所属分站')->as(function ($subsite_id) {
- if ($subsite_id->subsite_id) {
- $Subsite = Subsite::find($subsite_id->subsite_id);
- return isset($Subsite->sitename) ? $Subsite->sitename : '未知';
- }
- return '总站';
- });
- $show->created_at('Created at');
- $show->updated_at('Updated at');
- return $show;
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- $form = new Form(new Resume);
- $form->text('name', 'Name');
- $form->email('email', 'Email');
- $form->password('password', 'Password');
- $form->text('remember_token', 'Remember token');
- return $form;
- }
- /**
- * 审核图片
- * return json
- */
- public function auditPhoto(Request $request)
- {
- $id = $request->id;
- $form = new \Encore\Admin\Widgets\Form();
- $form->action(route('admin.personal.auditP'));
- $form->disableReset();
- $form->hidden('id', 'ID')->default($id);
- $form->radio('audit', '头像')->options([2=>'审核通过',0=>'审核未通过'])->default(2);
- $form->textarea('remark', '备注');
- $form->html('<label style="color: rgb(0, 153, 0)"><input type="checkbox" name="pms_notice" value="1" checked="checked">站内信通知</label>');
- return json_encode(['html'=>$form->render(),'detail'=>'审核头像']);
- }
- public function auditP(Request $request)
- {
- $id = $request->id;
- $audit = $request->audit;
- $remark = $request->remark;
- $pms_notice = $request->pms_notice;
- $arr = array_filter(explode(',', $id));
- if (empty($arr)) {
- admin_toastr('数据异常', 'error');
- return back();
- }
- $result = MemberInfo::whereIn('id', $arr)->update(['photo_audit'=>$audit]);
- foreach ($arr as $k => $v) {
- $data[$k]['type'] = 2;
- $data[$k]['type_id'] = $v;
- $data[$k]['status'] = $audit;
- $data[$k]['reason'] = $remark;
- $data[$k]['audit_man'] = Admin::user()->username;
- $data[$k]['created_at'] = date('Y-m-d H:i:s', time());
- $data[$k]['updated_at'] = date('Y-m-d H:i:s', time());
- }
- $this->auditReason($data);
- $reus = MemberInfo::with(['members'])->whereIn('id', $arr)->get();
- $resume_uid = [];
- if ($audit==0) {
- $stat='审核未通过';
- } elseif ($audit==2) {
- $stat = '审核通过';
- } else {
- $stat='等待审核';
- }
- $mobile = [];
- foreach ($reus as $res) {
- if (isset($res->members->mobile)) {
- if (validator_check($res->members->mobile, new MobileRule())) {
- $mobile[] = $res->members->mobile;
- }
- }
- }
- $mobile = array_unique($mobile);
- $sms_id = $audit ? 'sms_resume_photoallow' : 'sms_resume_photonotallow';
- foreach ($reus as $key => $val) {
- $ds[$key]['msgtype'] = 1;
- $ds[$key]['msgfromuid'] = Admin::user()->id;
- $ds[$key]['msgfrom'] = Admin::user()->username;
- $ds[$key]['msgtoname'] = $val->members->username;
- $ds[$key]['msgtouid'] = $val->uid;
- $resume_uid[] = $val->uid;
- if ($val->members->username) {
- $username_title = '('.$val->members->username.')';
- } else {
- $username_title = '';
- }
- $ds[$key]['message'] = $remark ? '简历头像'.$username_title.$stat.'<备注:'.$remark.'>' : '简历头像'.$username_title.$stat;
- $ds[$key]['created_at'] = date('Y-m-d H:i:s', time());
- $ds[$key]['updated_at'] = date('Y-m-d H:i:s', time());
- }
- if ($pms_notice) {
- Pms::insert($ds);
- }
- if ($result) {
- $this->resumeController->resumeSms($sms_id, $mobile);
- if ($resume_uid) {
- event_search_update(Resume::class, [['whereIn','uid', $resume_uid]], 'update');
- }
- admin_toastr('审核成功', 'success');
- } else {
- admin_toastr('审核失败', 'error');
- }
- return back();
- }
- /**
- * CREAT 审核日志.
- * @param $type
- * @param $status
- * @param $reason
- * @param $audit_man
- * return arr
- */
- public function auditReason($data)
- {
- AuditReason::insert($data);
- }
- public function deleteIma(Request $request)
- {
- $id = $request->id;
- $form = new \Encore\Admin\Widgets\Form();
- $form->action(route('admin.personal.deleteImage'));
- $form->disableReset();
- $form->hidden('id', 'ID')->default($id);
- $form->html('<div>删除头像会使简历完整度下降,是否删除?</div>');
- return json_encode(['html'=>$form->render(),'detail'=>'删除头像']);
- }
- public function deleteImage(Request $request)
- {
- $id = $request->id;
- $arr = array_filter(explode(',', $id));
- if (empty($arr)) {
- admin_toastr('数据异常', 'error');
- return back();
- }
- \DB::beginTransaction();
- try {
- MemberInfo::whereIn('id',$arr)->update(['images'=>'','photo'=>0,'photo_audit'=>1]);
- $resume_uid = MemberInfo::whereIn('id', $arr)->pluck('uid')->toArray();
- if ($resume_uid) {
- $resume = Resume::whereIn('uid',$resume_uid)->get();
- if(!$resume->isEmpty()){
- foreach ($resume as $resumes){
- if ($resumes->complete_percent-5>0) {
- if ($resumes->complete_percent-5>=70 && $resumes->complete_percent-5<90) {
- Resume::where(['id'=>$resumes->id])
- ->update(['complete_percent'=>$resumes->complete_percent-5,'level'=>2]);
- } elseif ($resumes->complete_percent-5>=90 && $resumes->complete_percent-15<=100) {
- Resume::where(['id'=>$resumes->id])
- ->update(['complete_percent'=>$resumes->complete_percent-5,'level'=>1]);
- } else {
- Resume::where(['id'=>$resumes->id])
- ->update(['complete_percent'=>$resumes->complete_percent-5,'level'=>0]);
- }
- }
- }
- }
- event_search_update(Resume::class, [['whereIn','uid', $resume_uid]], 'update');
- }
- \DB::commit();
- admin_toastr('删除成功', 'success');
- } catch (\Exception $e) {
- \DB::rollback();
- admin_toastr('删除失败', 'error');
- }
- return back();
- }
- }
|