JjhcController.php 7.1 KB

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