JjhcController.php 10 KB

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