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.
329 lines
11 KiB
PHP
329 lines
11 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\API\H5;
|
|
|
|
use App\Http\Controllers\API\AspNetZhuanController;
|
|
use App\Http\Controllers\Controller;
|
|
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()
|
|
{
|
|
// 这里放 弃检逻辑
|
|
|
|
return \Yz::Return(true, "弃检成功");
|
|
}
|
|
|
|
public function check()
|
|
{
|
|
// 这里放 检查是否有 体检引导的数据
|
|
$id_number = request('id_number');
|
|
$list = DB::table('orders')->where(['id_number' => $id_number])->whereIn('status', [2, 4])->where('tj_number', '!=', null)->orderBy('id', 'desc')->get();
|
|
if (count($list) == 0) {
|
|
$list = DB::table('orders')->where(['id_number' => $id_number])->whereIn('status', [2, 4])->orderBy('id', 'desc')->get();
|
|
}
|
|
return \Yz::Return(true, "弃检成功", ['list' => $list]);
|
|
}
|
|
|
|
public function list()
|
|
{
|
|
$id = request('id');
|
|
$info = DB::table('orders')->where(['id' => $id])->whereIn('status', [2, 4])->first();
|
|
if (!$info) return \Yz::echoError1("查询就诊人订单失败");
|
|
$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'];
|
|
$res = self::fz('time', [
|
|
'exam_id' => $info->tj_number ?? '??????????',
|
|
'start_time' => date('H:i', strtotime($info->appointment_date . ' ' . $info->appointment_time)),
|
|
'clinics' => $clinics
|
|
]);
|
|
if (!!$res) {
|
|
$time_line = $res['data']['time_line'];
|
|
$clinic_map = [];
|
|
foreach ($time_line 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,
|
|
"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,
|
|
"time" => "$in_time",
|
|
"tip" => ""
|
|
]
|
|
]);
|
|
}
|
|
}
|
|
// -1 报告未出 不能预约 报告解读 不显示
|
|
// 0 时间未到 不能预约 报告解读 不显示
|
|
// 1 时间已到 可以预约 报告解读
|
|
// 2 已经预约 报告解读
|
|
$check_report_status = -1;
|
|
$now_time = time();
|
|
// $now_time = strtotime('2024-11-07 00:00:00');
|
|
if (!!$res['data']['report']) {
|
|
$report_time = strtotime($res['data']['report'] . ' 00:00:00') + (60 * 60 * 24 * $report_day);
|
|
$report_time_show = date('m月d日', $report_time);
|
|
$report_status = false;
|
|
// 这里补充 获取 出具报告 时间的逻辑
|
|
if ($report_time < $now_time) {
|
|
$report_status = true;
|
|
}
|
|
if (!$report_status) {
|
|
$time_line[] = [
|
|
'time' => '',
|
|
'name' => '出具报告',
|
|
'status' => -1,
|
|
'desc' => "预计 $report_time_show 出具体检报告",
|
|
'tip' => '',
|
|
'more' => 0
|
|
];
|
|
} else {
|
|
$time_line[] = [
|
|
'time' => '',
|
|
'name' => '出具报告',
|
|
'status' => -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,
|
|
'desc' => "已预约 $show_date 报告解读",
|
|
'tip' => '',
|
|
'more' => 0
|
|
];
|
|
break;
|
|
case '199':
|
|
case '201':
|
|
$check_report_status = 1;
|
|
$time_line[] = [
|
|
'time' => '',
|
|
'name' => '报告解读',
|
|
'status' => -1,
|
|
'desc' => "可以预约报告解读",
|
|
'tip' => '',
|
|
'more' => 0
|
|
];
|
|
break;
|
|
case '202':
|
|
$check_report_status = 0;
|
|
$time_line[] = [
|
|
'time' => '',
|
|
'name' => '报告解读',
|
|
'status' => 1,
|
|
'desc' => "已完成报告解读",
|
|
'tip' => '',
|
|
'more' => 0
|
|
];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
$check_report_time_show = date('m月d日', $check_report_time);
|
|
$time_line[] = [
|
|
'time' => '',
|
|
'name' => '报告解读',
|
|
'status' => -1,
|
|
'desc' => "预计 $check_report_time_show 可以预约报告解读",
|
|
'tip' => '',
|
|
'more' => 0
|
|
];
|
|
}
|
|
}
|
|
$res['data']['end_time'] = date('H:i', $last_time);
|
|
return \Yz::Return(true, "获取成功", [
|
|
'info' => [
|
|
'name' => $info->name,
|
|
'sex' => $info->sex,
|
|
'combo_name' => $info->title,
|
|
'check_date' => $info->appointment_date,
|
|
'start_time' => $res['data']['start_time'] . ':00',
|
|
'end_time' => $res['data']['end_time'],
|
|
'qrcode' => '',
|
|
'code' => $info->appointment_number,
|
|
],
|
|
'list' => $time_line,
|
|
'report' => $check_report_status,
|
|
]);
|
|
} else {
|
|
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' => $end_time,
|
|
'qrcode' => '',
|
|
'code' => $info->appointment_number,
|
|
],
|
|
'list' => [],
|
|
'report' => -1,
|
|
]);
|
|
}
|
|
}
|
|
|
|
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,
|
|
]);
|
|
if (!!$res) {
|
|
if ($res['code'] == 200) {
|
|
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' => '',
|
|
'code' => $info->appointment_number,
|
|
],
|
|
'list' => $res['data']['list'],
|
|
]);
|
|
} else {
|
|
return \Yz::Return(false, $res['message']);
|
|
}
|
|
} else {
|
|
return \Yz::Return(false, "获取失败");
|
|
}
|
|
}
|
|
|
|
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',
|
|
];
|
|
$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;
|
|
}
|
|
}
|