diff --git a/Laravel/app/Http/Controllers/H5/FenzhenController.php b/Laravel/app/Http/Controllers/H5/FenzhenController.php index fc2052b..909899d 100644 --- a/Laravel/app/Http/Controllers/H5/FenzhenController.php +++ b/Laravel/app/Http/Controllers/H5/FenzhenController.php @@ -4,6 +4,11 @@ namespace App\Http\Controllers\H5; use App\Http\Controllers\API\PEISApiController; use App\Http\Controllers\Controller; +use DateInterval; +use DatePeriod; +use DateTime; +use GuzzleHttp\Client; +use GuzzleHttp\Promise; use Illuminate\Http\Request; use App\Http\Controllers\API\H5\FenzhenController as fzc; use Illuminate\Support\Facades\DB; @@ -269,10 +274,297 @@ class FenzhenController extends Controller $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'); +// $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; diff --git a/Laravel/routes/web.php b/Laravel/routes/web.php index c368d7a..27d482b 100644 --- a/Laravel/routes/web.php +++ b/Laravel/routes/web.php @@ -109,4 +109,5 @@ Route::post('/Day1WXSend', 'App\Http\Controllers\API\H5\OrderController@Day1WXSe Route::post('/AutoRefund', 'App\Http\Controllers\API\H5\PayController@AutoRefund')->middleware('log');//对外退款接口 Route::any('api/FenzhenInfoExport', 'App\Http\Controllers\H5\FenzhenController@export')->middleware('log');//导出报表 +Route::any('api/FenzhenInfoExport2', 'App\Http\Controllers\H5\FenzhenController@export2')->middleware('log');//导出报表 diff --git a/admin/src/api/api.js b/admin/src/api/api.js index fda94c0..8fd46e8 100644 --- a/admin/src/api/api.js +++ b/admin/src/api/api.js @@ -433,6 +433,10 @@ export const PlanListGetList = (data = {}) => { export const FenzhenInfoExport = (data = {}) => { return axios({ url: import.meta.env.VITE_APP_API + `FenzhenInfoExport`, data: data }) } +//导出分诊范围数据 +export const FenzhenInfoExport2 = (data = {}) => { + return axios({ url: import.meta.env.VITE_APP_API + `FenzhenInfoExport2`, data: data }) +} //导出问卷 export const QuestionExport = (data = {}) => { return axios({ url: import.meta.env.VITE_APP_API + `v1/admin/QuestionExport`, data: data }) diff --git a/admin/src/views/ReportForms/TiJianTime.vue b/admin/src/views/ReportForms/TiJianTime.vue index ea060ba..6dae35a 100644 --- a/admin/src/views/ReportForms/TiJianTime.vue +++ b/admin/src/views/ReportForms/TiJianTime.vue @@ -2,7 +2,9 @@
- + + @@ -20,13 +22,13 @@ ElMessageBox } from 'element-plus' import { - FenzhenInfoExport + FenzhenInfoExport,FenzhenInfoExport2 } from '@/api/api.js' let loading = ref(false) - let date = ref(''); + let dateRange = ref([]); const ExportFenZhenInfo = () => { loading.value = true - FenzhenInfoExport({date:date.value}).then(res => { + FenzhenInfoExport2({dates:dateRange.value}).then(res => { loading.value = false if (res.status) { const a = document.createElement('a'); @@ -40,17 +42,10 @@ } }) } - const GetToday = () =>{ - const today = new Date(); - const year = today.getFullYear(); - const month = String(today.getMonth() + 1).padStart(2, '0'); // 注意月份是从0开始的 - const day = String(today.getDate()).padStart(2, '0') - date.value=(`${year}-${month}-${day}`) - - } + onMounted(() => { -GetToday() + })