|
|
|
@ -13,7 +13,9 @@ use App\Models\Patient; |
|
|
|
|
use App\Services\HisHttp\Client; |
|
|
|
|
use App\Utils\Traits\Logger; |
|
|
|
|
use App\Utils\Traits\MiniProgramAuth; |
|
|
|
|
use App\Utils\Traits\SendSubscribeMessage; |
|
|
|
|
use Illuminate\Auth\AuthenticationException; |
|
|
|
|
use Illuminate\Support\Facades\Redis; |
|
|
|
|
use ReflectionException; |
|
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
|
|
|
use UnifyPayment\Cores\Exceptions\InvalidConfigException; |
|
|
|
@ -26,6 +28,7 @@ class RegisterLogic |
|
|
|
|
{ |
|
|
|
|
use Logger; |
|
|
|
|
use MiniProgramAuth; |
|
|
|
|
use SendSubscribeMessage; |
|
|
|
|
|
|
|
|
|
private Client $his_client; |
|
|
|
|
|
|
|
|
@ -47,7 +50,8 @@ class RegisterLogic |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param string $patient_id |
|
|
|
|
* 挂号 |
|
|
|
|
* @param string $patient_number |
|
|
|
|
* @param string $date |
|
|
|
|
* @param string $dept_id |
|
|
|
|
* @param string $doctor_id |
|
|
|
@ -55,22 +59,25 @@ class RegisterLogic |
|
|
|
|
* @return array |
|
|
|
|
* @throws GeneralException |
|
|
|
|
*/ |
|
|
|
|
public function register(string $patient_id, string $date, string $dept_id, string $doctor_id, string $reg_id): array |
|
|
|
|
public function register(string $patient_number, string $date, string $dept_id, string $doctor_id, string $reg_id): array |
|
|
|
|
{ |
|
|
|
|
// 基础信息 |
|
|
|
|
$patient_info = $this->getPatientInfo($patient_id, $this->open_id); |
|
|
|
|
$patient_info = $this->getPatientInfo($this->open_id, $patient_number); |
|
|
|
|
$schedule_info = $this->getRegisterScheduleDetails($date, $dept_id, $doctor_id, $reg_id); |
|
|
|
|
|
|
|
|
|
// 锁号? |
|
|
|
|
|
|
|
|
|
// 创建订单 |
|
|
|
|
$order_type = $date === date('Y-m-d') ? Type::TODAY_REGISTRATION : Type::APPOINTMENT_REGISTRATION; |
|
|
|
|
$pay_type = PayType::WECHAT_PAY; |
|
|
|
|
$order_id = $this->order_model->getOrderId($pay_type, 'M'); |
|
|
|
|
$reg_fee = (float)(string) $schedule_info['SHIFT']['FEE']; |
|
|
|
|
$reg_fee = (float)(string) $schedule_info['scheduleInfo']['fee']; |
|
|
|
|
|
|
|
|
|
$order = $this->createOrder($order_id, $pay_type, $reg_fee, $order_type, $patient_info, $schedule_info); |
|
|
|
|
|
|
|
|
|
// 挂号金额为 0 元 |
|
|
|
|
if ($reg_fee === 0.0) { |
|
|
|
|
return $this->freeRegistrationConfirm($order); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 申请支付 |
|
|
|
|
$pay_data = $this->applyPayment($order_type, $order_id, $reg_fee, $patient_info['patientNumber'], $patient_info['name']); |
|
|
|
|
|
|
|
|
@ -82,14 +89,14 @@ class RegisterLogic |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取患者信息 |
|
|
|
|
* @param string $patient_id |
|
|
|
|
* @param string $open_id |
|
|
|
|
* @param string $patient_number |
|
|
|
|
* @return mixed |
|
|
|
|
* @throws GeneralException |
|
|
|
|
*/ |
|
|
|
|
protected function getPatientInfo(string $patient_id, string $open_id): mixed |
|
|
|
|
protected function getPatientInfo(string $open_id, string $patient_number): mixed |
|
|
|
|
{ |
|
|
|
|
$info = $this->patient_model->getBindPatientInfo($open_id, $patient_id); |
|
|
|
|
$info = $this->patient_model->getBindPatientInfoByPatientNumber($open_id, $patient_number); |
|
|
|
|
if (empty($info)) { |
|
|
|
|
throw new GeneralException('找不到患者信息,请重新再试!', Response::HTTP_BAD_REQUEST); |
|
|
|
|
} |
|
|
|
@ -121,18 +128,17 @@ class RegisterLogic |
|
|
|
|
// 获取排班医生信息 |
|
|
|
|
$is_today = $dept_id === date('Y-m-d') ? '3' : '1'; |
|
|
|
|
$schedule_info = $this->his_client->getDoctorLists($dept_id, $is_today, '', $date); |
|
|
|
|
if (!isset($schedule_info['RESULTCODE']) || $schedule_info['RESULTCODE'] !== '0') { |
|
|
|
|
throw new GeneralException($schedule_info['ERRORMSG'] ?? '找不到该号源,请重新再试!', Response::HTTP_SERVICE_UNAVAILABLE); |
|
|
|
|
if (!isset($schedule_info['success']) || !$schedule_info['success']) { |
|
|
|
|
throw new GeneralException($schedule_info['msg'] ?? '找不到该号源,请重新再试!', Response::HTTP_SERVICE_UNAVAILABLE); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 获取号源信息 |
|
|
|
|
$schedule_info = xmlArrayToListByKey($schedule_info, 'ITEM'); |
|
|
|
|
foreach ($schedule_info['ITEM'] as $v) { |
|
|
|
|
if ($v['DOCTID'] === $doctor_id) { |
|
|
|
|
$v = xmlArrayToListByKey($v, 'SHIFT'); |
|
|
|
|
foreach ($v['SHIFT'] as $v2) { |
|
|
|
|
if ($v2['REGID'] === $reg_id && $v2['FDATE'] === $date) { |
|
|
|
|
$v['SHIFT'] = $v2; |
|
|
|
|
foreach ($schedule_info['response'] as $v) { |
|
|
|
|
if ($v['doctId'] === $doctor_id) { |
|
|
|
|
foreach ($v['doctotVisitInfoList'] as $v2) { |
|
|
|
|
if ($v2['regId'] === $reg_id && $v2['visitDate'] === $date) { |
|
|
|
|
$v['scheduleInfo'] = $v2; |
|
|
|
|
unset($v['doctotVisitInfoList']); |
|
|
|
|
$info = $v; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -143,21 +149,26 @@ class RegisterLogic |
|
|
|
|
throw new GeneralException('找不到该号源,请重新再试!', Response::HTTP_BAD_REQUEST); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!isset($info['SHIFT']['REGCOUNT']) || $info['SHIFT']['REGCOUNT'] <= 0) { |
|
|
|
|
if (!isset($info['scheduleInfo']['regCount']) || $info['scheduleInfo']['regCount'] <= 0) { |
|
|
|
|
throw new GeneralException('该号源已挂完,请重新选择号源!', Response::HTTP_BAD_REQUEST); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 获取科室名称 |
|
|
|
|
$dept_lists = $this->his_client->getDepType('', '','01', $date); |
|
|
|
|
if (!isset($schedule_info['RESULTCODE']) || $schedule_info['RESULTCODE'] !== '0') { |
|
|
|
|
throw new GeneralException($schedule_info['ERRORMSG'] ?? '找不到该号源,请重新再试!', Response::HTTP_SERVICE_UNAVAILABLE); |
|
|
|
|
if (Redis::exists('departments.'. $date)) { |
|
|
|
|
$dept_lists = Redis::get('departments.'. $date); |
|
|
|
|
$dept_lists = json_decode($dept_lists, true); |
|
|
|
|
} else { |
|
|
|
|
$dept_lists = $this->his_client->getDepType('', '','01', $date); |
|
|
|
|
|
|
|
|
|
if (!isset($dept_lists['success']) || !$dept_lists['success']) { |
|
|
|
|
throw new GeneralException($schedule_info['msg'] ?? '找不到该号源,请重新再试!', Response::HTTP_SERVICE_UNAVAILABLE); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$dept_lists = xmlArrayToListByKey($dept_lists, 'ITEM'); |
|
|
|
|
foreach ($dept_lists['ITEM'] as $v) { |
|
|
|
|
if ($v['DEPID'] === $dept_id) { |
|
|
|
|
$info['dept_id'] = $v['DEPID']; |
|
|
|
|
$info['dept_name'] = $v['DEPNAME']; |
|
|
|
|
foreach ($dept_lists['response'] as $v) { |
|
|
|
|
if ($v['typeId'] === $dept_id) { |
|
|
|
|
$info['dept_id'] = $v['typeId']; |
|
|
|
|
$info['dept_name'] = $v['typeName']; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -181,15 +192,15 @@ class RegisterLogic |
|
|
|
|
// 挂号记录表 |
|
|
|
|
$reg_record_data = [ |
|
|
|
|
'relate_patient_id' => $patient_info['id'], |
|
|
|
|
'reg_id' => $schedule_info['SHIFT']['REGID'], |
|
|
|
|
'reg_id' => $schedule_info['scheduleInfo']['regId'], |
|
|
|
|
'dept_id' => $schedule_info['dept_id'], |
|
|
|
|
'dept_name' => $schedule_info['dept_name'], |
|
|
|
|
'dept_location' => $schedule_info['DEPLOCATION'], |
|
|
|
|
'doctor_id' => $schedule_info['DOCTID'], |
|
|
|
|
'doctor_name' => $schedule_info['DOCTNAME'], |
|
|
|
|
'visit_date' => date('Y-m-d', strtotime($schedule_info['SHIFT']['FDATE'])), |
|
|
|
|
'begin_time' => $schedule_info['SHIFT']['STARTTIME'], |
|
|
|
|
'end_time' => $schedule_info['SHIFT']['ENDTIME'], |
|
|
|
|
'dept_location' => '', |
|
|
|
|
'doctor_id' => $schedule_info['doctId'], |
|
|
|
|
'doctor_name' => $schedule_info['doctName'], |
|
|
|
|
'visit_date' => date('Y-m-d', strtotime($schedule_info['scheduleInfo']['visitDate'])), |
|
|
|
|
'begin_time' => $schedule_info['scheduleInfo']['startTime'], |
|
|
|
|
'end_time' => $schedule_info['scheduleInfo']['endTime'], |
|
|
|
|
'lock_status' => 0, |
|
|
|
|
'extra_info' => json_encode($schedule_info, JSON_UNESCAPED_UNICODE), |
|
|
|
|
]; |
|
|
|
@ -201,8 +212,8 @@ class RegisterLogic |
|
|
|
|
$reg_fee * 100, |
|
|
|
|
0, |
|
|
|
|
$this->open_id, |
|
|
|
|
$patient_info['PATIENTID'], |
|
|
|
|
$patient_info['NAME'], |
|
|
|
|
$patient_info['patientId'], |
|
|
|
|
$patient_info['name'], |
|
|
|
|
$order_type, |
|
|
|
|
SourceId::MINI_PROGRAM, |
|
|
|
|
$reg_record_data |
|
|
|
@ -215,6 +226,58 @@ class RegisterLogic |
|
|
|
|
return $order; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 免费挂号确认 |
|
|
|
|
* @param Order $order |
|
|
|
|
* @return array |
|
|
|
|
* @throws GeneralException |
|
|
|
|
*/ |
|
|
|
|
protected function freeRegistrationConfirm(Order $order): array |
|
|
|
|
{ |
|
|
|
|
// 挂号确认 |
|
|
|
|
$record = &$order->registrationRecord; |
|
|
|
|
$extra = json_decode($record->extra_info, true); |
|
|
|
|
|
|
|
|
|
$data = [ |
|
|
|
|
$order->patient_id, |
|
|
|
|
$order->patient_name, |
|
|
|
|
$record->dept_id, |
|
|
|
|
$record->doctor_id, |
|
|
|
|
$record->reg_id, |
|
|
|
|
$extra['scheduleInfo']['rankId'], |
|
|
|
|
$record->visit_date, |
|
|
|
|
PayType::WECHAT_PAY->hisCode(), |
|
|
|
|
$order->order_id, |
|
|
|
|
'', |
|
|
|
|
'', |
|
|
|
|
'', |
|
|
|
|
'', |
|
|
|
|
'0', |
|
|
|
|
'' |
|
|
|
|
]; |
|
|
|
|
$response = $this->his_client->registerConfirm(... $data); |
|
|
|
|
$this->info('挂号订单出入参:'.$order->order_id, [$data, $response]); |
|
|
|
|
|
|
|
|
|
if (isset($response['success']) && $response['success'] === true) { |
|
|
|
|
// 成功流程 |
|
|
|
|
$order->orderConfirm($order->order_id, $response['response']['visitNo'], $response['response']); |
|
|
|
|
|
|
|
|
|
// 推送成功 |
|
|
|
|
$this->sendRegistrationSuccessMessage($order); |
|
|
|
|
|
|
|
|
|
// 返回数据 |
|
|
|
|
return [ |
|
|
|
|
'order_id' => $order->order_id, |
|
|
|
|
'reg_serial_no' => $response['response']['visitNo'] |
|
|
|
|
]; |
|
|
|
|
} else { |
|
|
|
|
// 推送失败 |
|
|
|
|
$this->sendRegistrationFailureMessage($order); |
|
|
|
|
|
|
|
|
|
throw new GeneralException('挂号失败,失败原因:'. ($response['msg'] ?? '数据异常'). ',请重新再试!'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 申请支付 |
|
|
|
|
* @param Type $order_type |
|
|
|
@ -242,7 +305,7 @@ class RegisterLogic |
|
|
|
|
$response = Unify::pay(config('unify'))->mini->setMockHandler([new CreateOrderHandler(true)])->jsapi($order_obj); |
|
|
|
|
$this->info('jsapi 支付参数', $response); |
|
|
|
|
|
|
|
|
|
if (!$response['success'] || empty($response['response'])) { |
|
|
|
|
if (!$response['success'] && empty($response['response'])) { |
|
|
|
|
throw new GeneralException('申请支付失败,请重新再试!', Response::HTTP_SERVICE_UNAVAILABLE); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|