IndexController.php 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044
  1. <?php
  2. namespace App\Http\Controllers\Web\Recruit;
  3. use App\Http\Controllers\Web\WebBaseController;
  4. use App\Models\RecruitAppointLog;
  5. use App\Models\RecruitTicket;
  6. use App\Validators\RecruitValidatorRequest;
  7. use Illuminate\Http\Request;
  8. use App\Models\Recruit;
  9. use App\Services\Recruit\RecruitService;
  10. use App\Models\RecruitAppointBasic;
  11. use App\Models\RecruitPost;
  12. use App\Models\RecruitAppointInfo;
  13. use think\Route;
  14. use Illuminate\Support\Facades\Validator;
  15. use Illuminate\Support\Facades\DB;
  16. use App\Models\RecruitAppointExpandSpecial;
  17. use App\Models\RecruitAppointDetail;
  18. use App\Models\RecruitArticle;
  19. class IndexController extends WebBaseController
  20. {
  21. protected $recruitService;
  22. public function __construct(RecruitService $recruitService)
  23. {
  24. $this->recruitService = $recruitService;
  25. }
  26. /**
  27. * 招考列表页
  28. * @param Request $request
  29. * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View|mixed|\think\response\View
  30. */
  31. public function index(Request $request)
  32. {
  33. $key = $request->input('key');
  34. $list = $this->recruitService->getRecruit($key, 10);
  35. $return_data = [
  36. 'list' => $list,
  37. 'key' => $key,
  38. ];
  39. return view('app.recruit.index', $return_data);
  40. }
  41. /**
  42. * 招考详情页
  43. * @param Request $request
  44. * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View|mixed|\think\response\Redirect|\think\response\View|void
  45. */
  46. public function show(Request $request)
  47. {
  48. $user = $this->getUser();
  49. if($user){
  50. $uid = $user->id;
  51. $utype = $user->utype;
  52. }else{
  53. $uid = 0;
  54. $utype = 0;
  55. }
  56. $id = $request->input('id', 0);
  57. if (empty($id)) {
  58. return $this->showMessage('抱歉,请输入指定的招考场次!', route('recruit.list'), true, '上一页', '2');
  59. }
  60. $recruit = Recruit::find($id);
  61. if (empty($recruit)) {
  62. return redirect(route('/recruit/list'));
  63. }
  64. $info = Recruit::parse_info($recruit);
  65. $appoint_info = RecruitAppointInfo::where('uid',$uid)->where('recruit_id',$id)->first();
  66. if(!$info->isApply && $appoint_info){
  67. $first_post = RecruitAppointLog::where('type',3)->where('uid',$uid)->orderBy('created_at','asc')->first();
  68. if($first_post){
  69. $info->isApply = 1;
  70. }
  71. }
  72. if($appoint_info){
  73. //笔试
  74. $pen_ticket = RecruitTicket::where('appoint_id',$appoint_info->id)->where('ex_type',1)->first();
  75. if($pen_ticket){
  76. $time = time();
  77. if(strtotime($pen_ticket->ex_start) < $time && strtotime($pen_ticket->ex_end) > $time){
  78. $appoint_info->pen_ticket = 1;
  79. }else{
  80. $appoint_info->pen_ticket = -1;
  81. }
  82. }else{
  83. $appoint_info->pen_ticket = 0;
  84. }
  85. //考核测试
  86. $check_ticket = RecruitTicket::where('appoint_id',$appoint_info->id)->where('ex_type',2)->first();
  87. if($check_ticket){
  88. $time = time();
  89. if(strtotime($check_ticket->ex_start) < $time && strtotime($check_ticket->ex_end) > $time){
  90. $appoint_info->check_ticket = 1;
  91. }else{
  92. $appoint_info->check_ticket = -1;
  93. }
  94. }else{
  95. $appoint_info->check_ticket = 0;
  96. }
  97. //面试
  98. $face_ticket = RecruitTicket::where('appoint_id',$appoint_info->id)->where('ex_type',3)->first();
  99. if($face_ticket && $appoint_info->face_audit == -1){
  100. $appoint_info->face_ticket = 1;
  101. }else{
  102. $appoint_info->face_ticket = 0;
  103. }
  104. }else{
  105. $appoint_info = new \stdClass();
  106. $appoint_info->pen_audit = 0;
  107. $appoint_info->post_id = 0;
  108. $appoint_info->pen_ticket = 0;
  109. $appoint_info->computer_ticket = 0;
  110. $appoint_info->face_ticket = 0;
  111. $appoint_info->check_ticket = 0;
  112. $appoint_info->realname = '';
  113. $appoint_info->card = '';
  114. $appoint_info->mobile = '';
  115. }
  116. $notice = $request->input('notice',0);
  117. if($notice){
  118. $public_notice_switch = 0;
  119. $public_notice = RecruitArticle::where('id',$notice)->where('released_at','<',time())->first();
  120. if (!empty($info)) {
  121. $view_data = [
  122. 'recruit' => $recruit,
  123. 'info' => $info,
  124. 'uid' => $uid,
  125. 'utype' => $utype,
  126. 'public_notice' => $public_notice,
  127. 'public_notice_switch' => $public_notice_switch,
  128. 'appoint_info' => $appoint_info
  129. ];
  130. return view('app.recruit.show')->with($view_data);
  131. } else {
  132. return back();
  133. }
  134. }else{
  135. $list = RecruitArticle::where('recruit_id',$id)->orderBy('created_at','desc')->where('released_at','<',time())->get();
  136. $public_notice_switch = 1;//有补充公告的模式
  137. if (!empty($info)) {
  138. $view_data = [
  139. 'recruit' => $recruit,
  140. 'info' => $info,
  141. 'uid' => $uid,
  142. 'utype' => $utype,
  143. 'list' => $list,
  144. 'public_notice_switch' => $public_notice_switch,
  145. 'appoint_info' => $appoint_info
  146. ];
  147. return view('app.recruit.show')->with($view_data);
  148. } else {
  149. return back();
  150. }
  151. }
  152. }
  153. /**
  154. * 报名功能页
  155. * @param Request $request
  156. * @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
  157. */
  158. public function sign_up(Request $request)
  159. {
  160. $user = $this->getUser();
  161. if (!empty($user)) {
  162. $uid = $user->id;
  163. } else {
  164. return redirect(route('login'));
  165. }
  166. //招考id
  167. $id = $request->input('id', 0);
  168. if (!$id) {
  169. return $this->showMessage('请选择招考项目!', route('home'), true, '上一页', '3');
  170. }
  171. //招考信息
  172. $recruit = Recruit::find($id);
  173. if(!$recruit['status']){
  174. return $this->showMessage('抱歉,该招考状态不正确,请联系客服!', route('recruit.show',array('id',$recruit['id'])), true, '上一页', '3');
  175. }
  176. if($recruit['current'] != 1){
  177. return $this->showMessage('抱歉,该招考报名通道已关闭,如有疑问,请联系客服!', route('recruit.show',array('id',$recruit['id'])), true, '上一页', '3');
  178. }
  179. $appoint_info = RecruitAppointInfo::where('uid',$uid)->where('recruit_id',$id)->first();
  180. $time = time();
  181. $formDisabled = 0;
  182. if(($time < strtotime($recruit['apply_start']) || strtotime($recruit['apply_end']) < $time)){//过了招考时间
  183. if(!$appoint_info){
  184. return $this->showMessage('抱歉,该招考已过报名时间或尚未开始!', route('recruit.show',array('id',$recruit['id'])), true, '上一页', '3');
  185. }
  186. if($appoint_info){
  187. //如果有报名记录,先查询首次报名是什么时候
  188. $first_post = RecruitAppointLog::where('type',3)->where('uid',$uid)->where('appoint_id',$appoint_info->id)->orderBy('created_at','asc')->first();
  189. if(!$first_post){//没有记录代表只是暂存
  190. return $this->showMessage('抱歉,该招考已过报名时间或尚未开始!', route('recruit.show',array('id',$recruit['id'])), true, '上一页', '3');
  191. }
  192. // $has_late_post = RecruitAppointLog::where('type',3)->where('uid',$uid)->where('created_at','>',$recruit['apply_end'])->first();//查找在过了报名时间后,有报名记录,且仍是审核失败的报名记录,看其是否在报名时间后是否有再次提交的记录
  193. // if($has_late_post){
  194. // $formDisabled = 1;
  195. // }else{
  196. // $formDisabled = 0;
  197. // }
  198. }
  199. }
  200. $view_data['module'] = $forms = explode(',', $recruit['forms']);
  201. //查询报名表是否已有记录
  202. if($appoint_info){
  203. //如果已有该场次的报名记录,读取录入的数据集合
  204. $user_info = $appoint_info;
  205. $user_info['sex'] = (string)$user_info['sex'];
  206. $user_info['edu_type'] = (string)$user_info['edu_type'];
  207. $user_info['family'] = json_decode($user_info['family']);
  208. if(in_array('expand_special',$forms)){
  209. $special = RecruitAppointExpandSpecial::where('recruit_appoint_id',$user_info['id'])->first();
  210. if(json_decode($special['material'])){
  211. $material = json_decode($special['material'],true);
  212. foreach ($material as $k => $v){
  213. if(array_key_exists('response',$v)){
  214. $material[$k]['url'] = $v['response']['path'];
  215. }
  216. }
  217. }else{
  218. $material = [];
  219. }
  220. $user_info['special'] = [
  221. 'point_apply' => (string)$special['point_apply'],
  222. 'condition' => $special['condition'],
  223. 'material' => $material
  224. ];
  225. }
  226. if(in_array('detail',$forms)){
  227. $detail = RecruitAppointDetail::where('recruit_appoint_id',$user_info['id'])->first();
  228. if($detail){
  229. $user_info['detail'] = $detail->toArray();
  230. }else{
  231. $user_info['detail'] = [
  232. 'train' => '',
  233. 'rewards_and_punishments' => '',
  234. 'introduce' => ''
  235. ];
  236. }
  237. }
  238. //如果有身份证明模块
  239. if(in_array('identification',$forms)){
  240. if(json_decode($user_info['identification'])){
  241. $identification = json_decode($user_info['identification'],true);
  242. foreach ($identification as $k => $v){
  243. if(array_key_exists('response',$v)){
  244. $identification[$k]['url'] = $v['response']['path'];
  245. }
  246. }
  247. }else{
  248. $identification = [];
  249. }
  250. $user_info['identification'] = $identification;
  251. }
  252. //如果有教育证明模块
  253. if(in_array('education_certification',$forms)){
  254. if(json_decode($user_info['education_certification'])){
  255. $education_certification = json_decode($user_info['education_certification'],true);
  256. foreach ($education_certification as $k => $v){
  257. if(array_key_exists('response',$v)){
  258. $education_certification[$k]['url'] = $v['response']['path'];
  259. }
  260. }
  261. }else{
  262. $education_certification = [];
  263. }
  264. $user_info['education_certification'] = $education_certification;
  265. }
  266. //如果有其他证明模块
  267. if(in_array('other_certification',$forms)){
  268. if(json_decode($user_info['other_certification'])){
  269. $other_certification = json_decode($user_info['other_certification'],true);
  270. foreach ($other_certification as $k => $v){
  271. if(array_key_exists('response',$v)){
  272. $other_certification[$k]['url'] = $v['response']['path'];
  273. }
  274. }
  275. }else{
  276. $other_certification = [];
  277. }
  278. $user_info['other_certification'] = $other_certification;
  279. }
  280. //获取最新的报名审核信息
  281. $logs = RecruitAppointLog::where('appoint_id',$user_info->id)->where('step',1)->where('type',2)->orderBy('created_at','desc')->first();
  282. if($logs){
  283. $user_info['audit_log'] = $logs->log;
  284. }else{
  285. $user_info['audit_log'] = '';
  286. }
  287. //获取提交报名的次数
  288. $number = RecruitAppointLog::where('appoint_id',$user_info->id)->where('step',1)->where('type',3)->count();
  289. $post_number = $number+1;//todo
  290. }
  291. else{
  292. $post_number = 1;
  293. //如果没有,结合基础数据及模块表单信息,制作数据对象
  294. $user_info = RecruitAppointBasic::where('uid',$uid)->first();
  295. if(!$user_info){
  296. //没有基础信息跳转完善route('person.recruitInfo')
  297. return $this->showMessage('请先完善招考基础信息!', route('person.recruitInfo',array('recruit_id',$id)), true, '上一页', '3');
  298. }
  299. $user_info['sex'] = (string)$user_info['sex'];
  300. $user_info['edu_type'] = (string)$user_info['edu_type'];
  301. $user_info['family'] = json_decode($user_info['family']);
  302. if(in_array('expand_special',$forms)){
  303. $user_info['special'] = [
  304. 'point_apply' => '0',
  305. 'condition' => '',
  306. 'material' => []
  307. ];
  308. }
  309. if(in_array('detail',$forms)){
  310. $user_info['detail'] = [
  311. 'train' => '',
  312. 'rewards_and_punishments' => '',
  313. 'introduce' => ''
  314. ];
  315. }
  316. if(in_array('identification',$forms)){
  317. $user_info['identification'] = [];
  318. }
  319. if(in_array('education_certification',$forms)){
  320. $user_info['education_certification'] = [];
  321. }
  322. if(in_array('other_certification',$forms)){
  323. $user_info['other_certification'] = [];
  324. }
  325. }
  326. $user_info['recruit_id'] = $id;
  327. $user_info['operation'] = 1;
  328. //招考岗位
  329. $where_post[] = ['recruit_id', '=', $id];
  330. $recruit_post = RecruitPost::where($where_post)->get();
  331. $post = [];
  332. $post_limit = [];
  333. foreach ($recruit_post as $value){
  334. $item = [
  335. 'value' => $value['id'],
  336. 'label' => $value['code'] . " " . $value['name']
  337. ];
  338. $post_limit[$value['id']] = json_decode($value['limit']);
  339. array_push($post,$item);
  340. }
  341. $view_data['appoint_info'] = $user_info;
  342. $view_data['post'] = json_encode($post);
  343. $view_data['post_number'] = $post_number;
  344. $view_data['post_times'] = $recruit['post_times'];
  345. $view_data['post_limit'] = json_encode($post_limit);
  346. $view_data['formDisable'] = $formDisabled;
  347. $view_data['title'] = $recruit->company;
  348. return view('app.recruit.sign_up',$view_data);
  349. }
  350. /**
  351. * 提交报名的处理程序
  352. * @param Request $request
  353. * @return array|\Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\think\response\Redirect|void
  354. */
  355. public function saveSignUp(Request $request)
  356. {
  357. $user = $this->getUser();
  358. if (!empty($user)) {
  359. $uid = $user->id;
  360. } else {
  361. return redirect(route('login'));
  362. }
  363. $recruit_id = $request->input('recruit_id', 0);
  364. if (!$recruit_id) {
  365. return response()->json(['status' => 0,'msg' => '请选择招考项目!']);
  366. }
  367. $recruit = Recruit::find($recruit_id);
  368. if(!$recruit['status']){
  369. return response()->json(['status' => 0,'msg' => '抱歉,该招考状态不正确,请联系客服!']);
  370. }
  371. if($recruit['current'] != 1){
  372. return response()->json(['status' => 0,'msg' => '抱歉,该招考报名通道已关闭,如有疑问,请联系客服!']);
  373. }
  374. $time = time();
  375. $appoint_info = RecruitAppointInfo::where('uid',$uid)->where('recruit_id',$recruit_id)->first();
  376. if(($time < strtotime($recruit['apply_start']) || strtotime($recruit['apply_end']) < $time)){//过了招考时间
  377. if($appoint_info){
  378. //如果有报名记录,先查询首次报名是什么时候
  379. $first_post = RecruitAppointLog::where('type',3)->where('uid',$uid)->orderBy('created_at','asc')->first();
  380. if(!$first_post){//没有记录代表只是暂存
  381. return response()->json(['status' => 0,'msg' => '抱歉,该招考已过报名时间!']);
  382. }
  383. }
  384. if(!$appoint_info){
  385. return response()->json(['status' => 0,'msg' => '抱歉,该招考已过报名时间!']);
  386. }
  387. }
  388. //基础信息的检查
  389. $rules = [
  390. 'realname' => 'required',
  391. 'sex' => 'required',
  392. 'birthday' => 'required',
  393. 'avatar' => 'required',
  394. 'nation' => 'required',
  395. 'native_place' => 'required',
  396. 'political_affiliation' => 'required',
  397. 'post_id' => 'required',
  398. 'house_register' => 'required',
  399. //'edu_type' => 'required',
  400. 'education' => 'required',
  401. 'school' => 'required',
  402. 'address' => 'required',
  403. 'mobile' => 'required',
  404. 'email' => 'required',
  405. 'card' => 'required',
  406. 'concat_name' => 'required',
  407. 'concat_mobile' => 'required',
  408. 'resume' => 'required'
  409. ];
  410. $messages = [
  411. 'realname.required' => '请填写姓名',
  412. 'sex.required' => '请填写性别',
  413. 'birthday.required' => '请填写出生日期',
  414. 'avatar.required' => '请上传彩色免冠照',
  415. 'nation.required' => '请填写民族',
  416. 'native_place.required' => '请填写籍贯',
  417. 'political_affiliation.required' => '请选择政治面貌',
  418. 'post_id.required' => '请选择报名岗位',
  419. 'house_register.required' => '请填写户籍所在地',
  420. //'edu_type.required' => '请选择教育类型',
  421. 'education.required' => '请输入学历',
  422. 'school.required' => '请输入毕业院校',
  423. 'address.required' => '请填写通信地址',
  424. 'mobile.required' => '请填写手机号码',
  425. 'email.required' => '请填写电子邮箱',
  426. 'card.required' => '请填写身份证号码',
  427. 'resume.required' => '请填写个人简历',
  428. 'concat_name.required' => '请填写联系人姓名',
  429. 'concat_mobile.required' => '请填写联系人手机号码'
  430. ];
  431. $create_data = $request->all();
  432. $validator = Validator::make($create_data,$rules,$messages);
  433. if ($validator->fails()) {
  434. $msg = $validator->errors()->all();
  435. return response()->json(['status' => 0,'msg' => $msg[0]]);
  436. }else{
  437. $data = $request->only('realname','sex','birthday','avatar','nation','native_place','political_affiliation','titles','join_time','work','house_register','education','school','degree','pro','address','card','mobile','email','concat_name','concat_mobile','resume','post_id');
  438. //身份证判断出生日期和性别
  439. $year = substr($data['card'],6,4);
  440. $month = substr($data['card'],10,2);
  441. $day = substr($data['card'],12,2);
  442. if($year.'-'.$month.'-'.$day != $data['birthday']){
  443. $data['birthday'] = $year.'-'.$month.'-'.$day;
  444. }
  445. if(intval(substr($data['card'],16,1)) % 2 == 0){
  446. $data['sex'] = 0;
  447. }else{
  448. $data['sex'] = 1;
  449. }
  450. $post_info = RecruitPost::where('id',$data['post_id'])->where('recruit_id',$recruit_id)->first();
  451. if(!$post_info['status'] || $post_info['deleted_at'] != null){
  452. return response()->json(['status' => 0,'msg' => '该岗位已失效']);
  453. }
  454. //获取操作符,是暂存还是提交
  455. $operation = $request->input('operation');
  456. if($operation == 1){
  457. $data['audit'] = 0;//暂存
  458. }else{
  459. $data['audit'] = 1;//提交
  460. }
  461. if(!empty($post_info['limit']) && json_decode($post_info['limit'])){
  462. //岗位限制条件的判断
  463. $post_limit = json_decode($post_info['limit'],true);
  464. if(is_array($post_limit)){
  465. foreach($post_limit as $k => $v){
  466. if($k == 'birthday'){
  467. $value = str_replace('-','',$data[$k]);
  468. }else{
  469. $value = $data[$k];
  470. }
  471. switch ($v['op']){
  472. case '=':
  473. if($value != $v['value']){
  474. return response()->json(['status' => 0,'msg' => $v['msg']]);
  475. }
  476. break;
  477. case '>':
  478. if($value <= $v['value']){
  479. return response()->json(['status' => 0,'msg' => $v['msg']]);
  480. }
  481. break;
  482. case '>=':
  483. if($value < $v['value']){
  484. return response()->json(['status' => 0,'msg' => $v['msg']]);
  485. }
  486. break;
  487. case '<':
  488. if($value >= $v['value']){
  489. return response()->json(['status' => 0,'msg' => $v['msg']]);
  490. }
  491. break;
  492. case '<=':
  493. if($value > $v['value']){
  494. return response()->json(['status' => 0,'msg' => $v['msg']]);
  495. }
  496. break;
  497. case '!=':
  498. if($value == $v['value']){
  499. return response()->json(['status' => 0,'msg' => $v['msg']]);
  500. }
  501. break;
  502. case 'like':
  503. if(strpos($value,$v['value']) === false){
  504. return response()->json(['status' => 0,'msg' => $v['msg']]);
  505. }
  506. break;
  507. case 'in':
  508. if(strpos($v['value'],$value) === false){
  509. return response()->json(['status' => 0,'msg' => $v['msg']]);
  510. }
  511. break;
  512. }
  513. }
  514. }
  515. }
  516. //前置审核 判断完成,先将数据入报名信息基础表
  517. //解析家庭成员数据
  518. $familys = $request->input('family');
  519. $family = [];
  520. if(is_array($familys)){
  521. foreach ($familys as $value){
  522. $item = [
  523. 'relation' => $value['relation'],
  524. 'realname' => $value['realname'],
  525. 'birthday' => $value['birthday'],
  526. 'political_affiliation' => $value['political_affiliation'],
  527. 'work' => $value['work']
  528. ];
  529. array_push($family,$item);
  530. }
  531. }
  532. $data['family'] = json_encode($family);
  533. if($appoint_info){
  534. //如果已有报名记录,进入修改阶段的处理流程
  535. DB::beginTransaction();
  536. try{
  537. RecruitAppointInfo::where('uid',$uid)->where('recruit_id',$recruit_id)->update($data);
  538. //分模块解析数据
  539. $forms = explode(',', $recruit['forms']);
  540. //如果有加分模块
  541. if(in_array('expand_special',$forms)){
  542. $special = $request->input('special');
  543. if($special['point_apply']){
  544. //删除掉没有成功返回路径的图片
  545. if(is_array($special['material'])){
  546. foreach ($special['material'] as $k => $v){
  547. if(!array_key_exists('response',$v)){
  548. unset($special['material'][$k]);
  549. }
  550. }
  551. }
  552. $special['material'] = json_encode($special['material']);
  553. }else{
  554. $special['material'] = json_encode([]);
  555. }
  556. $hasRecord = RecruitAppointExpandSpecial::where('recruit_appoint_id',$appoint_info->id)->first();
  557. if($hasRecord){
  558. RecruitAppointExpandSpecial::where('recruit_appoint_id',$appoint_info->id)->update($special);
  559. }else{
  560. $special['recruit_appoint_id'] = $appoint_info->id;
  561. RecruitAppointExpandSpecial::create($special);
  562. }
  563. }
  564. //如果有详情模块
  565. if(in_array('detail',$forms)){
  566. $detail = $request->input('detail');
  567. $hasRecord = RecruitAppointDetail::where('recruit_appoint_id',$appoint_info->id)->first();
  568. if($hasRecord){
  569. RecruitAppointDetail::where('recruit_appoint_id',$appoint_info->id)->update($detail);
  570. }else{
  571. $detail['recruit_appoint_id'] = $appoint_info->id;
  572. RecruitAppointDetail::create($detail);
  573. }
  574. }
  575. //如果有身份证明模块
  576. if(in_array('identification',$forms)){
  577. $identification = $request->input('identification');
  578. if(is_array($identification)){
  579. //删除掉没有成功返回路径的图片
  580. foreach ($identification as $k => $v){
  581. if(!array_key_exists('response',$v)){
  582. unset($identification[$k]);
  583. }
  584. }
  585. }
  586. $appoint_info->identification = json_encode($identification);
  587. $appoint_info->save();
  588. }
  589. //如果有教育证明模块
  590. if(in_array('education_certification',$forms)){
  591. $education_certification = $request->input('education_certification');
  592. if(is_array($education_certification)){
  593. //删除掉没有成功返回路径的图片
  594. foreach ($education_certification as $k => $v){
  595. if(!array_key_exists('response',$v)){
  596. unset($education_certification[$k]);
  597. }
  598. }
  599. }
  600. $appoint_info->education_certification = json_encode($education_certification);
  601. $appoint_info->save();
  602. }
  603. //如果有其他证明模块
  604. if(in_array('other_certification',$forms)){
  605. $other_certification = $request->input('other_certification');
  606. if(is_array($other_certification)){
  607. //删除掉没有成功返回路径的图片
  608. foreach ($other_certification as $k => $v){
  609. if(!array_key_exists('response',$v)){
  610. unset($other_certification[$k]);
  611. }
  612. }
  613. }
  614. if($other_certification){
  615. $appoint_info->other_certification = json_encode($other_certification);
  616. $appoint_info->save();
  617. }
  618. }
  619. DB::commit();
  620. if($operation == 2){
  621. $log = [
  622. 'type' => 3,
  623. 'appoint_id'=> $appoint_info->id,
  624. 'uid' => $uid,
  625. 'log' => '用户提交报名'
  626. ];
  627. RecruitAppointLog::create($log);
  628. return ['status' => 1, 'msg' => '提交成功', 'data' => $appoint_info->id];
  629. }else{
  630. return ['status' => 1, 'msg' => '资料保存成功,请尽快完善并提交', 'data' => $appoint_info->id];
  631. }
  632. } catch (\Exception $e){
  633. DB::rollback();
  634. return ['status' => 0, 'msg' => $e->getMessage()];
  635. }
  636. }else{
  637. //没有报名记录,进入增加阶段的处理流程
  638. DB::beginTransaction();
  639. try{
  640. $data['uid'] = $uid;
  641. $data['recruit_id'] = $recruit_id;
  642. $result = RecruitAppointInfo::create($data);
  643. //分模块解析数据
  644. $forms = explode(',', $recruit['forms']);
  645. //如果有加分模块
  646. if(in_array('expand_special',$forms)){
  647. $special = $request->input('special');
  648. if($special['point_apply']){
  649. if(is_array($special['material'])){
  650. //删除掉没有成功返回路径的图片
  651. foreach ($special['material'] as $k => $v){
  652. if(!array_key_exists('response',$v)){
  653. unset($special['material'][$k]);
  654. }
  655. }
  656. }
  657. $special['material'] = json_encode($special['material']);
  658. }
  659. $special['recruit_appoint_id'] = $result->id;
  660. RecruitAppointExpandSpecial::create($special);
  661. }
  662. //如果有详情模块
  663. if(in_array('detail',$forms)){
  664. $detail = $request->input('detail');
  665. $detail['recruit_appoint_id'] = $result->id;
  666. RecruitAppointDetail::create($detail);
  667. }
  668. //如果有身份证明模块
  669. if(in_array('identification',$forms)){
  670. $identification = $request->input('identification');
  671. if(is_array($identification)){
  672. //删除掉没有成功返回路径的图片
  673. foreach ($identification as $k => $v){
  674. if(!array_key_exists('response',$v)){
  675. unset($identification[$k]);
  676. }
  677. }
  678. }
  679. $result->identification = json_encode($identification);
  680. $result->save();
  681. }
  682. //如果有教育证明模块
  683. if(in_array('education_certification',$forms)){
  684. $education_certification = $request->input('education_certification');
  685. if(is_array($education_certification)){
  686. //删除掉没有成功返回路径的图片
  687. foreach ($education_certification as $k => $v){
  688. if(!array_key_exists('response',$v)){
  689. unset($education_certification[$k]);
  690. }
  691. }
  692. }
  693. $result->education_certification = json_encode($education_certification);
  694. $result->save();
  695. }
  696. //如果有其他证明模块
  697. if(in_array('other_certification',$forms)){
  698. $other_certification = $request->input('other_certification');
  699. if($other_certification){
  700. if(is_array($other_certification)){
  701. //删除掉没有成功返回路径的图片
  702. foreach ($other_certification as $k => $v){
  703. if(!array_key_exists('response',$v)){
  704. unset($other_certification[$k]);
  705. }
  706. }
  707. }
  708. $result->other_certification = json_encode($other_certification);
  709. $result->save();
  710. }
  711. }
  712. DB::commit();
  713. if($operation == 2){
  714. $log = [
  715. 'type' => 3,
  716. 'appoint_id'=> $result->id,
  717. 'uid' => $uid,
  718. 'log' => '用户首次提交报名'
  719. ];
  720. RecruitAppointLog::create($log);
  721. return ['status' => 1, 'msg' => '提交成功', 'data' => $result->id];
  722. }else{
  723. return ['status' => 1, 'msg' => '资料保存成功,请尽快完善并提交', 'data' => $result->id];
  724. }
  725. } catch (\Exception $e){
  726. DB::rollback();
  727. return ['status' => 0, 'msg' => $e->getMessage()];
  728. }
  729. }
  730. }
  731. }
  732. /**
  733. * 获得当前登录的用户
  734. * @return \Illuminate\Contracts\Auth\Authenticatable|null
  735. */
  736. public function getUser()
  737. {
  738. if (auth('web-member')->check()) {
  739. $user = auth('web-member')->user();
  740. } else {
  741. $user = null;
  742. }
  743. return $user;
  744. }
  745. public function checkUserBasicInfo()
  746. {
  747. $user = $this->getUser();
  748. if (!empty($user)) {
  749. $uid = $user->id;
  750. } else {
  751. $arr = ['status' => 401, 'msg'=>'请登录!'];
  752. return $arr;
  753. }
  754. $info = RecruitAppointBasic::where('uid',$uid)->first();
  755. if (empty($info)){
  756. $arr = ['status'=>401,'msg'=>'请先完善招考基本信息','url'=> route('recruit.recruitInfo')];
  757. return $arr;
  758. }
  759. return ['status' => 200, 'msg' => ''];
  760. }
  761. public function person_recruit()
  762. {
  763. $user = auth('web-member')->user();
  764. $list = RecruitAppointInfo::where('uid',$user->id)
  765. ->join('recruit', 'recruit.id', '=', 'recruit_appoint_info.recruit_id', 'left')
  766. ->join('recruit_post', 'recruit_post.id', '=', 'recruit_appoint_info.post_id', 'left')
  767. ->select('recruit.name as recruit_name','recruit_appoint_info.*','recruit_post.code','recruit_post.name')
  768. ->get();
  769. return view('app.person.recruit')->with(['list' => $list,'total' => count($list)]);
  770. }
  771. public function recruit_info(Request $request)
  772. {
  773. $user = auth('web-member')->user();
  774. $info = RecruitAppointBasic::where('uid',$user->id)->first();
  775. if(!$info){
  776. $info = [
  777. 'realname' => '',
  778. 'sex' => '0',
  779. 'birthday' => '',
  780. 'avatar' => '',
  781. 'nation' => '',
  782. 'native_place' => '',
  783. 'political_affiliation' => '',
  784. 'titles' => '',
  785. 'work' => '',
  786. 'house_register' => '',
  787. 'join_time' => '',
  788. 'edu_type' => '',
  789. 'education' => '',
  790. 'school' => '',
  791. 'degree' => '',
  792. 'pro' => '',
  793. 'address' => '',
  794. 'card' => '',
  795. 'mobile' => '',
  796. 'email' => '',
  797. 'concat_name' => '',
  798. 'concat_mobile' => '',
  799. 'resume' => '',
  800. 'family' => [
  801. [
  802. 'relation' => '',
  803. 'realname' => '',
  804. 'birthday' => '',
  805. 'political_affiliation' => '',
  806. 'work' => ''
  807. ]
  808. ],
  809. 'is_push' => '1'
  810. ];
  811. }else{
  812. $info->sex = (string)$info->sex;
  813. $info->edu_type = (string)$info->edu_type;
  814. $info->is_push = (string)$info->is_push;
  815. $info->family = empty($info->family) ? [[
  816. 'relation' => '',
  817. 'realname' => '',
  818. 'birthday' => '',
  819. 'political_affiliation' => '',
  820. 'work' => ''
  821. ]] : json_decode($info->family);
  822. }
  823. $recruit_id = $request->input('recruit_id',0);
  824. return view('app.person.recruit_info',[
  825. 'info' => json_encode($info),
  826. 'recruit_id'=> $recruit_id
  827. ]);
  828. }
  829. public function saveRecruitInfo(RecruitValidatorRequest $request)
  830. {
  831. $user = auth('web-member')->user();
  832. $basic = RecruitAppointBasic::where('uid',$user->id)->first();
  833. $data = $request->only('realname','sex','birthday','avatar','nation','native_place','political_affiliation','titles','work','house_register','join_time','education','school','degree','pro','address','card','mobile','email','concat_name','concat_mobile','resume','family','is_push');
  834. if(count($data['family']) > 0){
  835. $data['family'] = json_encode($data['family']);
  836. }
  837. if($basic){
  838. //更新基础信息
  839. $res = RecruitAppointBasic::where('uid',$user->id)->update($data);
  840. if (!$res) {
  841. return response()->json(['status'=>0,'msg'=>'保存失败,请联系客服']);
  842. }else{
  843. return response()->json(['status'=>1,'msg'=>'个人基础信息保存成功,快去报名吧!']);
  844. }
  845. }else{
  846. //新增基础信息
  847. $data['uid'] = $user->id;
  848. $res = RecruitAppointBasic::create($data);
  849. if (!$res) {
  850. return response()->json(['status'=>0,'msg'=>'保存失败,请联系客服']);
  851. }else{
  852. return response()->json(['status'=>1,'msg'=>'个人基础信息保存成功,快去报名吧!']);
  853. }
  854. }
  855. }
  856. public function pen_ticket(Request $request)
  857. {
  858. $user = $this->getUser();
  859. if (!empty($user)) {
  860. $uid = $user->id;
  861. } else {
  862. return $this->showMessage('请登录!', route('home'), true, '上一页', '3');
  863. }
  864. $recruit_id = $request->input('recruit_id');
  865. $appoint_info = RecruitAppointInfo::where('uid',$uid)->where('recruit_id',$recruit_id)->first();
  866. if($appoint_info){
  867. $pen_ticket = RecruitTicket::where('appoint_id',$appoint_info->id)->where('ex_type',1)->first();
  868. if($pen_ticket){
  869. $time = time();
  870. if(strtotime($pen_ticket->ex_start) < $time && strtotime($pen_ticket->ex_end) > $time){
  871. RecruitTicket::where('appoint_id',$appoint_info->id)->update(['ex_status' => 1]);
  872. $recruit = Recruit::where('id',$recruit_id)->first();
  873. $post_data = RecruitPost::where('recruit_id',$recruit_id)->where('status',1)->selectRaw('id, CONCAT(code," ",name) as post')->pluck('post', 'id');
  874. $name = $recruit->name_en;
  875. $date = date("Y-m-d",strtotime($recruit->created_at));
  876. $filename = date("Y-m-17",time()) . '_' . $appoint_info->realname . '_' . $appoint_info->card . '_' . $post_data[$appoint_info->post_id];
  877. $file = base_path() . "/storage/app/public/recruit/ticket/pdf/{$date}/{$name}/pen/" . $filename . '_create.pdf';
  878. if(file_exists($file)){
  879. header('Content-Description: File Transfer');
  880. header('Content-Type: application/octet-stream');
  881. header('Content-Disposition: attachment; filename='.basename($file));
  882. header('Content-Transfer-Encoding: binary');
  883. header('Expires: 0');
  884. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  885. header('Pragma: public');
  886. header('Content-Length: ' . filesize($file));
  887. ob_clean(); //重要的就是这个函数的调用, 清空但不关闭输出缓存, 否则下载的文件头两个字符会是0a
  888. flush();
  889. readfile($file);
  890. }
  891. }else{
  892. return $this->showMessage('非打印时间!', route('home'), true, '上一页', '3');
  893. }
  894. }else{
  895. return $this->showMessage('暂无准考证可以打印!', route('home'), true, '上一页', '3');
  896. }
  897. }else{
  898. return $this->showMessage('暂无准考证可以打印!', route('home'), true, '上一页', '3');
  899. }
  900. }
  901. public function check_ticket(Request $request)
  902. {
  903. $user = $this->getUser();
  904. if (!empty($user)) {
  905. $uid = $user->id;
  906. } else {
  907. return $this->showMessage('请登录!', route('home'), true, '上一页', '3');
  908. }
  909. $recruit_id = $request->input('recruit_id');
  910. $appoint_info = RecruitAppointInfo::where('uid',$uid)->where('recruit_id',$recruit_id)->first();
  911. if($appoint_info){
  912. $check_ticket = RecruitTicket::where('appoint_id',$appoint_info->id)->where('ex_type',2)->first();
  913. if($check_ticket){
  914. $time = time();
  915. if(strtotime($check_ticket->ex_start) < $time && strtotime($check_ticket->ex_end) > $time){
  916. RecruitTicket::where('appoint_id',$appoint_info->id)->update(['ex_status' => 1]);
  917. $recruit = Recruit::where('id',$recruit_id)->first();
  918. $post_data = RecruitPost::where('recruit_id',$recruit_id)->where('status',1)->selectRaw('id, CONCAT(code," ",name) as post')->pluck('post', 'id');
  919. $name = $recruit->name_en;
  920. $date = date("Y-m-d",strtotime($recruit->created_at));
  921. $filename = date("Y-m-18",time()) . '_' . $appoint_info->realname . '_' . $appoint_info->card . '_' . $post_data[$appoint_info->post_id];
  922. $file = base_path() . "/storage/app/public/recruit/ticket/pdf/{$date}/{$name}/check/" . $filename . '.pdf';
  923. if(file_exists($file)){
  924. header('Content-Description: File Transfer');
  925. header('Content-Type: application/octet-stream');
  926. header('Content-Disposition: attachment; filename='.basename($file));
  927. header('Content-Transfer-Encoding: binary');
  928. header('Expires: 0');
  929. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  930. header('Pragma: public');
  931. header('Content-Length: ' . filesize($file));
  932. ob_clean(); //重要的就是这个函数的调用, 清空但不关闭输出缓存, 否则下载的文件头两个字符会是0a
  933. flush();
  934. readfile($file);
  935. }
  936. }else{
  937. return $this->showMessage('非打印时间!', route('home'), true, '上一页', '3');
  938. }
  939. }else{
  940. return $this->showMessage('暂无准考证可以打印!', route('home'), true, '上一页', '3');
  941. }
  942. }else{
  943. return $this->showMessage('暂无准考证可以打印!', route('home'), true, '上一页', '3');
  944. }
  945. }
  946. public function face_ticket(Request $request)
  947. {
  948. $user = $this->getUser();
  949. if (!empty($user)) {
  950. $uid = $user->id;
  951. } else {
  952. return $this->showMessage('请登录!', route('home'), true, '上一页', '3');
  953. }
  954. $recruit_id = $request->input('recruit_id');
  955. $appoint_info = RecruitAppointInfo::where('uid',$uid)->where('recruit_id',$recruit_id)->first();
  956. if($appoint_info){
  957. $face_ticket = RecruitTicket::where('appoint_id',$appoint_info->id)->where('ex_type',3)->first();
  958. if($face_ticket){
  959. $time = time();
  960. if(strtotime($face_ticket->ex_start) < $time && strtotime($face_ticket->ex_end) > $time){
  961. RecruitTicket::where('id',$face_ticket->id)->update(['ex_status' => 1]);
  962. $recruit = Recruit::where('id',$recruit_id)->first();
  963. $post_data = RecruitPost::where('recruit_id',$recruit_id)->where('status',1)->selectRaw('id, CONCAT(code," ",name) as post')->pluck('post', 'id');
  964. $name = $recruit->name_en;
  965. $date = date("Y-m-d",strtotime($recruit->created_at));
  966. $filename = $date . '_' . $appoint_info->realname . '_' . $appoint_info->card . '_' . $post_data[$appoint_info->post_id].'_create';
  967. $file = base_path() . "/storage/app/public/recruit/ticket/pdf/{$date}/{$name}/face/" . $filename . '.pdf';
  968. if(file_exists($file)){
  969. header('Content-Description: File Transfer');
  970. header('Content-Type: application/octet-stream');
  971. header('Content-Disposition: attachment; filename='.basename($file));
  972. header('Content-Transfer-Encoding: binary');
  973. header('Expires: 0');
  974. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  975. header('Pragma: public');
  976. header('Content-Length: ' . filesize($file));
  977. ob_clean(); //重要的就是这个函数的调用, 清空但不关闭输出缓存, 否则下载的文件头两个字符会是0a
  978. flush();
  979. readfile($file);
  980. }
  981. }else{
  982. return $this->showMessage('非打印时间!', route('home'), true, '上一页', '3');
  983. }
  984. }else{
  985. return $this->showMessage('暂无准考证可以打印!', route('home'), true, '上一页', '3');
  986. }
  987. }else{
  988. return $this->showMessage('暂无准考证可以打印!', route('home'), true, '上一页', '3');
  989. }
  990. }
  991. }