recruitService = $recruitService; } /** * 招考列表页 */ public function index(Request $request) { $size = 10; $key = $request->input('key'); $list = $this->recruitService->getRecruit($key, $size); if ($request->ajax()) { if ($list->lastPage() < $list->currentPage()) { return response()->json(['status' => 0]); } return response()->json(['status' => 1, 'data' => view('mobile.app.recruit.ajax_recruit_list', ['list' => $list])->render()]); } $mobile_dropload = false; if ($list->total() > $size) { $mobile_dropload = true; } $return_data = [ 'list' => $list, 'key' => $key, 'current_url' => \Illuminate\Support\Facades\Request::getRequestUri(), 'wap_title' => '招考列表', 'mobile_dropload' => $mobile_dropload, 'current_text' => Recruit::$currentText, ]; return view('mobile.app.recruit.index', $return_data); } /** * 招考详情页 */ public function show(Request $request) { $user = $this->getUser(); if ($user) { $uid = $user->id; $utype = $user->utype; } else { $uid = 0; $utype = 0; } $id = $request->input('id', 0); if (empty($id)) { return $this->showMessage('抱歉,请输入指定的招考场次!', route('mobile.recruit.list'), true, '上一页', '3'); } $recruit = Recruit::find($id); if (empty($recruit)) { return redirect(route('/mobile/recruit/list')); } $info = Recruit::parse_info($recruit); $list = RecruitArticle::where('recruit_id', $id)->orderBy('created_at', 'desc')->get(); if (!empty($info)) { $view_data = [ 'recruit' => $recruit, 'info' => $info, 'uid' => $uid, 'utype' => $utype, 'list' => $list, ]; return view('mobile.app.recruit.show')->with($view_data); } else { return back(); } } /** * 报名功能页 * @param Request $request * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View|mixed|\think\response\Redirect|\think\response\View|void */ public function sign_up(Request $request) { $user = $this->getUser(); if (!empty($user)) { $uid = $user->id; } else { return redirect(route('login')); } //招考id $id = $request->input('id', 0); if (!$id) { return $this->showMessage('请选择招考项目!', route('home'), true, '上一页', '3'); } //招考信息 $recruit = Recruit::find($id); if (!$recruit['status']) { return $this->showMessage('抱歉,该招考状态不正确,请联系客服!', route('recruit.show', ['id', $recruit['id']]), true, '上一页', '3'); } if ($recruit['current'] != 1) { return $this->showMessage('抱歉,该招考报名通道已关闭,如有疑问,请联系客服!', route('recruit.show', ['id', $recruit['id']]), true, '上一页', '3'); } $time = time(); if ($time < strtotime($recruit['apply_start']) || strtotime($recruit['apply_end']) < $time) { return $this->showMessage('抱歉,该招考已过报名时间或尚未开始!', route('recruit.show', ['id', $recruit['id']]), true, '上一页', '3'); } $view_data['module'] = $forms = explode(',', $recruit['forms']); //查询报名表是否已有记录 $appoint_info = RecruitAppointInfo::where('uid', $uid)->where('recruit_id', $id)->first(); if ($appoint_info) { //如果已有该场次的报名记录,读取录入的数据集合 $user_info = $appoint_info; $user_info['sex'] = (string)$user_info['sex']; $user_info['edu_type'] = (string)$user_info['edu_type']; $user_info['family'] = json_decode($user_info['family']); if (in_array('expand_special', $forms)) { $special = RecruitAppointExpandSpecial::where('recruit_appoint_id', $user_info['id'])->first(); if (json_decode($special['material'])) { $material = json_decode($special['material'], true); foreach ($material as $k => $v) { $material[$k]['url'] = $v['response']['path']; } } else { $material = []; } $user_info['special'] = [ 'point_apply' => (string)$special['point_apply'], 'condition' => $special['condition'], 'material' => $material, ]; } if (in_array('detail', $forms)) { $detail = RecruitAppointDetail::where('recruit_appoint_id', $user_info['id'])->first(); if ($detail) { $user_info['detail'] = $detail->toArray(); } else { $user_info['detail'] = [ 'train' => '', 'rewards_and_punishments' => '', 'introduce' => '', ]; } } //如果有身份证明模块 if (in_array('identification', $forms)) { if (json_decode($user_info['identification'])) { $identification = json_decode($user_info['identification'], true); foreach ($identification as $k => $v) { $identification[$k]['url'] = $v['response']['path']; } } else { $identification = []; } $user_info['identification'] = $identification; } //如果有教育证明模块 if (in_array('education_certification', $forms)) { if (json_decode($user_info['education_certification'])) { $education_certification = json_decode($user_info['education_certification'], true); foreach ($education_certification as $k => $v) { $education_certification[$k]['url'] = $v['response']['path']; } } else { $education_certification = []; } $user_info['education_certification'] = $education_certification; } //如果有其他证明模块 if (in_array('other_certification', $forms)) { if (json_decode($user_info['other_certification'])) { $other_certification = json_decode($user_info['other_certification'], true); foreach ($other_certification as $k => $v) { $other_certification[$k]['url'] = $v['response']['path']; } } else { $other_certification = []; } $user_info['other_certification'] = $other_certification; } //获取最新的报名审核信息 $logs = RecruitAppointLog::where('appoint_id', $user_info->id)->where('step', 1)->where('type', 2)->orderBy('created_at', 'desc')->first(); if ($logs) { $user_info['audit_log'] = $logs->log; } else { $user_info['audit_log'] = ''; } //获取提交报名的次数 $number = RecruitAppointLog::where('appoint_id', $user_info->id)->where('step', 1)->where('type', 3)->count(); $post_number = $number + 1;//todo } else { $post_number = 1; //如果没有,结合基础数据及模块表单信息,制作数据对象 $user_info = RecruitAppointBasic::where('uid', $uid)->first(); if (!$user_info) { //没有基础信息跳转完善route('person.recruitInfo') return $this->showMessage('请先完善招考基础信息!', route('person.recruitInfo', ['recruit_id', $id]), true, '上一页', '3'); } $user_info['sex'] = (string)$user_info['sex']; $user_info['edu_type'] = (string)$user_info['edu_type']; $user_info['family'] = json_decode($user_info['family']); if (in_array('expand_special', $forms)) { $user_info['special'] = [ 'point_apply' => '0', 'condition' => '', 'material' => [], ]; } if (in_array('detail', $forms)) { $user_info['detail'] = [ 'train' => '', 'rewards_and_punishments' => '', 'introduce' => '', ]; } if (in_array('identification', $forms)) { $user_info['identification'] = []; } if (in_array('education_certification', $forms)) { $user_info['education_certification'] = []; } if (in_array('other_certification', $forms)) { $user_info['other_certification'] = []; } } $user_info['recruit_id'] = $id; $user_info['operation'] = 1; //招考岗位 $where_post[] = ['recruit_id', '=', $id]; $recruit_post = RecruitPost::where($where_post)->get(); $post = []; $post_limit = []; foreach ($recruit_post as $value) { $item = [ 'value' => $value['id'], 'label' => $value['code'] . " " . $value['name'], ]; $post_limit[$value['id']] = json_decode($value['limit']); array_push($post, $item); } $view_data['appoint_info'] = $user_info; $view_data['post'] = json_encode($post); $view_data['post_number'] = $post_number; $view_data['post_times'] = $recruit['post_times']; $view_data['post_limit'] = json_encode($post_limit); return view('mobile.app.recruit.sign_up', $view_data); } /** * 提交报名的处理程序 * @param Request $request * @return array|\Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\think\response\Redirect|void */ public function saveSignUp(Request $request) { $user = $this->getUser(); if (!empty($user)) { $uid = $user->id; } else { return redirect(route('login')); } $recruit_id = $request->input('recruit_id', 0); if (!$recruit_id) { return response()->json(['status' => 0, 'msg' => '请选择招考项目!']); } $recruit = Recruit::find($recruit_id); if (!$recruit['status']) { return response()->json(['status' => 0, 'msg' => '抱歉,该招考状态不正确,请联系客服!']); } if ($recruit['current'] != 1) { return response()->json(['status' => 0, 'msg' => '抱歉,该招考报名通道已关闭,如有疑问,请联系客服!']); } $time = time(); if ($time < $recruit['apply_start'] || $recruit['apply_end'] > $time) { return response()->json(['status' => 0, 'msg' => '抱歉,该招考已过报名时间!']); } //基础信息的检查 $rules = [ 'realname' => 'required', 'sex' => 'required', 'birthday' => 'required', 'avatar' => 'required', 'nation' => 'required', 'native_place' => 'required', 'political_affiliation' => 'required', 'post_id' => 'required', 'house_register' => 'required', 'edu_type' => 'required', 'education' => 'required', 'school' => 'required', 'address' => 'required', 'mobile' => 'required', 'email' => 'required', 'card' => 'required', 'concat_name' => 'required', 'concat_mobile' => 'required', 'resume' => 'required', ]; $messages = [ 'realname.required' => '请填写姓名', 'sex.required' => '请填写性别', 'birthday.required' => '请填写出生日期', 'avatar.required' => '请上传彩色免冠照', 'nation.required' => '请填写民族', 'native_place.required' => '请填写籍贯', 'political_affiliation.required' => '请选择政治面貌', 'post_id.required' => '请选择报名岗位', 'house_register.required' => '请填写户籍所在地', 'edu_type.required' => '请选择教育类型', 'education.required' => '请输入学历', 'school.required' => '请输入毕业院校', 'address.required' => '请填写通信地址', 'mobile.required' => '请填写手机号码', 'email.required' => '请填写电子邮箱', 'card.required' => '请填写身份证号码', 'resume.required' => '请填写个人简历', 'concat_name.required' => '请填写联系人姓名', 'concat_mobile.required' => '请填写联系人手机号码', ]; $create_data = $request->all(); $validator = Validator::make($create_data, $rules, $messages); if ($validator->fails()) { $msg = $validator->errors()->all(); return response()->json(['status' => 0, 'msg' => $msg[0]]); } else { $data = $request->only('realname', 'sex', 'birthday', 'avatar', 'nation', 'native_place', 'political_affiliation', 'titles', 'join_time', 'work', 'house_register', 'edu_type', 'education', 'school', 'degree', 'pro', 'address', 'card', 'mobile', 'email', 'concat_name', 'concat_mobile', 'resume', 'post_id'); $post_info = RecruitPost::where('id', $data['post_id'])->where('recruit_id', $recruit_id)->first(); if (!$post_info['status'] || $post_info['deleted_at'] != null) { return response()->json(['status' => 0, 'msg' => '该岗位已失效']); } //获取操作符,是暂存还是提交 $operation = $request->input('operation'); if ($operation == 1) { $data['audit'] = 0;//暂存 } else { $data['audit'] = 1;//提交 } if (!empty($post_info['limit']) && json_decode($post_info['limit'])) { //岗位限制条件的判断 $post_limit = json_decode($post_info['limit'], true); foreach ($post_limit as $k => $v) { if ($k == 'birthday') { $value = str_replace('-', '', $data[$k]); } else { $value = $data[$k]; } switch ($v['op']) { case '=': if ($value != $v['value']) { return response()->json(['status' => 0, 'msg' => $v['msg']]); } break; case '>': if ($value <= $v['value']) { return response()->json(['status' => 0, 'msg' => $v['msg']]); } break; case '>=': if ($value < $v['value']) { return response()->json(['status' => 0, 'msg' => $v['msg']]); } break; case '<': if ($value >= $v['value']) { return response()->json(['status' => 0, 'msg' => $v['msg']]); } break; case '<=': if ($value > $v['value']) { return response()->json(['status' => 0, 'msg' => $v['msg']]); } break; case '!=': if ($value == $v['value']) { return response()->json(['status' => 0, 'msg' => $v['msg']]); } break; case 'like': if (strpos($value, $v['value']) === false) { return response()->json(['status' => 0, 'msg' => $v['msg']]); } break; case 'in': if (strpos($v['value'], $value) === false) { return response()->json(['status' => 0, 'msg' => $v['msg']]); } break; } } } //前置审核 判断完成,先将数据入报名信息基础表 //解析家庭成员数据 $familys = $request->input('family'); $family = []; foreach ($familys as $value) { $item = [ 'relation' => $value['relation'], 'realname' => $value['realname'], 'birthday' => $value['birthday'], 'political_affiliation' => $value['political_affiliation'], 'work' => $value['work'], ]; array_push($family, $item); } $data['family'] = json_encode($family); $appoint_info = RecruitAppointInfo::where('uid', $uid)->where('recruit_id', $recruit_id)->first(); if ($appoint_info) { //如果已有报名记录,进入修改阶段的处理流程 DB::beginTransaction(); try { RecruitAppointInfo::where('uid', $uid)->where('recruit_id', $recruit_id)->update($data); //分模块解析数据 $forms = explode(',', $recruit['forms']); //如果有加分模块 if (in_array('expand_special', $forms)) { $special = $request->input('special'); if ($special['point_apply']) { $special['material'] = json_encode($special['material']); } $hasRecord = RecruitAppointExpandSpecial::where('recruit_appoint_id', $appoint_info->id)->first(); if ($hasRecord) { RecruitAppointExpandSpecial::where('recruit_appoint_id', $appoint_info->id)->update($special); } else { $special['recruit_appoint_id'] = $appoint_info->id; RecruitAppointExpandSpecial::create($special); } } //如果有详情模块 if (in_array('detail', $forms)) { $detail = $request->input('detail'); $hasRecord = RecruitAppointDetail::where('recruit_appoint_id', $appoint_info->id)->first(); if ($hasRecord) { RecruitAppointDetail::where('recruit_appoint_id', $appoint_info->id)->update($detail); } else { $detail['recruit_appoint_id'] = $appoint_info->id; RecruitAppointDetail::create($detail); } } //如果有身份证明模块 if (in_array('identification', $forms)) { $identification = $request->input('identification'); $appoint_info->identification = json_encode($identification); $appoint_info->save(); } //如果有教育证明模块 if (in_array('education_certification', $forms)) { $education_certification = $request->input('education_certification'); $appoint_info->education_certification = json_encode($education_certification); $appoint_info->save(); } //如果有其他证明模块 if (in_array('other_certification', $forms)) { $other_certification = $request->input('other_certification'); if ($other_certification) { $appoint_info->other_certification = json_encode($other_certification); $appoint_info->save(); } } DB::commit(); $log = [ 'type' => 3, 'appoint_id' => $appoint_info->id, 'uid' => $uid, 'log' => '用户提交报名', ]; RecruitAppointLog::create($log); return ['status' => 1, 'msg' => '提交成功', 'data' => $appoint_info->id]; } catch (\Exception $e) { } } else { //没有报名记录,进入增加阶段的处理流程 DB::beginTransaction(); try { $data['uid'] = $uid; $data['recruit_id'] = $recruit_id; $result = RecruitAppointInfo::create($data); //分模块解析数据 $forms = explode(',', $recruit['forms']); //如果有加分模块 if (in_array('expand_special', $forms)) { $special = $request->input('special'); if ($special['point_apply']) { $special['material'] = json_encode($special['material']); } $special['recruit_appoint_id'] = $result->id; RecruitAppointExpandSpecial::create($special); } //如果有详情模块 if (in_array('detail', $forms)) { $detail = $request->input('detail'); $detail['recruit_appoint_id'] = $result->id; RecruitAppointDetail::create($detail); } //如果有身份证明模块 if (in_array('identification', $forms)) { $identification = $request->input('identification'); // $identifications = []; // foreach ($identification as $k => $v){ // array_push($identifications,$v['response']['path']); // } $result->identification = json_encode($identification); $result->save(); } //如果有教育证明模块 if (in_array('education_certification', $forms)) { $education_certification = $request->input('education_certification'); // $education_certifications = []; // foreach ($education_certification as $k => $v){ // array_push($education_certifications,$v['response']['path']); // } $result->education_certification = json_encode($education_certification); $result->save(); } //如果有其他证明模块 if (in_array('other_certification', $forms)) { $other_certification = $request->input('other_certification'); if ($other_certification) { // $other_certifications = []; // foreach ($other_certification as $k => $v){ // array_push($other_certifications,$v['response']['path']); // } $result->other_certification = json_encode($other_certification); $result->save(); } } DB::commit(); $log = [ 'type' => 3, 'appoint_id' => $result->id, 'uid' => $uid, 'log' => '用户首次提交报名', ]; RecruitAppointLog::create($log); return ['status' => 1, 'msg' => '提交成功', 'data' => $result->id]; } catch (\Exception $e) { DB::rollback(); return ['status' => 0, 'msg' => $e->getMessage()]; } } } } /** * 获得当前登录的用户 * @return \Illuminate\Contracts\Auth\Authenticatable|null */ public function getUser() { if (auth('web-member')->check()) { $user = auth('web-member')->user(); } else { $user = null; } return $user; } public function checkUserBasicInfo(Request $request) { $user = $this->getUser(); if (!empty($user)) { $uid = $user->id; } else { //$request->session()->put('url.intended', $request->server('HTTP_REFERER')); $arr = ['status' => 401, 'msg' => '请登录!','url' => $request->server('HTTP_REFERER')]; return $arr; } $info = RecruitAppointBasic::where('uid', $uid)->first(); if (empty($info) || empty($info['realname'])) { $arr = ['status' => 401, 'msg' => '请先完善招考基本信息', 'url' => route('mobile.person.recruitInfo')]; return $arr; } return ['status' => 200, 'msg' => '']; } public function checkIndexUser(Request $request) { $id = $request->input('id', 0); return redirect(route('mobile.recruit.show',['id'=>$id])); } }