JjhcController.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. namespace App\Http\Controllers\Web\Talent;
  3. use App\Http\Controllers\Web\WebBaseController;
  4. use App\Models\RecruitPost;
  5. use App\Services\Common\SmsService;
  6. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  7. use PhpOffice\PhpSpreadsheet\IOFactory;
  8. use PhpOffice\PhpSpreadsheet\Cell\DataType;
  9. use PhpOffice\PhpWord\IOFactory as WordIOFactory;
  10. use PhpOffice\PhpWord\Settings;
  11. use PhpOffice\PhpWord\TemplateProcessor;
  12. use Illuminate\Support\Facades\DB;
  13. use App\Exceptions\ResponseException;
  14. use Illuminate\Http\Request;
  15. class JjhcController extends WebBaseController
  16. {
  17. private $smsService;
  18. public function __construct(SmsService $smsService)
  19. {
  20. $this->smsService = $smsService;
  21. }
  22. public function yqfk()
  23. {
  24. return view("app.talent.jjhc.yqfk");
  25. }
  26. public function chaxun(Request $request)
  27. {
  28. $data = array('msg'=>'查无此用户!','status' => 0);
  29. return response()->json($data);
  30. $info = DB::connection('fangyi')->table('fillinfo')
  31. ->where(['lxdh'=>$request->tel])->first();
  32. if($info){
  33. $data = array('status'=>1,'msg'=>'查到已存在数据!','info'=>$info);
  34. }else{
  35. $data = array('msg'=>'查无此用户!','status' => 0);
  36. }
  37. return response()->json($data);
  38. }
  39. public function test(Request $request)
  40. {
  41. $keyword = $request->input('keyword');
  42. if($keyword != "j0vOW5mBREZxdo3P"){
  43. throw new ResponseException("who are you?", [], 404);
  44. }
  45. // for ($room = 11;$room <= 52; $room++){
  46. // $list = DB::table("recruit_ticket")->leftJoin("recruit_appoint_info","recruit_ticket.appoint_id",'=','recruit_appoint_info.id')->where("recruit_ticket.ex_start",'2022-05-17 08:00:00')->where('recruit_ticket.ex_room',$room)->orderBy('ex_seat','ASC')->get()->toArray();
  47. //
  48. // $objPHPExcel = IOFactory::load(base_path() . "/public/cunwu.xlsx");
  49. // $sheet = $objPHPExcel->getActiveSheet();
  50. // $row = 4;
  51. // $sheet->setCellValue('A1', "晋江市公开招聘第十二批村务(社区)专职工作者
  52. //笔试参考情况一览表(第".intval($room)."考场)");
  53. //
  54. // foreach ($list as $k => $v){
  55. // $sheet->setCellValueByColumnAndRow('1',$row, $v->ex_seat);
  56. // $sheet->setCellValueByColumnAndRow('2',$row, $v->realname);
  57. // $sheet->setCellValueExplicitByColumnAndRow('3',$row, $v->ex_number,DataType::TYPE_STRING);
  58. // $row++;
  59. // }
  60. //
  61. // $writer = IOFactory::createWriter($objPHPExcel, 'Xlsx');
  62. // $writer->save(base_path() . "/public/excel/cunwu{$room}.xlsx");
  63. // }
  64. // for ($room = 1;$room <= 52; $room++){
  65. // $word = new TemplateProcessor(base_path() . "/public/cunwu.docx");
  66. // $word->setValue('room', $room);
  67. // if($room<10){
  68. // $room = sprintf('%02s', $room);
  69. // }
  70. // $list = DB::table("recruit_ticket")->leftJoin("recruit_appoint_info","recruit_ticket.appoint_id",'=','recruit_appoint_info.id')->where("recruit_ticket.ex_start",'2022-05-17 08:00:00')->where('recruit_ticket.ex_room',$room)->orderBy('ex_seat','ASC')->get()->toArray();
  71. // $rows = count($list);//总行数
  72. // $word->cloneRow('id', $rows);//复制行
  73. // for ($i = 0; $i < $rows; $i++) {
  74. // $word->setValue("id#" . ($i + 1), $i + 1);//替换变量
  75. // $word->setValue("realname#" . ($i + 1), $list[$i]->realname);
  76. // $word->setValue("ex_number#" . ($i + 1), $list[$i]->ex_number);
  77. // $word->setValue("ex_seat#" . ($i + 1), $list[$i]->ex_seat);
  78. // }
  79. // $word->saveAs(base_path() ."/public/excel/cunwu{$room}.docx");//另存为
  80. // }
  81. $spreadsheet = new Spreadsheet();
  82. $sheet = $spreadsheet->getActiveSheet();
  83. $header = ['姓名','身份证','准考证','报考岗位'];
  84. foreach ($header as $key => $value) {
  85. $sheet->setCellValueByColumnAndRow($key+1, 1, $value);
  86. }
  87. $row = 2;
  88. $sheet->getStyle('S')->getNumberFormat()->setFormatCode('0');
  89. $list = DB::table("recruit_ticket")->leftJoin("recruit_appoint_info","recruit_ticket.appoint_id",'=','recruit_appoint_info.id')->where("recruit_appoint_info.recruit_id",'16')->orderBy('recruit_appoint_info.post_id','ASC')->orderBy('recruit_appoint_info.id','ASC')->get()->toArray();
  90. $post_data = RecruitPost::where('recruit_id',16)->where('status',1)->selectRaw('id, CONCAT(code," ",name) as post')->pluck('post', 'id');
  91. foreach ($list as $k => $v){
  92. $sheet->setCellValueByColumnAndRow('1',$row, $v->realname);
  93. $sheet->setCellValueExplicitByColumnAndRow('2',$row, $v->card,DataType::TYPE_STRING);
  94. $sheet->setCellValueExplicitByColumnAndRow('3',$row, $v->ex_number,DataType::TYPE_STRING);
  95. $sheet->setCellValueByColumnAndRow('4',$row, $post_data[$v->post_id]);
  96. $row++;
  97. }
  98. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  99. header('Content-Disposition: attachment;filename="'.time().'.xlsx"');
  100. header('Cache-Control: max-age=0');
  101. // If you're serving to IE 9, then the following may be needed
  102. header('Cache-Control: max-age=1');
  103. // If you're serving to IE over SSL, then the following may be needed
  104. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  105. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
  106. header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  107. header('Pragma: public'); // HTTP/1.0
  108. $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
  109. $writer->save('php://output');
  110. echo "success";
  111. // $list = DB::table('lt_apppointment')->distinct()->pluck('card')->toArray();
  112. // $all = DB::table('lt_apppointment')->pluck('card')->toArray();
  113. // $all = array_count_values($all);
  114. // $time = time();
  115. // $data = [
  116. // 'idCards' => $list,
  117. // 'sign' => strtoupper(md5("timestr={$time}&key=rsKVyec52fqEKpk4RRD2TU8fKvPxt6ombKg0qSq1velPQtBHVi")),
  118. // 'timeStr' => $time,
  119. // ];
  120. // $data_string = json_encode($data);
  121. // $ch = curl_init ();
  122. // curl_setopt( $ch, CURLOPT_URL, "http://rc.jucai.gov.cn/api/dataInterface/findTalentInfoByIdCards" );
  123. // curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  124. // 'Content-Type: application/json',
  125. // 'Content-Length: ' . strlen($data_string))
  126. // );
  127. // curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); //若果报错 name lookup timed out 报错时添加这一行代码
  128. // curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
  129. // curl_setopt( $ch, CURLOPT_TIMEOUT,60);
  130. // curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0);
  131. // curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0);
  132. // curl_setopt( $ch, CURLOPT_POST, 1);
  133. // curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
  134. // $result = curl_exec ( $ch );
  135. // curl_close ( $ch );
  136. // $ret = json_decode($result,true);
  137. // $res = [];
  138. // if(count($ret['obj']) > 0){
  139. // foreach ($ret['obj'] as $k => $v){
  140. // if(array_key_exists($v['street'],$res)){
  141. // $res[$v['street']]['number']++;
  142. // $res[$v['street']]['count'] += $all[$v['idCard']];
  143. // }else{
  144. // $res[$v['street']] = [
  145. // 'number' => 1,
  146. // 'count' => $all[$v['idCard']]
  147. // ];
  148. // }
  149. // }
  150. // }
  151. //
  152. // $spreadsheet = new Spreadsheet();
  153. // $sheet = $spreadsheet->getActiveSheet();
  154. // $header = ['镇街','使用人数','使用次数'];
  155. // foreach ($header as $key => $value) {
  156. // $sheet->setCellValueByColumnAndRow($key+1, 1, $value);
  157. // }
  158. // $row = 2;
  159. // foreach ($res as $k => $v){
  160. // $sheet->setCellValueByColumnAndRow(1, $row, $k);
  161. // $sheet->setCellValueByColumnAndRow(2, $row, $v['number']);
  162. // $sheet->setCellValueByColumnAndRow(3, $row, $v['count']);
  163. // $row++;
  164. // }
  165. // $file_name = date("Y-m-d",time()) . '码上服务数据';
  166. // header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  167. // header('Content-Disposition: attachment;filename="'.$file_name.'.xlsx"');
  168. // header('Cache-Control: max-age=0');
  169. // // If you're serving to IE 9, then the following may be needed
  170. // header('Cache-Control: max-age=1');
  171. // // If you're serving to IE over SSL, then the following may be needed
  172. // header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  173. // header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
  174. // header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  175. // header('Pragma: public'); // HTTP/1.0
  176. // $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
  177. // $writer->save('php://output');
  178. //
  179. // //dd($res);
  180. }
  181. }