post('id_number'); $id = $request->post('id'); if (!$id_number) return \Yz::echoError('请输入身份证'); $queue = []; $fzc = new fzc(); $res = $fzc->fz('change', [ 'id_number' => $id_number, 'id' => $id, ]); if ($res['code'] == 200) { $queue_info = $res['data']['queue']; if (!!$queue_info) { $queue = [[ 'id' => $queue_info['id'], 'name' => $queue_info['name'], 'clinic' => $queue_info['clinic_name'], 'item' => $queue_info['item_name'], ]]; } } return \Yz::Return(true, '操作完成', [ 'queue' => $queue ]); } public function check_in(Request $request) { $id_number = $request->get('id_number'); if (!$id_number) { $id_number = ''; } $queue = []; if (!!$id_number) { $fzc = new fzc(); $res = $fzc->fz('search', [ 'id_number' => $id_number ]); if ($res['code'] == 200) { $queue_info = $res['data']['queue']; if (!!$queue_info) { $queue = [[ 'id' => $queue_info['id'], 'name' => $queue_info['name'], 'clinic' => $queue_info['clinic_name'], 'item' => $queue_info['item_name'], ]]; } } } return view('fenzhen', [ 'id_number' => $id_number, 'queue' => $queue ]); } public function export(){ $fzc = new fzc(); $date=request('date'); $res = $fzc->fz('export', [ 'date' => $date ]); $table_list=$res['data']['table1']; $clinic_list=$res['data']['table2']; $table_list3=$res['data']['table3']; // dd(json_encode($res['data'],JSON_UNESCAPED_UNICODE)); $template_path = Storage::path('public/excel/check_time.xlsx'); $spreadsheet = IOFactory::load($template_path); $worksheet = $spreadsheet->getActiveSheet(); $styleArray = [ 'borders' => [ 'allBorders' => [ 'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN, 'color' => ['argb' => 'FF000000'], ], ], ]; $row = 3; $col = [ 'A' => 'date', 'B' => 'name', 'C' => 'number', 'D' => 'phone', 'E' => 'group_name', 'F' => 'clinic', 'G' => 'doctor', 'H' => 'queue', 'I' => 'calling', 'J' => 'done', 'K' => 'clinic_check_time', 'L' => 'true_check_time', 'M' => 'timeout_check_time', 'N' => 'clinic_wait_time', 'O' => 'true_wait_time', 'P' => 'timeout_wait_time', 'Q' => 'clinic_all_time', 'R' => 'true_all_time', 'S' => 'timeout_all_time', ]; foreach ($table_list as $table_item) { foreach ($col as $index => $key) { $worksheet->setCellValueExplicit($index . $row, $table_item[$key], \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); } $row++; } $worksheet->getStyle('A3:S' . ($row - 1))->applyFromArray($styleArray); $row = 3; $col = [ 'U' => 'group_name', 'V' => 'clinic', 'W' => 'doctor', 'X' => 'check', 'Y' => 'check_out', 'Z' => 'wait', 'AA' => 'wait_out', ]; foreach ($clinic_list as $clinic_item) { foreach ($col as $index => $key) { $worksheet->setCellValueExplicit($index . $row, $clinic_item[$key], \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); } $row++; } $worksheet->getStyle('U3:AA' . ($row - 1))->applyFromArray($styleArray); $row = 3; $col = [ 'AC' => 'date', 'AD' => 'name', 'AE' => 'number', 'AF' => 'phone', 'AG' => 'combo', 'AH' => 'clinic_time', 'AI' => 'used_time', 'AJ' => 'timeout', ]; //汇总信息 $usercount=count($table_list3); $biaozhun_timecount=0; $shiji_timecount=0; $chaoshi_timecount=0; $weichaoshi_count=0; $tj_numbers=[]; foreach ($table_list3 as $table_list3_i) { $tj_numbers[]=$table_list3_i['uuid']; $biaozhun_timecount+=$table_list3_i['clinic_time']; $shiji_timecount+=$table_list3_i['used_time']; $chaoshi_timecount+=$table_list3_i['timeout']; if($table_list3_i['timeout']<=0){ $weichaoshi_count++; } $peis = new PEISApiController(); $data = [ '电话号码' => "", '证件号码' => "", '体检号' => $table_list3_i['uuid'], '包含内部信息' => true ]; $reports = $peis::Post('体检报告查询', 1, $data); if(isset($reports['data'][0]['套餐名称'])){ $table_list3_i['combo']=$reports['data'][0]['套餐名称']; }else{ $table_list3_i['combo']=''; } foreach ($col as $index => $key) { $worksheet->setCellValueExplicit($index . $row, $table_list3_i[$key], \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); } $row++; } $zhushilv=0; if($usercount>0){ $zhushilv=$weichaoshi_count/$usercount; } $worksheet->setCellValueExplicit('AC' . $row, '汇总', \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AD' . $row, '客户总数', \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AE' . $row, $usercount, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AG' . $row, '总用时:', \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AH' . $row, $biaozhun_timecount, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AI' . $row, $shiji_timecount, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AJ' . $row, $chaoshi_timecount, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AD' . ($row+1), '未超时总数', \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AE' . ($row+1), $weichaoshi_count, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AD' . ($row+2), "体检准时率", \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AE' . ($row+2),$zhushilv , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->getStyle('AC3:AJ' . ($row +2))->applyFromArray($styleArray); //准时到检率 $tj_numbers=implode(",", $tj_numbers); $peis = new PEISApiController(); $wait=$peis::Get($peis::Api('报告时间计算',$tj_numbers),'460107000001',"报告时间计算"); $jianhou_sign_count=0; $zhunshi_count=0; //dd($wait); if(isset($wait['Data'])){ $jianhou_sign_count=count($wait['Data']); } foreach ($table_list3 as $key=> $fz_value) { foreach ($wait['Data'] as $index => $sx_value) { if($fz_value['uuid']==$sx_value['体检号']){ if($date.' '.$fz_value['end_time']>$sx_value['检后签到时间']){ $zhunshi_count++; } } } } $daojianlv=0; if($jianhou_sign_count>0){ $daojianlv=$zhunshi_count/$jianhou_sign_count; } $worksheet->setCellValueExplicit('AL' . 3,$date , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AM' . 3,$zhunshi_count , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AN' . 3,$jianhou_sign_count , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AO' . 3,round($daojianlv, 2) , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->getStyle('AL3:AO' . 3)->applyFromArray($styleArray); //预约率 $yyl_yuyue_count=0;//预约人数 $yyl_tj_count=0;//体检总人数 $yuyuelv=0; $yuyueList=DB::table('orders')->where(['appointment_date'=>$date])->whereIn('status',[2,4])->whereNotNull(['appointment_number'])->get(); $yyl_yuyue_count=count($yuyueList); $yyl_tj_count=$usercount; if($yyl_tj_count>0){ $yuyuelv=$yyl_yuyue_count/$yyl_tj_count; } $worksheet->setCellValueExplicit('AL' . 7,$date , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AM' . 7,$yyl_yuyue_count , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AN' . 7,$yyl_tj_count , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AO' . 7,round($yuyuelv, 2) , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->getStyle('AL7:AO' . 7)->applyFromArray($styleArray); //预约准时率 $yyzsl_ren_count=0;//预约准时到达人数 $yyzsl_zong_count=0;//预约总人数 $yyzsl_zong_count=$yyl_yuyue_count; foreach ($yuyueList as $key=> $yy_value) { if($yy_value->appointment_date.' '.$yy_value->appointment_time > $yy_value->check_time){ $yyzsl_ren_count++; } } $zhunshilv=0; if($yyzsl_zong_count>0){ $zhunshilv=$yyzsl_ren_count/$yyzsl_zong_count; } $worksheet->setCellValueExplicit('AL' . 11,$date , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AM' . 11,$yyzsl_ren_count , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AN' . 11,$yyzsl_zong_count , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AO' . 11,round($zhunshilv, 2) , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->getStyle('AL11:AO' . 11)->applyFromArray($styleArray); //新建Sheet2 // $worksheet2 = new \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet($spreadsheet, 'Sheet2'); // $spreadsheet->addSheet($worksheet2); // $worksheet2->setCellValue('A1', 'Foo'); // $worksheet2->setCellValue('B1', 'Bar'); $file_name = Str::orderedUuid(); $dir_path = "public/excel/" . date('Ym') . '/' . $file_name; Storage::makeDirectory($dir_path); $name_date = date('n.j', strtotime($date . ' 00:00:00')); $excel_path = $dir_path . "/体检报表-时间监控$name_date.xlsx"; $writer = new Xlsx($spreadsheet); $writer->save(Storage::path($excel_path)); $url = Storage::url($excel_path); return \Yz::Return(true,"获取成功",['url' => env('APP_URL').$url]); } function generateDateArray($startDate, $endDate) { if ($startDate === $endDate) { return [$startDate]; } $dates = []; $start = new DateTime($startDate); $end = new DateTime($endDate); // 设置结束日期为最后一日的末尾时间(23:59:59) $end->setTime(23, 59, 59); // 创建一个 DatePeriod 对象 $interval = new DateInterval('P1D'); // 每日间隔 $period = new DatePeriod($start, $interval, $end); foreach ($period as $date) { $dates[] = $date->format("Y-m-d"); } return $dates; } public function export2(){ ini_set('memory_limit', '256M'); $dates=request('dates'); if(!$dates){ return \Yz::echoError1('请选择日期'); } $dates=$this->generateDateArray($dates[0],$dates[1]); if(count($dates)>30){ return \Yz::echoError1('最多只能选择30天'); } $table_list=[]; $clinic_list=[]; $table_list3=[]; $client = new Client(); $url = env('FENZHEN_URL'); $header=[ 'Authorization' => 'Bearer BD30333C-CBD4-4BA3-A27C-76727FF4D8B1', 'Content-Type' => 'application/json; charset=utf-8', ]; $promises=[]; foreach ($dates as $date) { $promises[]=$client->postAsync($url.'/api/Open/TiJian/export',['headers' => $header, 'json' => ['date'=>$date]]); } // 等待所有请求完成 $results = Promise\Utils::settle($promises)->wait(); foreach ($results as $key => $result) { if ($result['state'] === 'fulfilled') { $response = $result['value']; $res=json_decode($response->getBody(),true); // echo "Response from $key: " . $response->getBody() . "\n"; $table_list = array_merge($table_list, $res['data']['table1'] ?? []); $clinic_list = array_merge($clinic_list, $res['data']['table2'] ?? []); $table_list3 = array_merge($table_list3, $res['data']['table3'] ?? []); } } // foreach ($dates as $date) { // $res = $fzc->fz('export', [ // 'date' => $date // ]); // // // 使用 array_merge 逐个追加每日期的数据到总列表中 // $table_list = array_merge($table_list, $res['data']['table1'] ?? []); // $clinic_list = array_merge($clinic_list, $res['data']['table2'] ?? []); // $table_list3 = array_merge($table_list3, $res['data']['table3'] ?? []); // } $template_path = Storage::path('public/excel/check_time.xlsx'); $spreadsheet = IOFactory::load($template_path); $worksheet = $spreadsheet->getActiveSheet(); $styleArray = [ 'borders' => [ 'allBorders' => [ 'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN, 'color' => ['argb' => 'FF000000'], ], ], ]; $row = 3; $col = [ 'A' => 'date', 'B' => 'name', 'C' => 'number', 'D' => 'phone', 'E' => 'group_name', 'F' => 'clinic', 'G' => 'doctor', 'H' => 'queue', 'I' => 'calling', 'J' => 'done', 'K' => 'clinic_check_time', 'L' => 'true_check_time', 'M' => 'timeout_check_time', 'N' => 'clinic_wait_time', 'O' => 'true_wait_time', 'P' => 'timeout_wait_time', 'Q' => 'clinic_all_time', 'R' => 'true_all_time', 'S' => 'timeout_all_time', ]; foreach ($table_list as $table_item) { foreach ($col as $index => $key) { $worksheet->setCellValueExplicit($index . $row, $table_item[$key], \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); } $row++; } $worksheet->getStyle('A3:S' . ($row - 1))->applyFromArray($styleArray); $row = 3; $col = [ 'U' => 'group_name', 'V' => 'clinic', 'W' => 'doctor', 'X' => 'check', 'Y' => 'check_out', 'Z' => 'wait', 'AA' => 'wait_out', ]; foreach ($clinic_list as $clinic_item) { foreach ($col as $index => $key) { $worksheet->setCellValueExplicit($index . $row, $clinic_item[$key], \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); } $row++; } $worksheet->getStyle('U3:AA' . ($row - 1))->applyFromArray($styleArray); $row = 3; $col = [ 'AC' => 'date', 'AD' => 'name', 'AE' => 'number', 'AF' => 'phone', 'AG' => 'combo', 'AH' => 'clinic_time', 'AI' => 'used_time', 'AJ' => 'timeout', ]; //汇总信息 $usercount=count($table_list3); $biaozhun_timecount=0; $shiji_timecount=0; $chaoshi_timecount=0; $weichaoshi_count=0; $tj_numbers=[]; $peis = new PEISApiController(); foreach ($table_list3 as $table_list3_i) { $tj_numbers[]=$table_list3_i['uuid']; $biaozhun_timecount+=$table_list3_i['clinic_time']; $shiji_timecount+=$table_list3_i['used_time']; $chaoshi_timecount+=$table_list3_i['timeout']; if($table_list3_i['timeout']<=0){ $weichaoshi_count++; } $data = [ '电话号码' => "", '证件号码' => "", '体检号' => $table_list3_i['uuid'], '包含内部信息' => true ]; $reports = $peis::Post('体检报告查询', 1, $data); if(isset($reports['data'][0]['套餐名称'])){ $table_list3_i['combo']=$reports['data'][0]['套餐名称']; }else{ $table_list3_i['combo']=''; } foreach ($col as $index => $key) { $worksheet->setCellValueExplicit($index . $row, $table_list3_i[$key], \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); } $row++; } $zhushilv=0; if($usercount>0){ $zhushilv=$weichaoshi_count/$usercount; } $worksheet->setCellValueExplicit('AC' . $row, '汇总', \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AD' . $row, '客户总数', \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AE' . $row, $usercount, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AG' . $row, '总用时:', \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AH' . $row, $biaozhun_timecount, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AI' . $row, $shiji_timecount, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AJ' . $row, $chaoshi_timecount, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AD' . ($row+1), '未超时总数', \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AE' . ($row+1), $weichaoshi_count, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AD' . ($row+2), "体检准时率", \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AE' . ($row+2),$zhushilv , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->getStyle('AC3:AJ' . ($row +2))->applyFromArray($styleArray); //准时到检率 $jianhou_sign_count=0; $zhunshi_count=0; $tj_numbers_group= array_chunk($tj_numbers, 100); $waitGroup=[]; foreach ($tj_numbers_group as $index => $tj_number) { $tj_number=implode(",", $tj_number); $wait=$peis::Get($peis::Api('报告时间计算',$tj_number),'460107000001',"报告时间计算"); if(isset($wait['Data'])){ $jianhou_sign_count=$jianhou_sign_count+count($wait['Data']); $waitGroup=array_merge($waitGroup,$wait['Data']); } } //dd($wait); foreach ($table_list3 as $key=> $fz_value) { foreach ($waitGroup as $index => $sx_value) { if($fz_value['uuid']==$sx_value['体检号']){ if($fz_value['date'].' '.$fz_value['end_time']>$sx_value['检后签到时间']){ $zhunshi_count++; } } } } $daojianlv=0; if($jianhou_sign_count>0){ $daojianlv=$zhunshi_count/$jianhou_sign_count; } $datesRange=$dates[0].'~'.$dates[count($dates) - 1]; $worksheet->setCellValueExplicit('AL' . 3,$datesRange, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AM' . 3,$zhunshi_count , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AN' . 3,$jianhou_sign_count , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AO' . 3,round($daojianlv, 2) , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->getStyle('AL3:AO' . 3)->applyFromArray($styleArray); //预约率 $yyl_yuyue_count=0;//预约人数 $yyl_tj_count=0;//体检总人数 $yuyuelv=0; $yuyueList=DB::table('orders')->whereIn('appointment_date',$dates)->whereIn('status',[2,4])->whereNotNull(['appointment_number'])->get(); $yyl_yuyue_count=count($yuyueList); $yyl_tj_count=$usercount; if($yyl_tj_count>0){ $yuyuelv=$yyl_yuyue_count/$yyl_tj_count; } $worksheet->setCellValueExplicit('AL' . 7,$datesRange , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AM' . 7,$yyl_yuyue_count , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AN' . 7,$yyl_tj_count , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AO' . 7,round($yuyuelv, 2) , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->getStyle('AL7:AO' . 7)->applyFromArray($styleArray); //预约准时率 $yyzsl_ren_count=0;//预约准时到达人数 $yyzsl_zong_count=0;//预约总人数 $yyzsl_zong_count=$yyl_yuyue_count; foreach ($yuyueList as $key=> $yy_value) { if($yy_value->appointment_date.' '.$yy_value->appointment_time > $yy_value->check_time){ $yyzsl_ren_count++; } } $zhunshilv=0; if($yyzsl_zong_count>0){ $zhunshilv=$yyzsl_ren_count/$yyzsl_zong_count; } $worksheet->setCellValueExplicit('AL' . 11,$datesRange , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AM' . 11,$yyzsl_ren_count , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AN' . 11,$yyzsl_zong_count , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->setCellValueExplicit('AO' . 11,round($zhunshilv, 2) , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); $worksheet->getStyle('AL11:AO' . 11)->applyFromArray($styleArray); //新建Sheet2 // $worksheet2 = new \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet($spreadsheet, 'Sheet2'); // $spreadsheet->addSheet($worksheet2); // $worksheet2->setCellValue('A1', 'Foo'); // $worksheet2->setCellValue('B1', 'Bar'); $file_name = Str::orderedUuid(); $dir_path = "public/excel/" . date('Ym') . '/' . $file_name; Storage::makeDirectory($dir_path); $name_date = date('n.j', strtotime($date . ' 00:00:00')); $excel_path = $dir_path . "/体检报表-时间监控$name_date.xlsx"; $writer = new Xlsx($spreadsheet); $writer->save(Storage::path($excel_path)); $url = Storage::url($excel_path); return \Yz::Return(true,"获取成功",['url' => env('APP_URL').$url]); } }