"ddXPpBrM3C93PHFdWDXbMX2vQ2AJQFFy"){ return \Yz::echoError1('无权访问'); } if(!$dates){ return \Yz::echoError1('请选择日期'); } $dates=$this->generateDateArray($dates[0],$dates[1]); if(count($dates)>31){ return \Yz::echoError1('最多只能选择31天'); } $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'] ?? []); } } $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', ]; $INFO_table1=[]; foreach ($table_list as $table_item) { $row_info=[]; foreach ($col as $index => $key) { $row_info[]=[$key=>$table_item[$key]]; } $INFO_table1[]=$row_info; } $col = [ 'U' => 'group_name', 'V' => 'clinic', 'W' => 'doctor', 'X' => 'check', 'Y' => 'check_out', 'Z' => 'wait', 'AA' => 'wait_out', ]; $INFO_table2=[]; foreach ($clinic_list as $clinic_item) { $row_info=[]; foreach ($col as $index => $key) { $row_info[]=[$key=>$clinic_item[$key]]; } $INFO_table2[]=$row_info; } $col = [ 'AC' => 'date', 'AD' => 'name', 'AE' => 'number', 'AF' => 'phone', 'AG' => 'combo', 'AH' => 'clinic_time', 'AI' => 'used_time', 'AJ' => 'timeout', ]; $INFO_table3=[]; //汇总信息 $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) { $row_info=[]; $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) { $row_info[]=[$key=>$table_list3_i[$key]]; } $INFO_table3[]=$row_info; } $zhushilv=0; if($usercount>0){ $zhushilv=$weichaoshi_count/$usercount; } $INFO_table3['客户总数']=$usercount; $INFO_table3['总用时']=[$biaozhun_timecount,$shiji_timecount,$chaoshi_timecount]; $INFO_table3['未超时总数']=$weichaoshi_count; $INFO_table3['体检准时率']=$zhushilv; //准时到检率 $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]; $INFO_table4=[ "日期"=>$datesRange, "按时完成人数"=>$zhunshi_count, "检后签到人数"=>$jianhou_sign_count, "准时到检率"=>$daojianlv, ]; //预约率 $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; } $INFO_table5=[ "日期"=>$datesRange, "预约人数"=>$yyl_yuyue_count, "体检总数"=>$yyl_tj_count, "预约率"=>round($yuyuelv, 2), ]; //预约准时率 $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; } $INFO_table6=[ "日期"=>$datesRange, "预约准时到达人数"=>$yyzsl_ren_count, "预约总人数"=>$yyzsl_zong_count, "预约准时率"=>round($zhunshilv, 2), ]; return \Yz::Return(true,"获取成功",[ '明细表'=>$INFO_table1, '汇总表1'=>$INFO_table2, '汇总表2'=>$INFO_table3, '准时到检率'=>$INFO_table4, '预约率'=>$INFO_table5, '预约准时率'=>$INFO_table6, ]); } 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; } }