You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

521 lines
17 KiB
PHP

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace App\Http\Controllers\API\H5;
use App\Http\Controllers\API\AspNetZhuanController;
use App\Http\Controllers\Controller;
use App\Services\ComboItemGroupService;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use App\Services\OrderService;
class FenzhenController extends Controller
{
public static $log = null;
public function abandon()
{
// 这里放 弃检逻辑
$id = request('id');
$xmid = request('xmid');
$orderInfo = DB::table('orders')->where('id', $id)->first();
if (!$orderInfo) return \Yz::echoError1("订单不存在");
$service = new ComboItemGroupService();
$q = $service->QiJian($orderInfo->tj_number, $orderInfo->name, [$xmid]);
if ($q['status'] === true) {
self::fenzhenAbandon($orderInfo, $xmid);
return \Yz::Return(true, "弃检成功", []);
} else {
return \Yz::echoError1($q['msg']);
}
}
public function fenzhenAbandon($orderInfo, $xmid)
{
$data = [
'name' => $orderInfo->name,
'id_number' => $orderInfo->id_number,
'uuid' => $orderInfo->tj_number,
'type' => '',
'check_type' => '1',
'sex' => $orderInfo->sex,
'birthday' => $orderInfo->birthday,
'phone' => $orderInfo->phone,
'registration_number' => $orderInfo->plan_number,
'items' => [],
'drops' => [(string)$xmid],
'regenerate' => '1',
'line_up' => '1',
'mute' => '2',
'show' => '1',
];
self::fz('abandon', $data);
}
public function check()
{
// 这里放 检查是否有 体检引导的数据
$id_number = request('id_number');
$type = 1;
$list = DB::table('orders')->where(['id_number' => $id_number])->where('appointment_date', '>=', date('Y-m-d'))
->whereIn('status', [2, 4])->orderBy('id', 'desc')->get();
if (count($list) == 0) {
$type = 2;
$list = DB::table('orders')->where(['id_number' => $id_number])->whereIn('status', [2, 4])->where('tj_number', '!=', null)->get();
if (count($list) == 0) {
$type = 3;
$list = DB::table('orders')->where(['id_number' => $id_number])->whereIn('status', [2, 4])->orderBy('id', 'desc')->get();
}
} else {
//如果有多个订单则优先显示到检的如果到检的订单超过了当天则显示最近的一个订单。2025年5月30日与佳豪语音沟通商定。
$l = [];
foreach ($list as $key => $item) {
if ( (!empty($item->check_time)) and substr($item->check_time,0,10) == date('Y-m-d')) {
$l = [$item];
$list = $l;
break;
}
}
if (count($l) == 0) {
$l = [$list[0]];
$list = $l;
}
}
return \Yz::Return(true, "弃检成功", [
'list' => $list,
'type' => $type
]);
}
public function list()
{
$id = request('id');
$info = DB::table('orders')->where(['id' => $id])->whereIn('status', [2, 4])->first();
if (!$info) return \Yz::echoError1("查询就诊人订单失败");
if($info->check_read_status==1){
DB::table('orders')->where('id', $id)->update(['check_read_status' => 2]);
}
$end_time = date('H:i', strtotime($info->appointment_date . ' ' . $info->appointment_time) + (60 * 60 * 0.54));
$clinics = [];
$order = new OrderService();
$order_data = $order->DepartmentItemCount($info->id);
$clinics = $order_data['department_list'];
$report_day = $order_data['wait_day'];
$is_checked_sign_in = $order_data['is_checked_sign_in'];
$error_day = $report_day;
if ($report_day == -1) {
$report_day = false;
}
// return \Yz::Return(true, "查询成功", [
// 'a'=>$order_data
// ]);
$res = self::fz('time', [
'exam_id' => $info->tj_number ?? '??????????',
'start_time' => date('H:i', strtotime($info->appointment_date . ' ' . $info->appointment_time)),
'clinics' => $clinics
]);
$KaHao='';//卡号
$person_ghzid = '';
$dnet = new AspNetZhuanController();
$res2 = $dnet->GetPersonInfo([
"zjh" => $info->id_number,
"action" => "2",
"ghzid"=>""
]);
$KaHao=isset($res2['data'][0]['KH'])?$res2['data'][0]['KH']:'';
$person_info = DB::table('web_user_person')->where('id', $info->web_user_id)->first();
if (!!$person_info) {
$person_ghzid = $person_info->ghzid;
}
if (!!$res) {
$time_line = $res['data']['time_line'];
$end_queue = $res['data']['end_queue'];
$clinic_map = [];
foreach ($time_line as $key => $item) {
if (isset($item['his_number'])) {
$clinic_map[] = $item['his_number'];
}
}
foreach ($end_queue as $key => $item) {
if (isset($item['his_number'])) {
$clinic_map[] = $item['his_number'];
}
}
$last_time = strtotime('2024-10-10 ' . $time_line[count($time_line) - 1]['time'] . ':00');
if (!$res['data']['queue']) {
$push_end = false;
foreach ($clinics as $item) {
if (!in_array($item['keshi_id'], $clinic_map)) {
$push_end = true;
$item_count = $item['count'];
$in_time = date('H:i', $last_time);
$time_line = array_merge(array_splice($time_line, 0, count($time_line) - 1), [
[
"desc" => "预计 $in_time 进入队列",
"more" => 0,
"name" => $item['name'],
"status" => 1,
'count' => -1,
"time" => "$in_time",
"tip" => "剩余{$item_count}项正在排队中,"
]
], [$time_line[count($time_line) - 1]]);
$last_time = $last_time + (60 * 5);
}
}
if ($push_end) {
$in_time = date('H:i', $last_time);
$time_line = array_merge(array_splice($time_line, 0, count($time_line) - 1), [
[
"desc" => "结束时间 $in_time",
"more" => 0,
"name" => "体检结束",
"status" => -1,
'count' => -1,
"time" => "$in_time",
"tip" => ""
]
]);
}
}
$end_status = 0;
$tip_check_show = false;
foreach ($time_line as $time_line_item) {
if ($time_line_item['status'] == 4) {
$end_status += 1;
}
}
if (count($time_line) <= $end_status + 1) {
$tip_check_show = true;
$time_line[count($time_line) - 1]['status'] = 4;
}
// 插入 体检区外的 诊室
if (count($end_queue) != 0) {
foreach ($end_queue as $end_queue_item) {
$time_line[] = $end_queue_item;
}
}
// -1 报告未出 不能预约 报告解读 不显示
// 0 时间未到 不能预约 报告解读 不显示
// 1 时间已到 可以预约 报告解读
// 2 已经预约 报告解读
$check_report_status = -1;
$now_time = time();
// $now_time = strtotime('2024-11-07 00:00:00');
if (!!$res['data']['report']) {
if ($report_day !== false) {
$report_status = false;
$report_time = strtotime($res['data']['report'] . ' 00:00:00') + (60 * 60 * 24 * $report_day);
$report_time_show = date('m月d日', $report_time);
// 这里补充 获取 出具报告 时间的逻辑
if ($report_time < $now_time) {
$report_status = true;
}
if (!$report_status) {
$time_line[] = [
'time' => '',
'name' => '出具报告',
'status' => -1,
'count' => -1,
'desc' => "预计 $report_time_show 出具体检报告",
'tip' => '',
'more' => 0
];
} else {
$time_line[] = [
'time' => '',
'name' => '出具报告',
'status' => -1,
'count' => -1,
'desc' => "已出具体检报告 $report_time_show",
'tip' => '',
'more' => 0
];
}
$check_report_time = $report_time + (60 * 60 * 24);
$check_report_status = 0;
// $check_report_status = '2024年10月11日';
// 这里补充 获取 报告解读 时间的逻辑
if ($check_report_time < $now_time) {
if (!!$info->person_id) {
$user_info = DB::table('web_user_person')->where(['id' => $info->person_id])->first();
if (!!$user_info) {
$hospital_map = [
'h1' => '6',
'h4' => '2'
];
$dnet = new AspNetZhuanController();
$hid = $info->hospital_id;
$report_res = $dnet->GetReportAnalysis([
"yyrq" => date('Y-m-d', $check_report_time),
"ghzid" => $user_info->ghzid,
"yyid" => $hospital_map["h$hid"],
"action" => "1"
]);
switch ($report_res['code']) {
case '200':
$check_report_status = 2;
$show_date = date('m-d', strtotime($report_res['yyrq']));
$time_line[] = [
'time' => '',
'name' => '报告解读',
'status' => -1,
'count' => -1,
'desc' => "已预约 $show_date 报告解读",
'tip' => '',
'more' => 0
];
break;
case '199':
case '201':
$check_report_status = 1;
$time_line[] = [
'time' => '',
'name' => '报告解读',
'status' => -1,
'count' => -1,
'desc' => "可以预约报告解读",
'tip' => '',
'more' => 0
];
break;
case '202':
$check_report_status = 0;
$time_line[] = [
'time' => '',
'name' => '报告解读',
'status' => 1,
'count' => -1,
'desc' => "已完成报告解读",
'tip' => '',
'more' => 0
];
break;
}
}
}
} else {
$check_report_time_show = date('m月d日', $check_report_time);
$time_line[] = [
'time' => '',
'name' => '报告解读',
'status' => -1,
'count' => -1,
'desc' => "预计 $check_report_time_show 可以预约报告解读",
'tip' => '',
'more' => 0
];
}
}
}
if (!$tip_check_show) {
$res['data']['end_time'] = date('H:i', $last_time);
}
$check_tip = false;
// \Yz::debug(['$is_checked_sign_in'=>$is_checked_sign_in,'$error_day'=>$error_day]);
if (!!$is_checked_sign_in) {
if ($error_day == -1) {
if (!!$tip_check_show) {
$et = $info->appointment_date . ' ' . $res['data']['end_time'] . ':00';
$check_tip = (time() - strtotime($et)) > (60 * 20);
}
}
}
return \Yz::Return(true, "获取成功", [
'info' => [
'name' => $info->name,
'sex' => $info->sex,
'combo_name' => $info->title,
'check_date' => $info->appointment_date,
'plan_number' => $info->plan_number,
'start_time' => $res['data']['start_time'] . ':00',
'end_time' => $res['data']['end_time'],
'yuji_end_time' => $res['data']['yuji_end_time'],
'yuji_use_time' => $res['data']['yuji_use_time'],
'use_time' => $res['data']['use_time'],
'qrcode' => $person_ghzid,
'tj_number' => $info->tj_number,
'ghzid' => $person_ghzid,
'kahao'=>$KaHao,
'code' => $info->appointment_number,
],
'list' => $time_line,
'report' => $check_report_status,
'check_tip' => $check_tip,
]);
} else {
return \Yz::Return(true, "获取成功", [
'info' => [
'name' => $info->name,
'sex' => $info->sex,
'combo_name' => $info->title,
'check_date' => $info->appointment_date,
'plan_number' => $info->plan_number,
'start_time' => $info->appointment_time,
'end_time' => $end_time,
'yuji_end_time' => $end_time,
'yuji_use_time' => '',
'use_time' => '',
'qrcode' => $person_ghzid,
'ghzid' => $person_ghzid,
'kahao'=>$KaHao,
'tj_number' => $info->tj_number,
'code' => $info->appointment_number,
],
'list' => [],
'report' => -1,
'check_tip' => false,
]);
}
}
public function info()
{
$id = request('id');
$clinic = request('clinic');
$info = DB::table('orders')->where(['id' => $id])->whereIn('status', [2, 4])->first();
if (!$info) return \Yz::echoError1("查询就诊人订单失败");
$res = self::fz('info', [
'exam_id' => $info->tj_number ?? '??????????',
'clinic' => $clinic,
]);
$person_ghzid = '';
$person_info = DB::table('web_user_person')->where('id', $info->person_id)->first();
if (!!$person_info) {
$person_ghzid = $person_info->ghzid;
}
if (!!$res) {
if ($res['code'] == 200) {
$item_list = $res['data']['list'];
foreach ($item_list as $item_index => $item_info) {
$db_item = DB::table('items')
->where('item_id', $item_info['id'])
->first();
if (!!$db_item) {
$item_list[$item_index]['desc'] = self::item_desc($db_item);
} else {
$item_list[$item_index]['desc'] = '';
}
}
return \Yz::Return(true, "获取成功", [
'info' => [
'name' => $info->name,
'sex' => $info->sex,
'combo_name' => $info->title,
'check_date' => $info->appointment_date,
'start_time' => $info->appointment_time,
'end_time' => '10:25',
'qrcode' => $person_ghzid,
'ghzid' => $person_ghzid,
'tj_number' => $info->tj_number,
'code' => $info->appointment_number,
],
'list' => $item_list,
]);
} else {
return \Yz::Return(false, $res['message']);
}
} else {
return \Yz::Return(false, "获取失败");
}
}
public function item_desc($item)
{
// $canqian = $item->can_qian_hou == '餐前' ? '餐前' : '';
$beizhu = !!$item->beizhu ? $item->beizhu : '';
$tishi = !!$item->tishi ? $item->tishi : '';
$ret = [];
// if (!!$canqian) {
// $ret[] = $canqian;
// }
if (!!$beizhu) {
$ret[] = $beizhu;
}
if (!!$tishi) {
$ret[] = $tishi;
}
return count($ret) == 0 ? '' : '(' . implode(',', $ret) . ')';
}
public function post($url, $data)
{
$data_string = json_encode($data, JSON_UNESCAPED_UNICODE);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
'Content-Type: application/json; charset=utf-8',
'Content-Length: ' . strlen($data_string),
'Authorization: Bearer BD30333C-CBD4-4BA3-A27C-76727FF4D8B1'
]);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
$r = curl_exec($curl);
curl_close($curl);
return $r;
}
public function fz($type, $content)
{
$date = date('Y-m-d');
self::CheckTableName(date('Y-m-d'));
self::$log->date = $date;
self::$log->type = $type;
self::$log->content = json_encode($content, JSON_UNESCAPED_UNICODE);
self::$log->callback = '{}';
self::$log->save();
$url_map = [
'time' => '/api/Open/TiJian/get',
'info' => '/api/Open/TiJian/info',
'search' => '/api/Open/TiJian/search',
'change' => '/api/Open/TiJian/change',
'export' => '/api/Open/TiJian/export',
'abandon' => '/api/Open/Queue/registration?client=open',
];
$url = env('FENZHEN_URL');
$res = self::post("$url{$url_map[$type]}", $content);
// /api/Open/TiJian/get
self::$log->callback = $res;
self::$log->save();
if (json_decode($res)) {
return json_decode($res, true);
} else {
return false;
}
}
public static function CheckTableName($date)
{
$table_name = 'zz_fenzhen_log_' . date('ym', strtotime($date));
$table_count = DB::select('select count(1) as c from information_schema.TABLES where table_schema = ? and table_name = ?', [env('DB_DATABASE'), $table_name])[0];
if ($table_count->c === 0) {
Schema::create($table_name, function (Blueprint $table) {
$table->id();
$table->date('date')->index();
$table->string('type', 20)->index();
$table->longText('content');
$table->longText('callback');
$table->timestamps();
});
}
self::$log = new \App\Models\FenzhenLog;
self::$log->setTable($table_name);
return $table_name;
}
}