IndexController.php 53 KB

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