JjhcController.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 = 1;$room <= 78; $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-08-05 08:00:00')->where('recruit_ticket.ex_room',$room)->orderBy('ex_seat','ASC')->get()->toArray();
  47. $objPHPExcel = IOFactory::load(base_path() . "/public/cunwu.xlsx");
  48. $sheet = $objPHPExcel->getActiveSheet();
  49. $row = 4;
  50. $sheet->setCellValue('A1', "晋江市公开招聘第十三批村务(社区)专职工作者笔试参考情况一览表(第".intval($room)."考场)");
  51. foreach ($list as $k => $v){
  52. $sheet->setCellValueByColumnAndRow('1',$row, $v->ex_seat);
  53. $sheet->setCellValueByColumnAndRow('2',$row, $v->realname);
  54. $sheet->setCellValueExplicitByColumnAndRow('3',$row, $v->ex_number,DataType::TYPE_STRING);
  55. $row++;
  56. }
  57. $writer = IOFactory::createWriter($objPHPExcel, 'Xlsx');
  58. $writer->save(base_path() . "/public/excel/cunwu{$room}.xlsx");
  59. }
  60. // for ($room = 1;$room <= 78; $room++){
  61. // $word = new TemplateProcessor(base_path() . "/public/cunwu.docx");
  62. // $word->setValue('room', $room);
  63. // if($room<10){
  64. // $room = sprintf('%02s', $room);
  65. // }
  66. // $list = DB::table("recruit_ticket")->leftJoin("recruit_appoint_info","recruit_ticket.appoint_id",'=','recruit_appoint_info.id')->where("recruit_ticket.ex_start",'2022-08-05 08:00:00')->where('recruit_ticket.ex_room',$room)->orderBy('ex_seat','ASC')->get()->toArray();
  67. // $rows = count($list);//总行数
  68. // $word->cloneRow('id', $rows);//复制行
  69. // for ($i = 0; $i < $rows; $i++) {
  70. // $word->setValue("id#" . ($i + 1), $i + 1);//替换变量
  71. // $word->setValue("realname#" . ($i + 1), $list[$i]->realname);
  72. // $word->setValue("ex_number#" . ($i + 1), $list[$i]->ex_number);
  73. // $word->setValue("ex_seat#" . ($i + 1), $list[$i]->ex_seat);
  74. // }
  75. // $word->saveAs(base_path() ."/public/excel/cunwu{$room}.docx");//另存为
  76. // }
  77. // $spreadsheet = new Spreadsheet();
  78. // $sheet = $spreadsheet->getActiveSheet();
  79. // $header = ['姓名','身份证','准考证','报考岗位'];
  80. // foreach ($header as $key => $value) {
  81. // $sheet->setCellValueByColumnAndRow($key+1, 1, $value);
  82. // }
  83. // $row = 2;
  84. // $sheet->getStyle('S')->getNumberFormat()->setFormatCode('0');
  85. // $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();
  86. // $post_data = RecruitPost::where('recruit_id',16)->where('status',1)->selectRaw('id, CONCAT(code," ",name) as post')->pluck('post', 'id');
  87. // foreach ($list as $k => $v){
  88. // $sheet->setCellValueByColumnAndRow('1',$row, $v->realname);
  89. // $sheet->setCellValueExplicitByColumnAndRow('2',$row, $v->card,DataType::TYPE_STRING);
  90. // $sheet->setCellValueExplicitByColumnAndRow('3',$row, $v->ex_number,DataType::TYPE_STRING);
  91. // $sheet->setCellValueByColumnAndRow('4',$row, $post_data[$v->post_id]);
  92. // $row++;
  93. // }
  94. // header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  95. // header('Content-Disposition: attachment;filename="'.time().'.xlsx"');
  96. // header('Cache-Control: max-age=0');
  97. // // If you're serving to IE 9, then the following may be needed
  98. // header('Cache-Control: max-age=1');
  99. // // If you're serving to IE over SSL, then the following may be needed
  100. // header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  101. // header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
  102. // header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  103. // header('Pragma: public'); // HTTP/1.0
  104. // $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
  105. // $writer->save('php://output');
  106. echo "success";
  107. // $list = DB::table('lt_apppointment')->distinct()->pluck('card')->toArray();
  108. // $all = DB::table('lt_apppointment')->pluck('card')->toArray();
  109. // $all = array_count_values($all);
  110. // $time = time();
  111. // $data = [
  112. // 'idCards' => $list,
  113. // 'sign' => strtoupper(md5("timestr={$time}&key=rsKVyec52fqEKpk4RRD2TU8fKvPxt6ombKg0qSq1velPQtBHVi")),
  114. // 'timeStr' => $time,
  115. // ];
  116. // $data_string = json_encode($data);
  117. // $ch = curl_init ();
  118. // curl_setopt( $ch, CURLOPT_URL, "http://rc.jucai.gov.cn/api/dataInterface/findTalentInfoByIdCards" );
  119. // curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  120. // 'Content-Type: application/json',
  121. // 'Content-Length: ' . strlen($data_string))
  122. // );
  123. // curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); //若果报错 name lookup timed out 报错时添加这一行代码
  124. // curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
  125. // curl_setopt( $ch, CURLOPT_TIMEOUT,60);
  126. // curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0);
  127. // curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0);
  128. // curl_setopt( $ch, CURLOPT_POST, 1);
  129. // curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
  130. // $result = curl_exec ( $ch );
  131. // curl_close ( $ch );
  132. // $ret = json_decode($result,true);
  133. // $res = [];
  134. // if(count($ret['obj']) > 0){
  135. // foreach ($ret['obj'] as $k => $v){
  136. // if(array_key_exists($v['street'],$res)){
  137. // $res[$v['street']]['number']++;
  138. // $res[$v['street']]['count'] += $all[$v['idCard']];
  139. // }else{
  140. // $res[$v['street']] = [
  141. // 'number' => 1,
  142. // 'count' => $all[$v['idCard']]
  143. // ];
  144. // }
  145. // }
  146. // }
  147. //
  148. // $spreadsheet = new Spreadsheet();
  149. // $sheet = $spreadsheet->getActiveSheet();
  150. // $header = ['镇街','使用人数','使用次数'];
  151. // foreach ($header as $key => $value) {
  152. // $sheet->setCellValueByColumnAndRow($key+1, 1, $value);
  153. // }
  154. // $row = 2;
  155. // foreach ($res as $k => $v){
  156. // $sheet->setCellValueByColumnAndRow(1, $row, $k);
  157. // $sheet->setCellValueByColumnAndRow(2, $row, $v['number']);
  158. // $sheet->setCellValueByColumnAndRow(3, $row, $v['count']);
  159. // $row++;
  160. // }
  161. // $file_name = date("Y-m-d",time()) . '码上服务数据';
  162. // header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  163. // header('Content-Disposition: attachment;filename="'.$file_name.'.xlsx"');
  164. // header('Cache-Control: max-age=0');
  165. // // If you're serving to IE 9, then the following may be needed
  166. // header('Cache-Control: max-age=1');
  167. // // If you're serving to IE over SSL, then the following may be needed
  168. // header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  169. // header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
  170. // header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  171. // header('Pragma: public'); // HTTP/1.0
  172. // $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
  173. // $writer->save('php://output');
  174. //
  175. // //dd($res);
  176. }
  177. }