IndexController.php 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257
  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. if(in_array('internship',$forms)) {
  300. //如果已有该场次的报名记录,读取录入的数据集合
  301. $user_info = $appoint_info;
  302. $user_info['sex'] = (string)$user_info['sex'];
  303. $user_info['adjust'] = (string)$user_info['adjust'];
  304. $user_info['edu_type'] = (string)$user_info['edu_type'];
  305. $user_info['family'] = json_decode($user_info['family']);
  306. $detail = RecruitAppointDetail::where('recruit_appoint_id',$user_info['id'])->first();
  307. if($detail){
  308. $user_info['detail'] = $detail->toArray();
  309. }else{
  310. $user_info['detail'] = [
  311. 'rewards_and_punishments' => '',
  312. 'introduce' => ''
  313. ];
  314. }
  315. if(json_decode($user_info['identification'])){
  316. $identification = json_decode($user_info['identification'],true);
  317. foreach ($identification as $k => $v){
  318. if(array_key_exists('response',$v)){
  319. $identification[$k]['url'] = $v['response']['path'];
  320. }
  321. }
  322. }else{
  323. $identification = [];
  324. }
  325. $user_info['identification'] = $identification;
  326. if(json_decode($user_info['education_certification'])){
  327. $education_certification = json_decode($user_info['education_certification'],true);
  328. foreach ($education_certification as $k => $v){
  329. if(array_key_exists('response',$v)){
  330. $education_certification[$k]['url'] = $v['response']['path'];
  331. }
  332. }
  333. }else{
  334. $education_certification = [];
  335. }
  336. $user_info['education_certification'] = $education_certification;
  337. if(json_decode($user_info['other_certification'])){
  338. $other_certification = json_decode($user_info['other_certification'],true);
  339. foreach ($other_certification as $k => $v){
  340. if(array_key_exists('response',$v)){
  341. $other_certification[$k]['url'] = $v['response']['path'];
  342. }
  343. }
  344. }else{
  345. $other_certification = [];
  346. }
  347. $user_info['other_certification'] = $other_certification;
  348. //获取最新的报名审核信息
  349. $logs = RecruitAppointLog::where('appoint_id',$user_info->id)->where('step',1)->where('type',2)->orderBy('created_at','desc')->first();
  350. if($logs){
  351. $user_info['audit_log'] = $logs->log;
  352. }else{
  353. $user_info['audit_log'] = '';
  354. }
  355. }else{
  356. //如果已有该场次的报名记录,读取录入的数据集合
  357. $user_info = $appoint_info;
  358. $user_info['sex'] = (string)$user_info['sex'];
  359. $user_info['edu_type'] = (string)$user_info['edu_type'];
  360. $user_info['family'] = json_decode($user_info['family']);
  361. if(in_array('expand_special',$forms)){
  362. $special = RecruitAppointExpandSpecial::where('recruit_appoint_id',$user_info['id'])->first();
  363. if(json_decode($special['material'])){
  364. $material = json_decode($special['material'],true);
  365. foreach ($material as $k => $v){
  366. if(array_key_exists('response',$v)){
  367. $material[$k]['url'] = $v['response']['path'];
  368. }
  369. }
  370. }else{
  371. $material = [];
  372. }
  373. $user_info['special'] = [
  374. 'point_apply' => (string)$special['point_apply'],
  375. 'condition' => $special['condition'],
  376. 'material' => $material
  377. ];
  378. }
  379. if(in_array('detail',$forms)){
  380. $detail = RecruitAppointDetail::where('recruit_appoint_id',$user_info['id'])->first();
  381. if($detail){
  382. $user_info['detail'] = $detail->toArray();
  383. }else{
  384. $user_info['detail'] = [
  385. 'train' => '',
  386. 'rewards_and_punishments' => '',
  387. 'introduce' => ''
  388. ];
  389. }
  390. }
  391. //如果有身份证明模块
  392. if(in_array('identification',$forms)){
  393. if(json_decode($user_info['identification'])){
  394. $identification = json_decode($user_info['identification'],true);
  395. foreach ($identification as $k => $v){
  396. if(array_key_exists('response',$v)){
  397. $identification[$k]['url'] = $v['response']['path'];
  398. }
  399. }
  400. }else{
  401. $identification = [];
  402. }
  403. $user_info['identification'] = $identification;
  404. }
  405. //如果有教育证明模块
  406. if(in_array('education_certification',$forms)){
  407. if(json_decode($user_info['education_certification'])){
  408. $education_certification = json_decode($user_info['education_certification'],true);
  409. foreach ($education_certification as $k => $v){
  410. if(array_key_exists('response',$v)){
  411. $education_certification[$k]['url'] = $v['response']['path'];
  412. }
  413. }
  414. }else{
  415. $education_certification = [];
  416. }
  417. $user_info['education_certification'] = $education_certification;
  418. }
  419. //如果有其他证明模块
  420. if(in_array('other_certification',$forms)){
  421. if(json_decode($user_info['other_certification'])){
  422. $other_certification = json_decode($user_info['other_certification'],true);
  423. foreach ($other_certification as $k => $v){
  424. if(array_key_exists('response',$v)){
  425. $other_certification[$k]['url'] = $v['response']['path'];
  426. }
  427. }
  428. }else{
  429. $other_certification = [];
  430. }
  431. $user_info['other_certification'] = $other_certification;
  432. }
  433. //获取最新的报名审核信息
  434. $logs = RecruitAppointLog::where('appoint_id',$user_info->id)->where('step',1)->where('type',2)->orderBy('created_at','desc')->first();
  435. if($logs){
  436. $user_info['audit_log'] = $logs->log;
  437. }else{
  438. $user_info['audit_log'] = '';
  439. }
  440. //获取提交报名的次数
  441. // $number = RecruitAppointLog::where('appoint_id',$user_info->id)->where('step',1)->where('type',3)->count();
  442. // $post_number = $number+1;//todo
  443. }
  444. }
  445. else{
  446. //实习专场
  447. if(in_array('internship',$forms)){
  448. $user_info = json_encode([
  449. 'recruit_id' => $id,
  450. 'operation' => 1,
  451. 'realname' => '',
  452. 'sex' => '1',
  453. 'birthday' => '',
  454. 'card' => '',
  455. 'nation' => '',
  456. 'native_place' => '',
  457. 'political_affiliation' => '',
  458. 'join_time' => '',
  459. 'house_register' => '',
  460. 'education' => '',
  461. 'school' => '',
  462. 'pro' => '',
  463. 'adjust' => '',
  464. 'mobile' => '',
  465. 'email' => '',
  466. 'address' => '',
  467. 'post_id' => '',
  468. 'concat_name' => '',
  469. 'concat_mobile' => '',
  470. 'resume' => '',
  471. 'avatar' => '',
  472. 'family' => [
  473. [
  474. 'relation' => '',
  475. 'realname' => '',
  476. 'birthday' => '',
  477. 'political_affiliation' => '',
  478. 'work' => ''
  479. ]
  480. ],
  481. 'detail' => [
  482. 'rewards_and_punishments' => '',
  483. 'introduce' => ''
  484. ],
  485. 'identification' => [],
  486. 'education_certification' => [],
  487. 'other_certification' => []
  488. ]);
  489. }else{
  490. //如果没有,结合基础数据及模块表单信息,制作数据对象
  491. $user_info = RecruitAppointBasic::where('uid',$uid)->first();
  492. if(!$user_info){
  493. //没有基础信息跳转完善route('person.recruitInfo')
  494. return $this->showMessage('请先完善招考基础信息!', route('recruit.recruitInfo',array('recruit_id',$id)), true, '上一页', '3');
  495. }
  496. $user_info['sex'] = (string)$user_info['sex'];
  497. $user_info['edu_type'] = (string)$user_info['edu_type'];
  498. $user_info['family'] = json_decode($user_info['family']);
  499. if(in_array('expand_special',$forms)){
  500. $user_info['special'] = [
  501. 'point_apply' => '0',
  502. 'condition' => '',
  503. 'material' => []
  504. ];
  505. }
  506. if(in_array('detail',$forms)){
  507. $user_info['detail'] = [
  508. 'train' => '',
  509. 'rewards_and_punishments' => '',
  510. 'introduce' => ''
  511. ];
  512. }
  513. if(in_array('identification',$forms)){
  514. $user_info['identification'] = [];
  515. }
  516. if(in_array('education_certification',$forms)){
  517. $user_info['education_certification'] = [];
  518. }
  519. if(in_array('other_certification',$forms)){
  520. $user_info['other_certification'] = [];
  521. }
  522. $user_info['recruit_id'] = $id;
  523. $user_info['operation'] = 1;
  524. }
  525. }
  526. //招考岗位
  527. $where_post[] = ['recruit_id', '=', $id];
  528. $recruit_post = RecruitPost::where($where_post)->get();
  529. $post = [];
  530. $post_limit = [];
  531. foreach ($recruit_post as $value){
  532. $item = [
  533. 'value' => $value['id'],
  534. 'label' => $value['code'] . " " . $value['name']
  535. ];
  536. $post_limit[$value['id']] = json_decode($value['limit']);
  537. array_push($post,$item);
  538. }
  539. $view_data['appoint_info'] = $user_info;
  540. $view_data['post'] = json_encode($post);
  541. // $view_data['post_number'] = $post_number;
  542. // $view_data['post_times'] = $recruit['post_times'];
  543. $view_data['post_limit'] = json_encode($post_limit);
  544. $view_data['formDisable'] = $formDisabled;
  545. $view_data['title'] = $recruit->company;
  546. return view('app.recruit.sign_up',$view_data);
  547. }
  548. /**
  549. * 提交报名的处理程序
  550. * @param Request $request
  551. * @return array|\Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\think\response\Redirect|void
  552. */
  553. public function saveSignUp(Request $request)
  554. {
  555. $user = $this->getUser();
  556. if (!empty($user)) {
  557. $uid = $user->id;
  558. } else {
  559. return redirect(route('login'));
  560. }
  561. $recruit_id = $request->input('recruit_id', 0);
  562. if (!$recruit_id) {
  563. return response()->json(['status' => 0,'msg' => '请选择项目!']);
  564. }
  565. $recruit = Recruit::find($recruit_id);
  566. if(!$recruit['status']){
  567. return response()->json(['status' => 0,'msg' => '抱歉,该项目状态不正确,请联系客服!']);
  568. }
  569. if($recruit['current'] != 1){
  570. return response()->json(['status' => 0,'msg' => '抱歉,该项目报名通道已关闭,如有疑问,请联系客服!']);
  571. }
  572. $time = time();
  573. $appoint_info = RecruitAppointInfo::where('uid',$uid)->where('recruit_id',$recruit_id)->first();
  574. if(($time < strtotime($recruit['apply_start']) || strtotime($recruit['apply_end']) < $time)){//过了招考时间
  575. if($appoint_info){
  576. //如果有报名记录,先查询首次报名是什么时候
  577. $first_post = RecruitAppointLog::where('type',3)->where('uid',$uid)->orderBy('created_at','asc')->first();
  578. if(!$first_post){//没有记录代表只是暂存
  579. return response()->json(['status' => 0,'msg' => '抱歉,该项目已过报名时间!']);
  580. }
  581. }
  582. if(!$appoint_info){
  583. return response()->json(['status' => 0,'msg' => '抱歉,该项目已过报名时间!']);
  584. }
  585. }
  586. //基础信息的检查
  587. $rules = [
  588. 'realname' => 'required',
  589. 'sex' => 'required',
  590. 'birthday' => 'required',
  591. 'avatar' => 'required',
  592. 'nation' => 'required',
  593. 'native_place' => 'required',
  594. 'political_affiliation' => 'required',
  595. 'post_id' => 'required',
  596. 'house_register' => 'required',
  597. //'edu_type' => 'required',
  598. 'education' => 'required',
  599. 'school' => 'required',
  600. 'address' => 'required',
  601. 'mobile' => 'required',
  602. 'email' => 'required',
  603. 'card' => 'required',
  604. 'concat_name' => 'required',
  605. 'concat_mobile' => 'required',
  606. 'resume' => 'required'
  607. ];
  608. $messages = [
  609. 'realname.required' => '请填写姓名',
  610. 'sex.required' => '请填写性别',
  611. 'birthday.required' => '请填写出生日期',
  612. 'avatar.required' => '请上传彩色免冠照',
  613. 'nation.required' => '请填写民族',
  614. 'native_place.required' => '请填写籍贯',
  615. 'political_affiliation.required' => '请选择政治面貌',
  616. 'post_id.required' => '请选择报名岗位',
  617. 'house_register.required' => '请填写户籍所在地',
  618. //'edu_type.required' => '请选择教育类型',
  619. 'education.required' => '请输入学历',
  620. 'school.required' => '请输入毕业院校',
  621. 'address.required' => '请填写通信地址',
  622. 'mobile.required' => '请填写手机号码',
  623. 'email.required' => '请填写电子邮箱',
  624. 'card.required' => '请填写身份证号码',
  625. 'resume.required' => '请填写个人简历',
  626. 'concat_name.required' => '请填写联系人姓名',
  627. 'concat_mobile.required' => '请填写联系人手机号码'
  628. ];
  629. $create_data = $request->all();
  630. $validator = Validator::make($create_data,$rules,$messages);
  631. if ($validator->fails()) {
  632. $msg = $validator->errors()->all();
  633. return response()->json(['status' => 0,'msg' => $msg[0]]);
  634. }else{
  635. $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','adjust');
  636. //身份证判断出生日期和性别
  637. $year = substr($data['card'],6,4);
  638. $month = substr($data['card'],10,2);
  639. $day = substr($data['card'],12,2);
  640. if($year.'-'.$month.'-'.$day != $data['birthday']){
  641. $data['birthday'] = $year.'-'.$month.'-'.$day;
  642. }
  643. if(intval(substr($data['card'],16,1)) % 2 == 0){
  644. $data['sex'] = 0;
  645. }else{
  646. $data['sex'] = 1;
  647. }
  648. $post_info = RecruitPost::where('id',$data['post_id'])->where('recruit_id',$recruit_id)->first();
  649. if(!$post_info['status'] || $post_info['deleted_at'] != null){
  650. return response()->json(['status' => 0,'msg' => '该岗位已失效']);
  651. }
  652. //获取操作符,是暂存还是提交
  653. $operation = $request->input('operation');
  654. if($operation == 1){
  655. $data['audit'] = 0;//暂存
  656. }else{
  657. $data['audit'] = 1;//提交
  658. }
  659. if(!empty($post_info['limit']) && json_decode($post_info['limit'])){
  660. //岗位限制条件的判断
  661. $post_limit = json_decode($post_info['limit'],true);
  662. if(is_array($post_limit)){
  663. foreach($post_limit as $k => $v){
  664. if($k == 'birthday'){
  665. $value = str_replace('-','',$data[$k]);
  666. }else{
  667. $value = $data[$k];
  668. }
  669. switch ($v['op']){
  670. case '=':
  671. if($value != $v['value']){
  672. return response()->json(['status' => 0,'msg' => $v['msg']]);
  673. }
  674. break;
  675. case '>':
  676. if($value <= $v['value']){
  677. return response()->json(['status' => 0,'msg' => $v['msg']]);
  678. }
  679. break;
  680. case '>=':
  681. if($value < $v['value']){
  682. return response()->json(['status' => 0,'msg' => $v['msg']]);
  683. }
  684. break;
  685. case '<':
  686. if($value >= $v['value']){
  687. return response()->json(['status' => 0,'msg' => $v['msg']]);
  688. }
  689. break;
  690. case '<=':
  691. if($value > $v['value']){
  692. return response()->json(['status' => 0,'msg' => $v['msg']]);
  693. }
  694. break;
  695. case '!=':
  696. if($value == $v['value']){
  697. return response()->json(['status' => 0,'msg' => $v['msg']]);
  698. }
  699. break;
  700. case 'like':
  701. if(strpos($value,$v['value']) === false){
  702. return response()->json(['status' => 0,'msg' => $v['msg']]);
  703. }
  704. break;
  705. case 'in':
  706. if(strpos($v['value'],$value) === false){
  707. return response()->json(['status' => 0,'msg' => $v['msg']]);
  708. }
  709. break;
  710. }
  711. }
  712. }
  713. }
  714. //前置审核 判断完成,先将数据入报名信息基础表
  715. //解析家庭成员数据
  716. $familys = $request->input('family');
  717. $family = [];
  718. if(is_array($familys)){
  719. foreach ($familys as $value){
  720. $item = [
  721. 'relation' => $value['relation'],
  722. 'realname' => $value['realname'],
  723. 'birthday' => $value['birthday'],
  724. 'political_affiliation' => $value['political_affiliation'],
  725. 'work' => $value['work']
  726. ];
  727. array_push($family,$item);
  728. }
  729. }
  730. $data['family'] = json_encode($family);
  731. if($appoint_info){
  732. //如果已有报名记录,进入修改阶段的处理流程
  733. DB::beginTransaction();
  734. try{
  735. RecruitAppointInfo::where('uid',$uid)->where('recruit_id',$recruit_id)->update($data);
  736. //分模块解析数据
  737. $forms = explode(',', $recruit['forms']);
  738. //如果有加分模块
  739. if(in_array('expand_special',$forms)){
  740. $special = $request->input('special');
  741. if($special['point_apply']){
  742. //删除掉没有成功返回路径的图片
  743. if(is_array($special['material'])){
  744. foreach ($special['material'] as $k => $v){
  745. if(!array_key_exists('response',$v)){
  746. unset($special['material'][$k]);
  747. }
  748. }
  749. }
  750. $special['material'] = json_encode($special['material']);
  751. }else{
  752. $special['material'] = json_encode([]);
  753. }
  754. $hasRecord = RecruitAppointExpandSpecial::where('recruit_appoint_id',$appoint_info->id)->first();
  755. if($hasRecord){
  756. RecruitAppointExpandSpecial::where('recruit_appoint_id',$appoint_info->id)->update($special);
  757. }else{
  758. $special['recruit_appoint_id'] = $appoint_info->id;
  759. RecruitAppointExpandSpecial::create($special);
  760. }
  761. }
  762. //如果有详情模块
  763. if(in_array('detail',$forms) || in_array('internship',$forms)){
  764. $detail = $request->input('detail');
  765. $hasRecord = RecruitAppointDetail::where('recruit_appoint_id',$appoint_info->id)->first();
  766. if($hasRecord){
  767. RecruitAppointDetail::where('recruit_appoint_id',$appoint_info->id)->update($detail);
  768. }else{
  769. $detail['recruit_appoint_id'] = $appoint_info->id;
  770. RecruitAppointDetail::create($detail);
  771. }
  772. }
  773. //如果有身份证明模块
  774. if(in_array('identification',$forms) || in_array('internship',$forms)){
  775. $identification = $request->input('identification');
  776. if(is_array($identification)){
  777. //删除掉没有成功返回路径的图片
  778. foreach ($identification as $k => $v){
  779. if(!array_key_exists('response',$v)){
  780. unset($identification[$k]);
  781. }
  782. }
  783. }
  784. $appoint_info->identification = json_encode($identification);
  785. $appoint_info->save();
  786. }
  787. //如果有教育证明模块
  788. if(in_array('education_certification',$forms) || in_array('internship',$forms)){
  789. $education_certification = $request->input('education_certification');
  790. if(is_array($education_certification)){
  791. //删除掉没有成功返回路径的图片
  792. foreach ($education_certification as $k => $v){
  793. if(!array_key_exists('response',$v)){
  794. unset($education_certification[$k]);
  795. }
  796. }
  797. }
  798. $appoint_info->education_certification = json_encode($education_certification);
  799. $appoint_info->save();
  800. }
  801. //如果有其他证明模块
  802. if(in_array('other_certification',$forms) || in_array('internship',$forms)){
  803. $other_certification = $request->input('other_certification');
  804. if(is_array($other_certification)){
  805. //删除掉没有成功返回路径的图片
  806. foreach ($other_certification as $k => $v){
  807. if(!array_key_exists('response',$v)){
  808. unset($other_certification[$k]);
  809. }
  810. }
  811. }
  812. if($other_certification){
  813. $appoint_info->other_certification = json_encode($other_certification);
  814. $appoint_info->save();
  815. }
  816. }
  817. DB::commit();
  818. if($operation == 2){
  819. $log = [
  820. 'type' => 3,
  821. 'appoint_id'=> $appoint_info->id,
  822. 'uid' => $uid,
  823. 'log' => '用户提交报名'
  824. ];
  825. RecruitAppointLog::create($log);
  826. return ['status' => 1, 'msg' => '提交成功', 'data' => $appoint_info->id];
  827. }else{
  828. return ['status' => 1, 'msg' => '资料保存成功,请尽快完善并提交', 'data' => $appoint_info->id];
  829. }
  830. } catch (\Exception $e){
  831. DB::rollback();
  832. return ['status' => 0, 'msg' => $e->getMessage()];
  833. }
  834. }else{
  835. //没有报名记录,进入增加阶段的处理流程
  836. DB::beginTransaction();
  837. try{
  838. $data['uid'] = $uid;
  839. $data['recruit_id'] = $recruit_id;
  840. $result = RecruitAppointInfo::create($data);
  841. //分模块解析数据
  842. $forms = explode(',', $recruit['forms']);
  843. //如果有加分模块
  844. if(in_array('expand_special',$forms)){
  845. $special = $request->input('special');
  846. if($special['point_apply']){
  847. if(is_array($special['material'])){
  848. //删除掉没有成功返回路径的图片
  849. foreach ($special['material'] as $k => $v){
  850. if(!array_key_exists('response',$v)){
  851. unset($special['material'][$k]);
  852. }
  853. }
  854. }
  855. $special['material'] = json_encode($special['material']);
  856. }
  857. $special['recruit_appoint_id'] = $result->id;
  858. RecruitAppointExpandSpecial::create($special);
  859. }
  860. //如果有详情模块
  861. if(in_array('detail',$forms) || in_array('internship',$forms)){
  862. $detail = $request->input('detail');
  863. $detail['recruit_appoint_id'] = $result->id;
  864. RecruitAppointDetail::create($detail);
  865. }
  866. //如果有身份证明模块
  867. if(in_array('identification',$forms) || in_array('internship',$forms)){
  868. $identification = $request->input('identification');
  869. if(is_array($identification)){
  870. //删除掉没有成功返回路径的图片
  871. foreach ($identification as $k => $v){
  872. if(!array_key_exists('response',$v)){
  873. unset($identification[$k]);
  874. }
  875. }
  876. }
  877. $result->identification = json_encode($identification);
  878. $result->save();
  879. }
  880. //如果有教育证明模块
  881. if(in_array('education_certification',$forms) || in_array('internship',$forms)){
  882. $education_certification = $request->input('education_certification');
  883. if(is_array($education_certification)){
  884. //删除掉没有成功返回路径的图片
  885. foreach ($education_certification as $k => $v){
  886. if(!array_key_exists('response',$v)){
  887. unset($education_certification[$k]);
  888. }
  889. }
  890. }
  891. $result->education_certification = json_encode($education_certification);
  892. $result->save();
  893. }
  894. //如果有其他证明模块
  895. if(in_array('other_certification',$forms) || in_array('internship',$forms)){
  896. $other_certification = $request->input('other_certification');
  897. if($other_certification){
  898. if(is_array($other_certification)){
  899. //删除掉没有成功返回路径的图片
  900. foreach ($other_certification as $k => $v){
  901. if(!array_key_exists('response',$v)){
  902. unset($other_certification[$k]);
  903. }
  904. }
  905. }
  906. $result->other_certification = json_encode($other_certification);
  907. $result->save();
  908. }
  909. }
  910. DB::commit();
  911. if($operation == 2){
  912. $log = [
  913. 'type' => 3,
  914. 'appoint_id'=> $result->id,
  915. 'uid' => $uid,
  916. 'log' => '用户首次提交报名'
  917. ];
  918. RecruitAppointLog::create($log);
  919. return ['status' => 1, 'msg' => '提交成功', 'data' => $result->id];
  920. }else{
  921. return ['status' => 1, 'msg' => '资料保存成功,请尽快完善并提交', 'data' => $result->id];
  922. }
  923. } catch (\Exception $e){
  924. DB::rollback();
  925. return ['status' => 0, 'msg' => $e->getMessage()];
  926. }
  927. }
  928. }
  929. }
  930. /**
  931. * 获得当前登录的用户
  932. * @return \Illuminate\Contracts\Auth\Authenticatable|null
  933. */
  934. public function getUser()
  935. {
  936. if (auth('web-member')->check()) {
  937. $user = auth('web-member')->user();
  938. } else {
  939. $user = null;
  940. }
  941. return $user;
  942. }
  943. public function checkUserBasicInfo()
  944. {
  945. $user = $this->getUser();
  946. if (!empty($user)) {
  947. $uid = $user->id;
  948. } else {
  949. $arr = ['status' => 401, 'msg'=>'请登录!'];
  950. return $arr;
  951. }
  952. $info = RecruitAppointBasic::where('uid',$uid)->first();
  953. if (empty($info)){
  954. $arr = ['status'=>401,'msg'=>'请先完善招考基本信息','url'=> route('recruit.recruitInfo')];
  955. return $arr;
  956. }
  957. return ['status' => 200, 'msg' => ''];
  958. }
  959. public function person_recruit()
  960. {
  961. $user = auth('web-member')->user();
  962. $list = RecruitAppointInfo::where('uid',$user->id)
  963. ->join('recruit', 'recruit.id', '=', 'recruit_appoint_info.recruit_id', 'left')
  964. ->join('recruit_post', 'recruit_post.id', '=', 'recruit_appoint_info.post_id', 'left')
  965. ->select('recruit.name as recruit_name','recruit_appoint_info.*','recruit_post.code','recruit_post.name')
  966. ->get();
  967. return view('app.person.recruit')->with(['list' => $list,'total' => count($list)]);
  968. }
  969. public function recruit_info(Request $request)
  970. {
  971. $user = auth('web-member')->user();
  972. $info = RecruitAppointBasic::where('uid',$user->id)->first();
  973. if(!$info){
  974. $info = [
  975. 'realname' => '',
  976. 'sex' => '0',
  977. 'birthday' => '',
  978. 'avatar' => '',
  979. 'nation' => '',
  980. 'native_place' => '',
  981. 'political_affiliation' => '',
  982. 'titles' => '',
  983. 'work' => '',
  984. 'house_register' => '',
  985. 'join_time' => '',
  986. 'edu_type' => '',
  987. 'education' => '',
  988. 'school' => '',
  989. 'degree' => '',
  990. 'pro' => '',
  991. 'address' => '',
  992. 'card' => '',
  993. 'mobile' => '',
  994. 'email' => '',
  995. 'concat_name' => '',
  996. 'concat_mobile' => '',
  997. 'resume' => '',
  998. 'family' => [
  999. [
  1000. 'relation' => '',
  1001. 'realname' => '',
  1002. 'birthday' => '',
  1003. 'political_affiliation' => '',
  1004. 'work' => ''
  1005. ]
  1006. ],
  1007. 'is_push' => '1'
  1008. ];
  1009. }else{
  1010. $info->sex = (string)$info->sex;
  1011. $info->edu_type = (string)$info->edu_type;
  1012. $info->is_push = (string)$info->is_push;
  1013. $info->family = empty($info->family) ? [[
  1014. 'relation' => '',
  1015. 'realname' => '',
  1016. 'birthday' => '',
  1017. 'political_affiliation' => '',
  1018. 'work' => ''
  1019. ]] : json_decode($info->family);
  1020. }
  1021. $recruit_id = $request->input('recruit_id',0);
  1022. return view('app.person.recruit_info',[
  1023. 'info' => json_encode($info),
  1024. 'recruit_id'=> $recruit_id
  1025. ]);
  1026. }
  1027. public function saveRecruitInfo(RecruitValidatorRequest $request)
  1028. {
  1029. $user = auth('web-member')->user();
  1030. $basic = RecruitAppointBasic::where('uid',$user->id)->first();
  1031. $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');
  1032. if(count($data['family']) > 0){
  1033. $data['family'] = json_encode($data['family']);
  1034. }
  1035. if($basic){
  1036. //更新基础信息
  1037. $res = RecruitAppointBasic::where('uid',$user->id)->update($data);
  1038. if (!$res) {
  1039. return response()->json(['status'=>0,'msg'=>'保存失败,请联系客服']);
  1040. }else{
  1041. return response()->json(['status'=>1,'msg'=>'个人基础信息保存成功,快去报名吧!']);
  1042. }
  1043. }else{
  1044. //新增基础信息
  1045. $data['uid'] = $user->id;
  1046. $res = RecruitAppointBasic::create($data);
  1047. if (!$res) {
  1048. return response()->json(['status'=>0,'msg'=>'保存失败,请联系客服']);
  1049. }else{
  1050. return response()->json(['status'=>1,'msg'=>'个人基础信息保存成功,快去报名吧!']);
  1051. }
  1052. }
  1053. }
  1054. public function pen_ticket(Request $request)
  1055. {
  1056. $user = $this->getUser();
  1057. if (!empty($user)) {
  1058. $uid = $user->id;
  1059. } else {
  1060. return $this->showMessage('请登录!', route('home'), true, '上一页', '3');
  1061. }
  1062. $recruit_id = $request->input('recruit_id');
  1063. $appoint_info = RecruitAppointInfo::where('uid',$uid)->where('recruit_id',$recruit_id)->first();
  1064. if($appoint_info){
  1065. $pen_ticket = RecruitTicket::where('appoint_id',$appoint_info->id)->where('ex_type',1)->first();
  1066. if($pen_ticket){
  1067. $time = time();
  1068. if(strtotime($pen_ticket->ex_start) < $time && strtotime($pen_ticket->ex_end) > $time){
  1069. RecruitTicket::where('appoint_id',$appoint_info->id)->update(['ex_status' => 1]);
  1070. $recruit = Recruit::where('id',$recruit_id)->first();
  1071. $post_data = RecruitPost::where('recruit_id',$recruit_id)->where('status',1)->selectRaw('id, CONCAT(code," ",name) as post')->pluck('post', 'id');
  1072. $name = $recruit->name_en;
  1073. $date = date("Y-m-d",strtotime($recruit->created_at));
  1074. $filename = $date . '_' . $appoint_info->realname . '_' . $appoint_info->card . '_' . $post_data[$appoint_info->post_id];
  1075. $file = base_path() . "/storage/app/public/recruit/ticket/pdf/{$date}/{$name}/pen/" . $filename . '_create.pdf';
  1076. if(file_exists($file)){
  1077. header('Content-Description: File Transfer');
  1078. header('Content-Type: application/octet-stream');
  1079. header('Content-Disposition: attachment; filename='.basename($file));
  1080. header('Content-Transfer-Encoding: binary');
  1081. header('Expires: 0');
  1082. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  1083. header('Pragma: public');
  1084. header('Content-Length: ' . filesize($file));
  1085. ob_clean(); //重要的就是这个函数的调用, 清空但不关闭输出缓存, 否则下载的文件头两个字符会是0a
  1086. flush();
  1087. readfile($file);
  1088. }
  1089. }else{
  1090. return $this->showMessage('非打印时间!', route('home'), true, '上一页', '3');
  1091. }
  1092. }else{
  1093. return $this->showMessage('暂无准考证可以打印!', route('home'), true, '上一页', '3');
  1094. }
  1095. }else{
  1096. return $this->showMessage('暂无准考证可以打印!', route('home'), true, '上一页', '3');
  1097. }
  1098. }
  1099. public function check_ticket(Request $request)
  1100. {
  1101. $user = $this->getUser();
  1102. if (!empty($user)) {
  1103. $uid = $user->id;
  1104. } else {
  1105. return $this->showMessage('请登录!', route('home'), true, '上一页', '3');
  1106. }
  1107. $recruit_id = $request->input('recruit_id');
  1108. $appoint_info = RecruitAppointInfo::where('uid',$uid)->where('recruit_id',$recruit_id)->first();
  1109. if($appoint_info){
  1110. $check_ticket = RecruitTicket::where('appoint_id',$appoint_info->id)->where('ex_type',2)->first();
  1111. if($check_ticket){
  1112. $time = time();
  1113. if(strtotime($check_ticket->ex_start) < $time && strtotime($check_ticket->ex_end) > $time){
  1114. RecruitTicket::where('appoint_id',$appoint_info->id)->update(['ex_status' => 1]);
  1115. $recruit = Recruit::where('id',$recruit_id)->first();
  1116. $post_data = RecruitPost::where('recruit_id',$recruit_id)->where('status',1)->selectRaw('id, CONCAT(code," ",name) as post')->pluck('post', 'id');
  1117. $name = $recruit->name_en;
  1118. $date = date("Y-m-d",strtotime($recruit->created_at));
  1119. $filename = date("Y-m-18",time()) . '_' . $appoint_info->realname . '_' . $appoint_info->card . '_' . $post_data[$appoint_info->post_id];
  1120. $file = base_path() . "/storage/app/public/recruit/ticket/pdf/{$date}/{$name}/check/" . $filename . '.pdf';
  1121. if(file_exists($file)){
  1122. header('Content-Description: File Transfer');
  1123. header('Content-Type: application/octet-stream');
  1124. header('Content-Disposition: attachment; filename='.basename($file));
  1125. header('Content-Transfer-Encoding: binary');
  1126. header('Expires: 0');
  1127. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  1128. header('Pragma: public');
  1129. header('Content-Length: ' . filesize($file));
  1130. ob_clean(); //重要的就是这个函数的调用, 清空但不关闭输出缓存, 否则下载的文件头两个字符会是0a
  1131. flush();
  1132. readfile($file);
  1133. }
  1134. }else{
  1135. return $this->showMessage('非打印时间!', route('home'), true, '上一页', '3');
  1136. }
  1137. }else{
  1138. return $this->showMessage('暂无准考证可以打印!', route('home'), true, '上一页', '3');
  1139. }
  1140. }else{
  1141. return $this->showMessage('暂无准考证可以打印!', route('home'), true, '上一页', '3');
  1142. }
  1143. }
  1144. public function face_ticket(Request $request)
  1145. {
  1146. $user = $this->getUser();
  1147. if (!empty($user)) {
  1148. $uid = $user->id;
  1149. } else {
  1150. return $this->showMessage('请登录!', route('home'), true, '上一页', '3');
  1151. }
  1152. $recruit_id = $request->input('recruit_id');
  1153. $appoint_info = RecruitAppointInfo::where('uid',$uid)->where('recruit_id',$recruit_id)->first();
  1154. if($appoint_info){
  1155. $face_ticket = RecruitTicket::where('appoint_id',$appoint_info->id)->where('ex_type',3)->first();
  1156. if($face_ticket){
  1157. $time = time();
  1158. if(strtotime($face_ticket->ex_start) < $time && strtotime($face_ticket->ex_end) > $time){
  1159. RecruitTicket::where('id',$face_ticket->id)->update(['ex_status' => 1]);
  1160. $recruit = Recruit::where('id',$recruit_id)->first();
  1161. $post_data = RecruitPost::where('recruit_id',$recruit_id)->where('status',1)->selectRaw('id, CONCAT(code," ",name) as post')->pluck('post', 'id');
  1162. $name = $recruit->name_en;
  1163. $date = date("Y-m-d",strtotime($recruit->created_at));
  1164. $filename = $date . '_' . $appoint_info->realname . '_' . $appoint_info->card . '_' . $post_data[$appoint_info->post_id].'_create';
  1165. $file = base_path() . "/storage/app/public/recruit/ticket/pdf/{$date}/{$name}/face/" . $filename . '.pdf';
  1166. if(file_exists($file)){
  1167. header('Content-Description: File Transfer');
  1168. header('Content-Type: application/octet-stream');
  1169. header('Content-Disposition: attachment; filename='.basename($file));
  1170. header('Content-Transfer-Encoding: binary');
  1171. header('Expires: 0');
  1172. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  1173. header('Pragma: public');
  1174. header('Content-Length: ' . filesize($file));
  1175. ob_clean(); //重要的就是这个函数的调用, 清空但不关闭输出缓存, 否则下载的文件头两个字符会是0a
  1176. flush();
  1177. readfile($file);
  1178. }
  1179. }else{
  1180. return $this->showMessage('非打印时间!', route('home'), true, '上一页', '3');
  1181. }
  1182. }else{
  1183. return $this->showMessage('暂无准考证可以打印!', route('home'), true, '上一页', '3');
  1184. }
  1185. }else{
  1186. return $this->showMessage('暂无准考证可以打印!', route('home'), true, '上一页', '3');
  1187. }
  1188. }
  1189. }