diff --git a/app/Amqp/Consumer/AssignDoctorDelayDirectConsumer.php b/app/Amqp/Consumer/AssignDoctorDelayDirectConsumer.php index 891696a..43a8c49 100644 --- a/app/Amqp/Consumer/AssignDoctorDelayDirectConsumer.php +++ b/app/Amqp/Consumer/AssignDoctorDelayDirectConsumer.php @@ -30,6 +30,9 @@ use PhpAmqpLib\Message\AMQPMessage; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; +/** + * 快速-购药分配医生 + */ #[Consumer(nums: 1)] class AssignDoctorDelayDirectConsumer extends ConsumerMessage { diff --git a/app/Amqp/Consumer/AutoCompleteInquiryDelayDirectConsumer.php b/app/Amqp/Consumer/AutoCompleteInquiryDelayDirectConsumer.php index 770f130..95fe4c4 100644 --- a/app/Amqp/Consumer/AutoCompleteInquiryDelayDirectConsumer.php +++ b/app/Amqp/Consumer/AutoCompleteInquiryDelayDirectConsumer.php @@ -45,14 +45,14 @@ class AutoCompleteInquiryDelayDirectConsumer extends ConsumerMessage public function consumeMessage($data, AMQPMessage $message): string { - Log::getInstance()->error("开始执行 自动完成问诊订单 队列:" . json_encode($data, JSON_UNESCAPED_UNICODE)); + Log::getInstance("queue-AutoCompleteInquiry")->info(json_encode($data, JSON_UNESCAPED_UNICODE)); Db::beginTransaction(); try { // 检测入参参数 if (empty($data['order_inquiry_id'])) { Db::rollBack(); - Log::getInstance()->error("自动完成问诊订单队列执行失败:入参错误"); + Log::getInstance("queue-AutoCompleteInquiry")->error("参数错误"); return Result::DROP; } @@ -62,7 +62,7 @@ class AutoCompleteInquiryDelayDirectConsumer extends ConsumerMessage $order_inquiry = OrderInquiry::getOne($params); if (empty($order_inquiry)) { Db::rollBack(); - Log::getInstance()->error("自动完成问诊订单队列执行失败:问诊订单数据为空"); + Log::getInstance("queue-AutoCompleteInquiry")->error("问诊订单数据为空"); return Result::DROP; } @@ -72,23 +72,23 @@ class AutoCompleteInquiryDelayDirectConsumer extends ConsumerMessage if ($order_inquiry['inquiry_status'] != 4) { // 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消) Db::rollBack(); - Log::getInstance()->info("自动完成问诊订单队列执行结果:无需处理"); - return Result::DROP; + Log::getInstance("queue-AutoCompleteInquiry")->info("无需处理"); + return Result::ACK; } // 检测问诊订单退款状态 if (!in_array($order_inquiry['inquiry_refund_status'],[0,4,5])){ // 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常) Db::rollBack(); - Log::getInstance()->info("自动完成问诊订单队列执行结果:订单退款中,无需处理"); - return Result::DROP; + Log::getInstance("queue-AutoCompleteInquiry")->info("订单退款中,无需处理"); + return Result::ACK; } // 订单支付状态 if ($order_inquiry['inquiry_pay_status'] != 2){ Db::rollBack(); - Log::getInstance()->info("自动完成问诊订单队列执行结果:订单未支付,无需处理"); - return Result::DROP; + Log::getInstance("queue-AutoCompleteInquiry")->info("订单未支付,无需处理"); + return Result::ACK; } // 新增患者历史问诊表 @@ -104,8 +104,8 @@ class AutoCompleteInquiryDelayDirectConsumer extends ConsumerMessage $patient_history_inquiry = PatientHistoryInquiry::addPatientHistoryInquiry($data); if (empty($patient_history_inquiry)){ Db::rollBack(); - Log::getInstance()->info("自动完成问诊订单队列执行结果:新增患者历史问诊表失败"); - return Result::DROP; + Log::getInstance("queue-AutoCompleteInquiry")->error("新增患者历史问诊表失败"); + return Result::REQUEUE; } // 获取医生数据 @@ -114,7 +114,7 @@ class AutoCompleteInquiryDelayDirectConsumer extends ConsumerMessage $user_doctor = UserDoctor::getOne($params); if(empty($user_doctor)){ Db::rollBack(); - Log::getInstance()->info("自动完成问诊订单队列执行结果:缺少医生数据"); + Log::getInstance("queue-AutoCompleteInquiry")->error("缺少医生数据"); return Result::DROP; } @@ -163,16 +163,16 @@ class AutoCompleteInquiryDelayDirectConsumer extends ConsumerMessage $res = $producer->produce($message); if (!$res) { Db::rollBack(); - Log::getInstance()->info("自动完成问诊订单队列执行结果:添加自动结束队列失败"); + Log::getInstance("queue-AutoCompleteInquiry")->error("添加自动结束队列失败"); return Result::DROP; } Db::commit(); - Log::getInstance()->info("自动完成问诊订单队列执行成功"); + Log::getInstance("queue-AutoCompleteInquiry")->info("执行成功"); } catch (\Exception $e) { Db::rollBack(); - Log::getInstance()->error("自动完成问诊订单执行失败:" . $e->getMessage()); + Log::getInstance("queue-AutoCompleteInquiry")->error($e->getMessage()); return Result::ACK; // 重回队列 } @@ -195,10 +195,8 @@ class AutoCompleteInquiryDelayDirectConsumer extends ConsumerMessage // 医生-发送站内消息-问诊结束 $MessagePush = new MessagePush($user_doctor['user_id'],$order_inquiry['order_inquiry_id']); $MessagePush->finishInquiryToDoctor(); - - - }catch (\Exception $e){ - Log::getInstance()->error("发送消息异常错误:" . $e->getMessage()); + }catch (\Throwable $e){ + Log::getInstance("queue-AutoCompleteInquiry")->error($e->getMessage()); return Result::ACK; } diff --git a/app/Amqp/Consumer/AutoFinishInquiryDelayDirectConsumer.php b/app/Amqp/Consumer/AutoFinishInquiryDelayDirectConsumer.php index 20f74f4..b4fe764 100644 --- a/app/Amqp/Consumer/AutoFinishInquiryDelayDirectConsumer.php +++ b/app/Amqp/Consumer/AutoFinishInquiryDelayDirectConsumer.php @@ -4,27 +4,34 @@ declare(strict_types=1); namespace App\Amqp\Consumer; +use App\Amqp\Producer\AutoFinishInquiryDelayDirectProducer; +use App\Constants\HttpEnumCode; use App\Model\DoctorAccount; use App\Model\DoctorAccountDay; use App\Model\OrderEvaluation; use App\Model\OrderInquiry; use App\Model\OrderInquiryCase; use App\Model\OrderPrescription; +use App\Model\PatientFamily; use App\Model\PatientFamilyHealth; use App\Model\PatientFamilyPersonal; +use App\Model\PatientPathography; use App\Model\UserDoctor; use App\Model\UserPatient; use App\Services\ImService; use App\Services\MessagePush; +use App\Services\ReportRegulatoryService; use App\Utils\Log; use App\Utils\Mask; use Hyperf\Amqp\Message\ConsumerDelayedMessageTrait; use Hyperf\Amqp\Message\ProducerDelayedMessageTrait; use Hyperf\Amqp\Message\Type; +use Hyperf\Amqp\Producer; use Hyperf\Amqp\Result; use Hyperf\Amqp\Annotation\Consumer; use Hyperf\Amqp\Message\ConsumerMessage; use Hyperf\DbConnection\Db; +use Hyperf\Redis\Redis; use PhpAmqpLib\Message\AMQPMessage; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; @@ -52,45 +59,55 @@ class AutoFinishInquiryDelayDirectConsumer extends ConsumerMessage { Log::getInstance("queue-AutoFinishInquiry")->info("开始:" . json_encode($data, JSON_UNESCAPED_UNICODE)); + // 检测入参参数 + if (empty($data['order_inquiry_id'])) { + Log::getInstance("queue-AutoFinishInquiry")->error("错误:入参错误"); + return Result::DROP; + } + + // 获取问诊订单数据 + $params = array(); + $params['order_inquiry_id'] = $data['order_inquiry_id']; + $order_inquiry = OrderInquiry::getOne($params); + if (empty($order_inquiry)) { + Log::getInstance("queue-AutoFinishInquiry")->error("问诊订单数据为空"); + return Result::DROP; + } + + $order_inquiry = $order_inquiry->toArray(); + + // 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消) + if ($order_inquiry['inquiry_status'] != 5) { + Log::getInstance("queue-AutoFinishInquiry")->error("问诊订单未完成,无法结束"); + return Result::DROP; + } + + // 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常) + if (!in_array($order_inquiry['inquiry_refund_status'], [0, 4, 5])) { + Log::getInstance("queue-AutoFinishInquiry")->error("问诊订单正在申请退款"); + return Result::DROP; + } + + if (empty($order_inquiry['doctor_id'])) { + Log::getInstance("queue-AutoFinishInquiry")->error("医生id为空"); + return Result::DROP; + } + + Db::beginTransaction(); try { - // 检测入参参数 - if (empty($data['order_inquiry_id'])) { + // 检测执行次数 + $result = $this->checkExecutionCount($data['order_inquiry_id']); + if (empty($result)) { Db::rollBack(); - Log::getInstance("queue-AutoFinishInquiry")->error("错误:入参错误"); - return Result::DROP; + Log::getInstance("queue-AutoFinishInquiry")->error("检测订单执行次数错误"); + return Result::ACK; } - // 获取问诊订单数据 - $params = array(); - $params['order_inquiry_id'] = $data['order_inquiry_id']; - $order_inquiry = OrderInquiry::getOne($params); - if (empty($order_inquiry)) { + // 超出执行次数 + if ($result['code'] == 2) { Db::rollBack(); - Log::getInstance("queue-AutoFinishInquiry")->error("错误:问诊订单数据为空"); - return Result::DROP; - } - - $order_inquiry = $order_inquiry->toArray(); - - // 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消) - if ($order_inquiry['inquiry_status'] != 5) { - Db::rollBack(); - Log::getInstance("queue-AutoFinishInquiry")->error("错误:问诊订单未完成,无法结束"); - return Result::DROP; - } - - // 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常) - if (!in_array($order_inquiry['inquiry_refund_status'], [0, 4, 5])) { - Db::rollBack(); - Log::getInstance("queue-AutoFinishInquiry")->error("错误:问诊订单正在申请退款"); - return Result::DROP; - } - - if (empty($order_inquiry['doctor_id'])) { - Db::rollBack(); - Log::getInstance("queue-AutoFinishInquiry")->error("错误:医生id为空"); - return Result::DROP; + return Result::ACK; } // 处理统计问题 @@ -99,16 +116,16 @@ class AutoFinishInquiryDelayDirectConsumer extends ConsumerMessage $res = $this->handleDoctorAccount($order_inquiry); if (!$res) { Db::rollBack(); - Log::getInstance("queue-AutoFinishInquiry")->error("错误:处理医生账户总表失败"); - return Result::DROP; + Log::getInstance("queue-AutoFinishInquiry")->error("处理医生账户总表失败"); + return Result::REQUEUE; } // 处理医生账户表-日 $res = $this->handleDoctorAccountDay($order_inquiry); if (!$res) { Db::rollBack(); - Log::getInstance("queue-AutoFinishInquiry")->error("错误:处理医生账户表-日失败"); - return Result::DROP; + Log::getInstance("queue-AutoFinishInquiry")->error("处理医生账户表-日失败"); + return Result::REQUEUE; } } @@ -121,6 +138,9 @@ class AutoFinishInquiryDelayDirectConsumer extends ConsumerMessage // 处理回写患者病例-回写失败不做处理 $this->handleOrderInquiryCase($order_inquiry); + // 处理回写患者病情记录-回写失败不做处理 + $this->handlePatientPathography($order_inquiry); + // 处理医生服务患者数量 $this->handleDoctorServedPatientsNum($order_inquiry['doctor_id']); @@ -130,19 +150,29 @@ class AutoFinishInquiryDelayDirectConsumer extends ConsumerMessage // 计算医生平均响应时间 $this->computeDoctorAvgPesponseTime($order_inquiry['doctor_id']); + // 新增上报监管平台数据 + $reportRegulatoryService = new ReportRegulatoryService(); + $res = $reportRegulatoryService->addReportRegulatory($order_inquiry['order_inquiry_id']); + if (!$res) { + // 新增上报失败 + Db::rollBack(); + Log::getInstance("queue-AutoFinishInquiry")->error("新增上报监管平台数据失败"); + return Result::REQUEUE; + } + Db::commit(); Log::getInstance("queue-AutoFinishInquiry")->info("成功"); } catch (\Exception $e) { Db::rollBack(); Log::getInstance("queue-AutoFinishInquiry")->error("错误:" . $e->getMessage()); - return Result::ACK; // 重回队列 + return Result::REQUEUE; // 重回队列 } // 推送消息 try { // 推送问诊结束im消息 $this->pushImInquiryFinish($order_inquiry); - }catch (\Exception $e){ + } catch (\Exception $e) { Log::getInstance("queue-AutoFinishInquiry")->error("发送消息异常错误:" . $e->getMessage()); } @@ -254,17 +284,12 @@ class AutoFinishInquiryDelayDirectConsumer extends ConsumerMessage return true; } - // 获取用户数据 - $params = array(); - $params['patient_id'] = $order_inquiry['patient_id']; - $user_patient = UserPatient::getOne($params); - // 未评价 $data = array(); $data['doctor_id'] = $order_inquiry['doctor_id']; $data['patient_id'] = $order_inquiry['patient_id']; $data['order_inquiry_id'] = $order_inquiry['order_inquiry_id']; - $data['name_mask'] = Mask::maskNameStr($order_inquiry['patient_name'],2); + $data['name_mask'] = Mask::maskNameStr($order_inquiry['patient_name'], 2); $data['reply_quality'] = 100;//回复质量(百分制) $data['service_attitude'] = 100; // 服务态度(百分制) $data['reply_progress'] = 100; // 回复速度(百分制) @@ -284,13 +309,70 @@ class AutoFinishInquiryDelayDirectConsumer extends ConsumerMessage * @param array|object $order_inquiry * @return void */ - protected function handleOrderInquiryCase(array|object $order_inquiry): void + protected function handleOrderInquiryCase(array|object $order_inquiry): bool { - // 获取订单-问诊病例表 - $params = array(); - $params['order_inquiry_id'] = $order_inquiry['order_inquiry_id']; - $order_inquiry_case = OrderInquiryCase::getOne($params); - if (!empty($order_inquiry_case)) { + try { + // 获取订单-问诊病例表 + $params = array(); + $params['order_inquiry_id'] = $order_inquiry['order_inquiry_id']; + $order_inquiry_case = OrderInquiryCase::getOne($params); + if (empty($order_inquiry_case)) { + return false; + } + + // 获取患者家庭成员信息表-基本信息 + $params = array(); + $params['family_id'] = $order_inquiry['family_id']; + $params['patient_id'] = $order_inquiry['patient_id']; + $params['status'] = 1; + $patient_family = PatientFamily::getOne($params); + if (empty($patient_family)){ + return false; + } + + $data = array(); + + // 身高 + if ($patient_family['height'] == null && $order_inquiry_case['height'] != null){ + $data['height'] = $order_inquiry_case['height']; + } + + // 体重 + if ($patient_family['weight'] == null && $order_inquiry_case['weight'] != null){ + $data['weight'] = $order_inquiry_case['weight']; + } + + // 婚姻状况(0:未婚 1:已婚 2:离异) + if ($patient_family['marital_status'] == null && $order_inquiry_case['marital_status'] != null){ + $data['marital_status'] = $order_inquiry_case['marital_status']; + } + + // 民族 + if ($patient_family['nation_id'] == null && $order_inquiry_case['nation_id'] != null){ + $data['nation_id'] = $order_inquiry_case['nation_id']; + + // 民族名称 + if ($patient_family['nation_name'] == null && $order_inquiry_case['nation_name'] != null){ + $data['nation_name'] = $order_inquiry_case['nation_name']; + } + } + + // 职业 + if ($patient_family['job_id'] == null && $order_inquiry_case['job_id'] != null){ + $data['job_id'] = $order_inquiry_case['job_id']; + + // 职业名称 + if ($patient_family['job_name'] == null && $order_inquiry_case['job_name'] != null){ + $data['job_name'] = $order_inquiry_case['job_name']; + } + } + + if (!empty($data)) { + $params = array(); + $params['family_id'] = $patient_family['family_id']; + PatientFamily::edit($params, $data); + } + // 获取患者家庭成员信息表-健康情况 $params = array(); $params['family_id'] = $order_inquiry['family_id']; @@ -304,22 +386,44 @@ class AutoFinishInquiryDelayDirectConsumer extends ConsumerMessage $data['disease_class_id'] = $order_inquiry_case['disease_class_id']; // 疾病分类id-系统 $data['disease_class_name'] = $order_inquiry_case['disease_class_name']; // 疾病名称-系统 $data['diagnosis_date'] = $order_inquiry_case['diagnosis_date']; // 确诊日期 + $data['diagnosis_hospital'] = $order_inquiry_case['diagnosis_hospital']; // 确诊医院 + $data['is_take_medicine'] = $order_inquiry_case['is_take_medicine']; // 正在服药(0:否 1:是) + $data['drugs_name'] = $order_inquiry_case['drugs_name']; // 正在服药名称 $patient_family_health = PatientFamilyHealth::addPatientFamilyHealth($data); if (empty($patient_family_health)) { - Log::getInstance("queue-AutoFinishInquiry")->error("错误:回写患者家庭成员信息表-健康情况表失败"); + Log::getInstance("queue-AutoFinishInquiry")->error("回写患者家庭成员信息表-健康情况表失败"); } } else { $data = array(); - if ($order_inquiry_case['disease_class_id'] != $patient_family_health['disease_class_id']) { - $data['disease_class_id'] = $order_inquiry_case['disease_class_id']; // 疾病分类id-系统 + + // 疾病分类id-系统 + if ($patient_family_health['disease_class_id'] == null && $order_inquiry_case['disease_class_id'] != null) { + $data['disease_class_id'] = $order_inquiry_case['disease_class_id']; + + // 疾病名称-系统 + if ($patient_family_health['disease_class_name'] == null && $order_inquiry_case['disease_class_name'] != null) { + $data['disease_class_name'] = $order_inquiry_case['disease_class_name']; + } } - if ($order_inquiry_case['disease_class_name'] != $patient_family_health['disease_class_name']) { - $data['disease_class_name'] = $order_inquiry_case['disease_class_name']; // 疾病名称-系统 + // 确诊日期 + if ($patient_family_health['diagnosis_date'] == null && $order_inquiry_case['diagnosis_date'] != null) { + $data['diagnosis_date'] = $order_inquiry_case['diagnosis_date']; } - if ($order_inquiry_case['diagnosis_date'] != $patient_family_health['diagnosis_date']) { - $data['diagnosis_date'] = $order_inquiry_case['diagnosis_date']; // 确诊日期 + // 确诊医院 + if ($patient_family_health['diagnosis_hospital'] == null && $order_inquiry_case['diagnosis_hospital'] != null) { + $data['diagnosis_hospital'] = $order_inquiry_case['diagnosis_hospital']; + } + + // 正在服药 + if ($patient_family_health['is_take_medicine'] == null && $order_inquiry_case['is_take_medicine'] != null) { + $data['is_take_medicine'] = $order_inquiry_case['is_take_medicine']; + + // 正在服药名称 + if ($patient_family_health['drugs_name'] == null && $order_inquiry_case['drugs_name'] != null) { + $data['drugs_name'] = $order_inquiry_case['drugs_name']; + } } if (!empty($data)) { @@ -338,58 +442,103 @@ class AutoFinishInquiryDelayDirectConsumer extends ConsumerMessage $data = array(); $data['family_id'] = $order_inquiry['family_id']; $data['patient_id'] = $order_inquiry['patient_id']; + + // 是否存在过敏史(0:否 1:是) if ($order_inquiry_case['is_allergy_history'] !== null) { - $data['is_allergy_history'] = $order_inquiry_case['is_allergy_history']; // 是否存在过敏史(0:否 1:是) + $data['is_allergy_history'] = $order_inquiry_case['is_allergy_history']; + + // 过敏史描述 + if ($order_inquiry_case['allergy_history'] != null) { + $data['allergy_history'] = $order_inquiry_case['allergy_history']; + } } - if ($order_inquiry_case['allergy_history'] != null) { - $data['allergy_history'] = $order_inquiry_case['allergy_history']; // 过敏史描述 - } + // 是否存在家族病史(0:否 1:是) if ($order_inquiry_case['is_family_history'] !== null) { - $data['is_family_history'] = $order_inquiry_case['is_family_history']; // 是否存在家族病史(0:否 1:是) - } - - if ($order_inquiry_case['family_history'] != null) { - $data['family_history'] = $order_inquiry_case['family_history']; // 家族病史描述 + $data['is_family_history'] = $order_inquiry_case['is_family_history']; + + // 家族病史描述 + if ($order_inquiry_case['family_history'] != null) { + $data['family_history'] = $order_inquiry_case['family_history']; + } } + // 是否备孕、妊娠、哺乳期(0:否 1:是) if ($order_inquiry_case['is_pregnant'] !== null) { - $data['is_pregnant'] = $order_inquiry_case['is_pregnant']; // 是否备孕、妊娠、哺乳期(0:否 1:是) - } + $data['is_pregnant'] = $order_inquiry_case['is_pregnant']; - if ($order_inquiry_case['pregnant'] != null) { - $data['pregnant'] = $order_inquiry_case['pregnant']; // 是否备孕、妊娠、哺乳期(0:否 1:是) + // 是否备孕、妊娠、哺乳期(0:否 1:是) + if ($order_inquiry_case['pregnant'] != null) { + $data['pregnant'] = $order_inquiry_case['pregnant']; + } } $patient_family_personal = PatientFamilyPersonal::addPatientFamilyPersonal($data); if (empty($patient_family_personal)) { - Log::getInstance("queue-AutoFinishInquiry")->error("错误:回写患者家庭成员信息表-个人情况表失败"); + Log::getInstance("queue-AutoFinishInquiry")->error("回写患者家庭成员信息表-个人情况表失败"); } } else { $data = array(); - if ($order_inquiry_case['is_allergy_history'] !== $patient_family_personal['is_allergy_history']) { - $data['is_allergy_history'] = $order_inquiry_case['is_allergy_history']; // 是否存在过敏史(0:否 1:是) + + // 是否存在过敏史(0:否 1:是) + if ($patient_family_personal['is_allergy_history'] == null && $order_inquiry_case['is_allergy_history'] != null){ + $data['is_allergy_history'] = $order_inquiry_case['is_allergy_history']; + + // 过敏史描述 + if ($patient_family_personal['allergy_history'] == null && $order_inquiry_case['allergy_history'] != null){ + $data['allergy_history'] = $order_inquiry_case['allergy_history']; + } } - if ($order_inquiry_case['allergy_history'] != $patient_family_personal['allergy_history']) { - $data['allergy_history'] = $order_inquiry_case['allergy_history']; // 过敏史描述 + // 是否存在家族病史(0:否 1:是) + if ($patient_family_personal['is_family_history'] == null && $order_inquiry_case['is_family_history'] != null){ + $data['is_family_history'] = $order_inquiry_case['is_family_history']; + + // 家族病史描述 + if ($patient_family_personal['family_history'] == null && $order_inquiry_case['family_history'] != null){ + $data['family_history'] = $order_inquiry_case['family_history']; + } } - if ($order_inquiry_case['is_family_history'] !== $patient_family_personal['is_family_history']) { - $data['is_family_history'] = $order_inquiry_case['is_family_history']; // 是否存在家族病史(0:否 1:是) + // 是否备孕、妊娠、哺乳期(0:否 1:是) + if ($patient_family_personal['is_pregnant'] == null && $order_inquiry_case['is_pregnant'] != null){ + $data['is_pregnant'] = $order_inquiry_case['is_pregnant']; + + // 备孕、妊娠、哺乳期描述 + if ($patient_family_personal['pregnant'] == null && $order_inquiry_case['pregnant'] != null){ + $data['pregnant'] = $order_inquiry_case['pregnant']; + } } - if ($order_inquiry_case['family_history'] != $patient_family_personal['family_history']) { - $data['family_history'] = $order_inquiry_case['family_history']; // 家族病史描述 + // 是否存在手术(0:否 1:是) + if ($patient_family_personal['is_operation'] == null && $order_inquiry_case['is_operation'] != null){ + $data['is_operation'] = $order_inquiry_case['is_operation']; + + // 手术描述 + if ($patient_family_personal['operation'] == null && $order_inquiry_case['operation'] != null){ + $data['operation'] = $order_inquiry_case['operation']; + } } - if ($order_inquiry_case['is_pregnant'] !== $patient_family_personal['is_pregnant']) { - $data['is_pregnant'] = $order_inquiry_case['is_pregnant']; // 是否备孕、妊娠、哺乳期(0:否 1:是) + // 饮酒状态(1:从不 2:偶尔 3:经常 4:每天 5:已戒酒) + if ($patient_family_personal['drink_wine_status'] == null && $order_inquiry_case['drink_wine_status'] != null){ + $data['drink_wine_status'] = $order_inquiry_case['drink_wine_status']; } - if ($order_inquiry_case['pregnant'] != $patient_family_personal['pregnant']) { - $data['pregnant'] = $order_inquiry_case['pregnant']; // 是否备孕、妊娠、哺乳期(0:否 1:是) + // 吸烟状态(1:从不 2:偶尔 3:经常 4:每天 5:已戒烟) + if ($patient_family_personal['smoke_status'] == null && $order_inquiry_case['smoke_status'] != null){ + $data['smoke_status'] = $order_inquiry_case['smoke_status']; + } + + // 化合物状态(1:从不 2:偶尔 3:经常 4:每天) + if ($patient_family_personal['chemical_compound_status'] == null && $order_inquiry_case['chemical_compound_status'] != null){ + $data['chemical_compound_status'] = $order_inquiry_case['chemical_compound_status']; + + // 化合物描述 + if ($patient_family_personal['chemical_compound_describe'] == null && $order_inquiry_case['chemical_compound_describe'] != null){ + $data['chemical_compound_describe'] = $order_inquiry_case['chemical_compound_describe']; + } } if (!empty($data)) { @@ -398,6 +547,11 @@ class AutoFinishInquiryDelayDirectConsumer extends ConsumerMessage PatientFamilyPersonal::edit($params, $data); } } + + return true; + }catch (\Throwable $e){ + Log::getInstance("queue-AutoFinishInquiry")->error($e->getMessage()); + return false; } } @@ -410,7 +564,7 @@ class AutoFinishInquiryDelayDirectConsumer extends ConsumerMessage { $params = array(); $params['doctor_id'] = $doctor_id; - UserDoctor::inc($params,'served_patients_num'); + UserDoctor::inc($params, 'served_patients_num'); } /** @@ -424,7 +578,7 @@ class AutoFinishInquiryDelayDirectConsumer extends ConsumerMessage $params = array(); $params['doctor_id'] = $doctor_id; $order_evaluation_count = OrderEvaluation::getCount($params); - if ($order_evaluation_count == 0){ + if ($order_evaluation_count == 0) { return 0; } @@ -439,7 +593,7 @@ class AutoFinishInquiryDelayDirectConsumer extends ConsumerMessage $data = array(); $data['praise_rate'] = $praise_rate; - UserDoctor::editUserDoctor($params,$data); + UserDoctor::editUserDoctor($params, $data); } /** @@ -457,22 +611,22 @@ class AutoFinishInquiryDelayDirectConsumer extends ConsumerMessage $params['doctor_id'] = $doctor_id; $params['inquiry_status'] = 6; $order_inquiry = OrderInquiry::getList($params); - if (!empty($order_inquiry)){ + if (!empty($order_inquiry)) { $order_inquiry = $order_inquiry->toArray(); - foreach ($order_inquiry as $item){ - if (empty($item['reception_time'])){ + foreach ($order_inquiry as $item) { + if (empty($item['reception_time'])) { continue; } $response_time = strtotime($item['reception_time']) - strtotime($item['created_at']); - if ($response_time < 0){ + if ($response_time < 0) { // 小于0的数据不统计 continue; } $avg_response_time[] = $response_time; } - if (!empty($avg_response_time)){ + if (!empty($avg_response_time)) { $result = floor((array_sum($avg_response_time) / count($avg_response_time)) / 60 * 100) / 100; $params = array(); @@ -480,7 +634,7 @@ class AutoFinishInquiryDelayDirectConsumer extends ConsumerMessage $data = array(); $data['avg_response_time'] = $result; - UserDoctor::editUserDoctor($params,$data); + UserDoctor::editUserDoctor($params, $data); } } } @@ -496,13 +650,13 @@ class AutoFinishInquiryDelayDirectConsumer extends ConsumerMessage $is_inquiry = false; $params = array(); - $params[] = ['user_id','=',$order_inquiry['user_id']]; - $params[] = ['doctor_id','=',$order_inquiry['doctor_id']]; - $params[] = ['created_at','>',$order_inquiry['created_at']]; + $params[] = ['user_id', '=', $order_inquiry['user_id']]; + $params[] = ['doctor_id', '=', $order_inquiry['doctor_id']]; + $params[] = ['created_at', '>', $order_inquiry['created_at']]; $order_inquirys = OrderInquiry::getList($params); - if (!empty($order_inquirys)){ - foreach ($order_inquirys as $item){ - if ($item['order_inquiry_id'] == $order_inquiry['order_inquiry_id']){ + if (!empty($order_inquirys)) { + foreach ($order_inquirys as $item) { + if ($item['order_inquiry_id'] == $order_inquiry['order_inquiry_id']) { continue; } $is_inquiry = true; @@ -510,16 +664,139 @@ class AutoFinishInquiryDelayDirectConsumer extends ConsumerMessage } } - if (!$is_inquiry){ + if (!$is_inquiry) { // 获取医生数据 $params = array(); $params['doctor_id'] = $order_inquiry['doctor_id']; $user_doctor = UserDoctor::getOne($params); - if (!empty($user_doctor)){ + if (!empty($user_doctor)) { // 发送IM消息-问诊已结束 $imService = new ImService(); - $imService->inquiryFinish($order_inquiry,$user_doctor['user_id'],$order_inquiry['user_id']); + $imService->inquiryFinish($order_inquiry, $user_doctor['user_id'], $order_inquiry['user_id']); } } } + + /** + * 处理回写患者病情记录 + * 回写失败不做处理 + * @param array|object $order_inquiry + * @return bool + */ + protected function handlePatientPathography(array|object $order_inquiry): bool + { + if ($order_inquiry['inquiry_type'] != 1 && $order_inquiry['inquiry_type'] != 2 && $order_inquiry['inquiry_type'] != 3 && $order_inquiry['inquiry_type'] != 4) { + // 非问诊订单,不进行处理 + return true; + } + + // 获取患者家庭成员病情记录 + $params = array(); + $params['user_id'] = $order_inquiry['user_id']; + $params['patient_id'] = $order_inquiry['patient_id']; + $params['order_inquiry_id'] = $order_inquiry['order_inquiry_id']; + $patient_pathography = PatientPathography::getOne($params); + if (!empty($patient_pathography)) { + return false; + } + + // 获取订单-问诊病例表 + $params = array(); + $params['order_inquiry_id'] = $order_inquiry["order_inquiry_id"]; + $order_inquiry_case = OrderInquiryCase::getOne($params); + if (empty($order_inquiry_case)) { + Log::getInstance("queue-AutoFinishInquiry")->error("错误:缺少问诊病例表"); + return false; + } + + $order_inquiry_case = $order_inquiry_case->toArray(); + + $data = array(); + foreach ($order_inquiry_case as $key => $value) { + // 主键跳过 + if ($key == "inquiry_case_id") { + continue; + } + + if ($key == "created_at") { + continue; + } + + if ($key == "updated_at") { + continue; + } + + if ($value == null) { + continue; + } + + $data[$key] = $value; + } + + // 获取处方数据 + $params = array(); + $params['order_inquiry_id'] = $order_inquiry['order_inquiry_id']; + $order_prescription = OrderPrescription::getOne($params); + if (!empty($order_prescription)) { + $data['order_prescription_id'] = $order_prescription['order_prescription_id']; + } + + // 新增病情记录 + $patient_pathography = PatientPathography::addPatientPathography($data); + if (empty($patient_pathography)) { + Log::getInstance("queue-AutoFinishInquiry")->error("错误:回写病情记录失败"); + return false; + } + + return true; + } + + /** + * 检测执行次数 + * @param string $redis_key + * @return array + */ + protected function checkExecutionCount(string $redis_key): array + { + // code:0:异常 1:正常 2:超出最大执行次数 + $result = array(); + $result['code'] = 0; + $result['message'] = ""; + + try { + $redis = $this->container->get(Redis::class); + } catch (\Throwable $e) { + Log::getInstance("queue-AutoFinishInquiry")->error($e->getMessage()); + $result['message'] = $e->getMessage(); + return $result; + } + + try { + $redis_value = $redis->get($redis_key); + if (empty($redis_value)) { + $redis->set($redis_key, 1, 60 * 60 * 24 * 1); + + $result['code'] = 1; + return $result; + } + + // 执行次数超出4次 + if ($redis_value > 4) { + Log::getInstance("queue-AutoFinishInquiry")->info("超出最大执行次数"); + // 加入短信队列,通知管理员 + + $result['code'] = 2; + $result['message'] = "超出最大执行次数"; + return $result; + } + + $redis->incr($redis_key); + } catch (\Throwable $e) { + Log::getInstance("queue-AutoFinishInquiry")->error($e->getMessage()); + $result['message'] = $e->getMessage(); + return $result; + } + + return $result; + } } diff --git a/app/Amqp/Consumer/AutoPharmacistCaVerifyDelayDirectConsumer.php b/app/Amqp/Consumer/AutoPharmacistCaVerifyDelayDirectConsumer.php index 16628a3..60ee84e 100644 --- a/app/Amqp/Consumer/AutoPharmacistCaVerifyDelayDirectConsumer.php +++ b/app/Amqp/Consumer/AutoPharmacistCaVerifyDelayDirectConsumer.php @@ -31,6 +31,9 @@ use PhpAmqpLib\Message\AMQPMessage; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; +/** + * 药师审核并ca签章 + */ #[Consumer(nums: 1)] class AutoPharmacistCaVerifyDelayDirectConsumer extends ConsumerMessage { @@ -254,14 +257,6 @@ class AutoPharmacistCaVerifyDelayDirectConsumer extends ConsumerMessage // 修改处方表为通过 $this->modifyOrderPrescription($data['order_prescription_id'],1); - // 增加上报监管平台表 - $res = $this->addReportRegulatory($order_inquiry['order_inquiry_id'],$order_prescription['order_prescription_id']); - if (!$res){ - Db::rollBack(); - Log::getInstance("queue-AutoPharmacistCaVerify")->error("错误:增加监管平台上报表失败"); - return Result::REQUEUE; - } - Db::commit(); Log::getInstance("queue-AutoPharmacistCaVerify")->info("成功"); } catch (\Throwable $e) { @@ -476,31 +471,4 @@ class AutoPharmacistCaVerifyDelayDirectConsumer extends ConsumerMessage OrderPrescription::edit($params,$data); } - - /** - * 增加上报监管平台表 - * @param string $order_inquiry_id - * @param string $order_prescription_id - * @return bool - */ - protected function addReportRegulatory(string $order_inquiry_id,string $order_prescription_id): bool - { - // 检测是否已添加 - $params = array(); - $params['order_inquiry_id'] = $order_inquiry_id; - $report_regulatory = ReportRegulatory::getOne($params); - if (!empty($report_regulatory)) { - return true; - } - - $data = array(); - $data['order_inquiry_id'] = $order_inquiry_id; - $data['order_prescription_id'] = $order_prescription_id; - $report_regulatory = ReportRegulatory::addReportRegulatory($data); - if (empty($report_regulatory)){ - return false; - } - - return true; - } } diff --git a/app/Amqp/Consumer/DetectionCompleteDelayDirectConsumer.php b/app/Amqp/Consumer/DetectionCompleteDelayDirectConsumer.php index e63cae7..f3f9529 100644 --- a/app/Amqp/Consumer/DetectionCompleteDelayDirectConsumer.php +++ b/app/Amqp/Consumer/DetectionCompleteDelayDirectConsumer.php @@ -29,6 +29,10 @@ use Hyperf\DbConnection\Db; use Hyperf\Snowflake\IdGeneratorInterface; use PhpAmqpLib\Message\AMQPMessage; +/** + * 检测订单自动完成延迟队列 + * 当接收到检测报告时,如当时患者-医生存在问诊中订单,则加入此延迟队列,等待问诊结束后,检测订单才会接收 + */ #[Consumer(nums: 1)] class DetectionCompleteDelayDirectConsumer extends ConsumerMessage { diff --git a/app/Amqp/Consumer/GrantUserCouponDelayDirectConsumer.php b/app/Amqp/Consumer/GrantUserCouponDelayDirectConsumer.php index a35031c..06eee1e 100644 --- a/app/Amqp/Consumer/GrantUserCouponDelayDirectConsumer.php +++ b/app/Amqp/Consumer/GrantUserCouponDelayDirectConsumer.php @@ -16,6 +16,9 @@ use Hyperf\Amqp\Message\ConsumerMessage; use Hyperf\DbConnection\Db; use PhpAmqpLib\Message\AMQPMessage; +/** + * 再次发放用户优惠卷 + */ #[Consumer(nums: 1)] class GrantUserCouponDelayDirectConsumer extends ConsumerMessage { diff --git a/app/Amqp/Consumer/PrescriptionExpiredDelayDirectConsumer.php b/app/Amqp/Consumer/PrescriptionExpiredDelayDirectConsumer.php index 9e82838..6073657 100644 --- a/app/Amqp/Consumer/PrescriptionExpiredDelayDirectConsumer.php +++ b/app/Amqp/Consumer/PrescriptionExpiredDelayDirectConsumer.php @@ -34,14 +34,14 @@ class PrescriptionExpiredDelayDirectConsumer extends ConsumerMessage public function consumeMessage($data, AMQPMessage $message): string { - Log::getInstance()->error("开始执行 处方过期 队列:" . json_encode($data, JSON_UNESCAPED_UNICODE)); + Log::getInstance("queue-PrescriptionExpired")->info(json_encode($data, JSON_UNESCAPED_UNICODE)); Db::beginTransaction(); try { // 验证参数 if (!isset($data['order_prescription_id'])){ Db::rollBack(); - Log::getInstance()->error("处方过期队列执行失败:入参错误"); + Log::getInstance("queue-PrescriptionExpired")->error("入参错误"); return Result::DROP; } @@ -51,7 +51,7 @@ class PrescriptionExpiredDelayDirectConsumer extends ConsumerMessage $order_prescription = OrderPrescription::getOne($params); if (empty($order_prescription)){ Db::rollBack(); - Log::getInstance()->error("处方过期处方队列执行失败:获取处方数据为空"); + Log::getInstance("queue-PrescriptionExpired")->error("获取处方数据为空"); return Result::DROP; } @@ -66,11 +66,11 @@ class PrescriptionExpiredDelayDirectConsumer extends ConsumerMessage $this->handlePrescription($order_prescription); Db::commit(); - Log::getInstance()->info("处方过期 队列执行成功"); + Log::getInstance("queue-PrescriptionExpired")->info("成功"); return Result::ACK; } catch (\Exception $e) { Db::rollBack(); - Log::getInstance()->error("处方过期 执行失败:" . $e->getMessage()); + Log::getInstance("queue-PrescriptionExpired")->error($e->getMessage()); return Result::ACK; // 重回队列 } } @@ -84,13 +84,13 @@ class PrescriptionExpiredDelayDirectConsumer extends ConsumerMessage { if ($order_prescription['prescription_status'] == 3){ Db::rollBack(); - Log::getInstance()->info("处方过期 队列执行失败:处方已失效,无需处理"); + Log::getInstance("queue-PrescriptionExpired")->info("处方已失效,无需处理"); return false; } if ($order_prescription['prescription_status'] == 4){ Db::rollBack(); - Log::getInstance()->info("处方过期 队列执行失败:处方已使用,无需处理"); + Log::getInstance("queue-PrescriptionExpired")->info("处方已使用,无需处理"); return false; } return true; diff --git a/app/Amqp/Consumer/UserCouponExpiredNoticeDelayDirectConsumer.php b/app/Amqp/Consumer/UserCouponExpiredNoticeDelayDirectConsumer.php index cf23ed0..e786523 100644 --- a/app/Amqp/Consumer/UserCouponExpiredNoticeDelayDirectConsumer.php +++ b/app/Amqp/Consumer/UserCouponExpiredNoticeDelayDirectConsumer.php @@ -36,7 +36,7 @@ class UserCouponExpiredNoticeDelayDirectConsumer extends ConsumerMessage public function consumeMessage($data, AMQPMessage $message): string { - Log::getInstance("queue-UserCouponExpiredNotice")->error("开始:" . json_encode($data, JSON_UNESCAPED_UNICODE)); + Log::getInstance("queue-UserCouponExpiredNotice")->info("开始:" . json_encode($data, JSON_UNESCAPED_UNICODE)); // 检测参数 if (!isset($data['user_coupon_id'])){ diff --git a/app/Amqp/Consumer/UserImOffDelayDirectConsumer.php b/app/Amqp/Consumer/UserImOffDelayDirectConsumer.php new file mode 100644 index 0000000..0d7e309 --- /dev/null +++ b/app/Amqp/Consumer/UserImOffDelayDirectConsumer.php @@ -0,0 +1,89 @@ +info("开始:" . json_encode($data, JSON_UNESCAPED_UNICODE)); + + // 检测参数 + if (!isset($data['user_id'])){ + Log::getInstance("queue-UserImOff")->error("入参错误"); + return Result::DROP; + } + + // 获取用户数据 + $params = array(); + $params['user_id'] = $data['user_id']; + $user = User::getOne($params); + if (empty($user)){ + Log::getInstance("queue-UserImOff")->error("无该用户"); + return Result::DROP; + } + + try { + // 检测用户状态 + if ($user['is_online'] == 0){ + Log::getInstance("queue-UserImOff")->info("用户目前已下线,无需处理"); + return Result::ACK; + } + + $im_login_at = strtotime($user['im_login_at']); + + $diff_time = time() - $im_login_at; +// if ($diff_time <= (30 * 60 + 10)){ + if ($diff_time <= (2 * 50)){ + Log::getInstance("queue-UserImOff")->info("用户刚上线未满30分钟,无需处理"); + return Result::ACK; + } + + // 修改用户表在线状态 + $params = array(); + $params['user_id'] = $user['user_id']; + + $data = array(); + $data['is_online'] = 0; + $res = User::editUser($params,$data); + if (!$res){ + Log::getInstance("queue-UserImOff")->error("在线状态修改失败"); + return Result::ACK; + } + }catch (\Throwable $e){ + Log::getInstance("queue-UserImOff")->error($e->getMessage()); + return Result::DROP; + } + + Log::getInstance("queue-UserImOff")->info("结束:" . $user['user_name'] . "已下线"); + return Result::ACK; + } +} diff --git a/app/Amqp/Producer/GrantUserCouponDelayDirectProducer.php b/app/Amqp/Producer/GrantUserCouponDelayDirectProducer.php index 909738d..4ae1ac1 100644 --- a/app/Amqp/Producer/GrantUserCouponDelayDirectProducer.php +++ b/app/Amqp/Producer/GrantUserCouponDelayDirectProducer.php @@ -9,6 +9,9 @@ use Hyperf\Amqp\Message\ProducerDelayedMessageTrait; use Hyperf\Amqp\Message\ProducerMessage; use Hyperf\Amqp\Message\Type; +/** + * 再次发放用户优惠卷 + */ #[Producer] class GrantUserCouponDelayDirectProducer extends ProducerMessage { diff --git a/app/Amqp/Producer/UserImOffDelayDirectProducer.php b/app/Amqp/Producer/UserImOffDelayDirectProducer.php new file mode 100644 index 0000000..3ed77f8 --- /dev/null +++ b/app/Amqp/Producer/UserImOffDelayDirectProducer.php @@ -0,0 +1,30 @@ +payload = $data; + } +} diff --git a/app/Command/GrantUserCouponCommand.php b/app/Command/GrantUserCouponCommand.php index db4cbbc..17e5aad 100644 --- a/app/Command/GrantUserCouponCommand.php +++ b/app/Command/GrantUserCouponCommand.php @@ -43,7 +43,7 @@ class GrantUserCouponCommand extends HyperfCommand // 获取需要发放的优惠卷数据 $params = array(); - $params['coupon_id'] = 2; + $params['coupon_id'] = 3; $coupon = Coupon::getOne($params); if (empty($coupon)){ $this->line("结束:无可执行优惠卷"); diff --git a/app/Command/ReportRegulatoryCommand.php b/app/Command/ReportRegulatoryCommand.php index 0cbf353..4badcf4 100644 --- a/app/Command/ReportRegulatoryCommand.php +++ b/app/Command/ReportRegulatoryCommand.php @@ -54,44 +54,142 @@ class ReportRegulatoryCommand extends HyperfCommand } foreach ($report_regulatorys as $report_regulatory){ - // 获取处方数据 - $params = array(); - $params['order_prescription_id'] = $report_regulatory['order_prescription_id']; - $order_prescription = OrderPrescription::getOne($params); - if (empty($order_prescription)){ - // 无处方数据,不处理 - continue; - } - - // 获取问诊订单数据 - $params = array(); - $params['order_inquiry_id'] = $order_prescription['order_inquiry_id']; - $order_inquiry = OrderInquiry::getOne($params); - if (empty($order_inquiry)) { - // 无处方数据,不处理 - continue; - } - - $order_inquiry = $order_inquiry->toArray(); - - $res = $this->checkInquiryOrder($order_inquiry); - if (!$res) { - // 问诊订单数据不符合条件,不执行 - continue; - } - $this->line("开始:" . $report_regulatory['report_regulatory_id']); - // 上报问诊 - if ($report_regulatory['report_inquiry_status'] != 1){ - $this->line("信息:上报问诊"); - $this->reportRegulatoryInquiry($report_regulatory,$order_inquiry,$order_prescription); + try { + // 获取问诊订单数据 + $params = array(); + $params['order_inquiry_id'] = $report_regulatory['order_inquiry_id']; + $order_inquiry = OrderInquiry::getOne($params); + if (empty($order_inquiry)) { + // 问诊订单数据错误 + $this->line("问诊订单数据错误"); + continue; + } + + $order_inquiry = $order_inquiry->toArray(); + + // 检测问诊订单 + $res = $this->checkInquiryOrder($order_inquiry); + if (!$res) { + continue; + } + }catch (\Throwable $e){ + $this->line($e->getMessage()); + continue; + } + + // 上报网络咨询 + try { + if ($report_regulatory['report_consult_status'] != 1 && $report_regulatory['report_consult_int'] < 5){ + $this->line("上报网络咨询"); + + // 获取上报数据-网络咨询 + $consult_data = $this->getConsultData($order_inquiry); + + // 上报网络咨询 + $regulatoryPlatform = new regulatoryPlatform(); + $result = $regulatoryPlatform->uploadConsult([$consult_data]); + + $this->line("上报网络咨询成功" . json_encode($result,JSON_UNESCAPED_UNICODE)); + + // 修改上报状态-网络咨询 + $res = $this->modifyReportConsultStatus($report_regulatory, 1); + if (!$res) { + // 记录失败 + $this->line("上报成功,存储记录失败"); + } + } + }catch (\Throwable $e){ + $this->line("上报网络咨询失败" . $e->getMessage()); + + // 上报失败 + $res = $this->modifyReportConsultStatus($report_regulatory, 2, $e->getMessage()); + if (!$res) { + // 记录失败 + $this->line("上报网络咨询失败,存储记录失败"); + } + } + + + // 上报复诊 + try { + if ($report_regulatory['is_further_consult'] == 1){ + if ($report_regulatory['report_further_consult_status'] != 1 && $report_regulatory['report_further_consult_int'] < 5) { + $this->line("上报复诊"); + + // 获取处方数据 + $params = array(); + $params['order_prescription_id'] = $report_regulatory['order_prescription_id']; + $order_prescription = OrderPrescription::getOne($params); + if (empty($order_prescription)){ + $this->line("需上报复诊,但无处方数据"); + }else{ + // 获取上报数据-复诊 + $further_consult_data = $this->getFurtherConsultData($order_inquiry,$order_prescription); + + // 上报复诊 + $regulatoryPlatform = new regulatoryPlatform(); + $result = $regulatoryPlatform->uploadFurtherConsult([$further_consult_data]); + $this->line("上报复诊成功" . json_encode($result,JSON_UNESCAPED_UNICODE)); + + // 修改上报状态-复诊 + $res = $this->modifyReportFurtherConsultStatus($report_regulatory, 1); + if (!$res) { + // 记录失败 + $this->line("上报成功,存储记录失败"); + } + } + } + } + }catch (\Throwable $e){ + $this->line("上报复诊失败" . $e->getMessage()); + + // 上报失败 + $res = $this->modifyReportFurtherConsultStatus($report_regulatory, 2, $e->getMessage()); + if (!$res) { + // 记录失败 + $this->line("上报复诊失败,存储记录失败"); + } } // 上报处方 - if ($report_regulatory['report_prescription_status'] != 1){ - $this->line("信息:上报处方"); - $this->reportRegulatoryPrescription($report_regulatory,$order_inquiry,$order_prescription); + try { + $this->line("上报处方"); + + // 获取处方数据 + $params = array(); + $params['order_prescription_id'] = $report_regulatory['order_prescription_id']; + $order_prescription = OrderPrescription::getOne($params); + if (empty($order_prescription)){ + $this->line("需上报复诊,但无处方数据"); + }else{ + // 获取上报数据-处方 + $report_prescription_data = $this->getReportPrescriptionData($order_inquiry, $order_prescription); + + // 上报处方 + $regulatoryPlatform = new regulatoryPlatform(); + $result = $regulatoryPlatform->uploadRecipe([$report_prescription_data]); + + $this->line("上报处方成功" . json_encode($result,JSON_UNESCAPED_UNICODE)); + + // 上报成功 + $res = $this->modifyReportRegulatoryPrescription($report_regulatory, 1); + if (!$res) { + // 记录失败 + $this->line("上报处方失败,存储记录失败"); + } + } + }catch (\Throwable $e){ + $this->line("上报处方失败" . $e->getMessage()); + + // 上报失败 + $res = $this->modifyReportRegulatoryPrescription($report_regulatory, 2, $e->getMessage()); + if (!$res) { + // 记录失败 + $this->line("上报复诊失败,存储记录失败"); + return ; + } } $this->line("结束:" . $report_regulatory['report_regulatory_id']); @@ -106,11 +204,7 @@ class ReportRegulatoryCommand extends HyperfCommand */ private function getNotReportRegulatory(): array { - $params = array(); - $params[] = ['report_inquiry_int','<',5]; - $params[] = ['report_prescription_int','<',5]; - - $report_regulatory = ReportRegulatory::getNotReportList($params,['*']); + $report_regulatory = ReportRegulatory::getNotReportList(); if (empty($report_regulatory)){ return []; }else{ @@ -119,48 +213,13 @@ class ReportRegulatoryCommand extends HyperfCommand } /** - * 检测执行次数 - * @param string $key - * @return bool - * @throws ContainerExceptionInterface - * @throws NotFoundExceptionInterface - */ - protected function checkHandleNumber(string $key): bool - { - try { - $redis = $this->container->get(Redis::class); - - $redis_key = "ReportRegulatoryInquiry" . $key; - $redis_value = $redis->get($redis_key); - if (empty($redis_value)) { - $redis->set($redis_key, 1, 60 * 60 * 24 * 10); - return true; - } - - // 执行次数过多 - if ($redis_value > 5) { - // 加入短信队列,通知管理员 - - return false; - } - - $redis->incr($redis_key); - } catch (\Exception $e) { - return false; - } - - return true; - } - - /** - * 修改上报问诊数据 + * 修改上报状态-网络咨询 * @param array|object $report_regulatory - * @param int $report_inquiry_status 问诊上报状态(0:未上报 1:已上报 2:上报失败) - * @param int $report_inquiry_type 问诊上报类型(1:网络初诊 2:网络复诊) - * @param string $report_inquiry_fail_reason 问诊上报失败原因 + * @param int $report_consult_status 上报网络咨询状态(0:未上报 1:已上报 2:上报失败) + * @param string $report_consult_fail_reason 网络咨询上报失败原因 * @return bool */ - private function modifyReportRegulatoryInquiry(array|object $report_regulatory, int $report_inquiry_status, int $report_inquiry_type, string $report_inquiry_fail_reason = ""): bool + private function modifyReportConsultStatus(array|object $report_regulatory, int $report_consult_status,string $report_consult_fail_reason = ""): bool { try { // 修改 @@ -168,14 +227,41 @@ class ReportRegulatoryCommand extends HyperfCommand $params['report_regulatory_id'] = $report_regulatory['report_regulatory_id']; $data = array(); - $data['report_inquiry_status'] = $report_inquiry_status; - $data['report_inquiry_int'] = $report_regulatory['report_inquiry_int'] + 1; - $data['report_inquiry_type'] = $report_inquiry_type; - $data['report_inquiry_time'] = date('Y-m-d H:i:s', time()); - $data['report_inquiry_fail_reason'] = $report_inquiry_fail_reason; + $data['report_consult_status'] = $report_consult_status; + $data['report_consult_int'] = $report_regulatory['report_consult_int'] + 1; + $data['report_consult_time'] = date('Y-m-d H:i:s', time()); + $data['report_consult_fail_reason'] = $report_consult_fail_reason; ReportRegulatory::edit($params, $data); } catch (\Exception $e) { - $this->line("失败:" . $e->getMessage()); + $this->line($e->getMessage()); + return false; + } + + return true; + } + + /** + * 修改上报状态-复诊 + * @param array|object $report_regulatory + * @param int $report_further_consult_status 上报网络复诊状态(0:未上报 1:已上报 2:上报失败) + * @param string $report_further_consult_fail_reason 网络复诊上报失败原因 + * @return bool + */ + private function modifyReportFurtherConsultStatus(array|object $report_regulatory, int $report_further_consult_status,string $report_further_consult_fail_reason = ""): bool + { + try { + // 修改 + $params = array(); + $params['report_regulatory_id'] = $report_regulatory['report_regulatory_id']; + + $data = array(); + $data['report_further_consult_status'] = $report_further_consult_status; + $data['report_further_consult_int'] = $report_regulatory['report_further_consult_int'] + 1; + $data['report_further_consult_time'] = date('Y-m-d H:i:s', time()); + $data['report_further_consult_fail_reason'] = $report_further_consult_fail_reason; + ReportRegulatory::edit($params, $data); + } catch (\Exception $e) { + $this->line($e->getMessage()); return false; } @@ -228,7 +314,7 @@ class ReportRegulatoryCommand extends HyperfCommand // 已取消状态,查看是否完成后取消的 if ($order_inquiry['inquiry_status'] == 7 && $order_inquiry['cancel_reason'] != 4 && empty($order_inquiry['complete_time'])) { - $this->line("信息:订单为取消的未完成订单,不执行"); + $this->line("信息:订单未取消的未完成订单,不执行"); return false; } @@ -236,291 +322,7 @@ class ReportRegulatoryCommand extends HyperfCommand } /** - * 检测患者是否首次问诊-是否开具过处方 - * @param string $patient_id - * @param string $order_prescription_id - * @return bool true:首次 false:复诊 - */ - private function checkPatientFirstInquiry(string $patient_id, string $order_prescription_id): bool - { - $params = array(); - $params['patient_id'] = $patient_id; - $params['pharmacist_audit_status'] = 1; - - $prescription_status_params = [2, 3, 4]; - $order_prescriptions = OrderPrescription::getStatusList($params, $prescription_status_params); - if (empty($order_prescriptions)) { - return true; - } - - foreach ($order_prescriptions as $item) { - if ($item['order_prescription_id'] == $order_prescription_id) { - continue; - } - - // 开具过处方 - return false; - } - - return true; - } - - /** - * 获取上报监管数据-问诊 - * @param array|object $order_inquiry - * @param array|object $order_prescription - * @param bool $is_first 是否首次问诊 true:是 1:否 - * @return bool|array - */ - private function getReportInquiryData(array|object $order_inquiry, array|object $order_prescription, bool $is_first = true): bool|array - { - // 获取医生数据 - $params = array(); - $params['doctor_id'] = $order_inquiry['doctor_id']; - $user_doctor = UserDoctor::getOne($params); - if (empty($user_doctor)) { - $this->line("错误:医生数据错误"); - return false; - } - - $params = array(); - $params['doctor_id'] = $order_inquiry['doctor_id']; - $user_doctor_info = UserDoctorInfo::getOne($params); - if (empty($user_doctor_info)) { - $this->line("错误:医生详情数据错误"); - return false; - } - - // 获取医生自定义科室数据 - $params = array(); - $params['department_custom_id'] = $user_doctor['department_custom_id']; - $hospital_department_custom = HospitalDepartmentCustom::getOne($params); - if (empty($hospital_department_custom)) { - $this->line("错误:医生自定义数据错误"); - return false; - } - - // 获取问诊患者数据 - $params = array(); - $params['family_id'] = $order_inquiry['family_id']; - $patient_family = PatientFamily::getOne($params); - if (empty($patient_family)) { - $this->line("错误:问诊患者数据错误"); - return false; - } - - // 获取患者问诊病例 - $params = array(); - $params['order_inquiry_id'] = $order_inquiry['order_inquiry_id']; - $params['status'] = 1; - $order_inquiry_case = OrderInquiryCase::getOne($params); - if (empty($order_inquiry_case)) { - $this->line("错误:患者问诊病例错误"); - return false; - } - - if ($is_first) { - $this->line("信息:患者首次问诊"); - // 初诊 - // 网络咨询(网络门诊)服务 - $data = array(); - $data['thirdUniqueid'] = $order_inquiry['order_inquiry_id']; // 唯一标识 - $data['orgName'] = "成都金牛欣欣相照互联网医院"; // 机构名称 - $data['orgCode'] = "MA6CGUDA251010619D2112"; // 机构编码 - $data['channelName'] = "成都金牛欣欣相照互联网医院";//平台名称 - $data['section'] = $hospital_department_custom['department_name'];//科室名称 - $data['sectionCode'] = $hospital_department_custom['department_code'];//科室编码 - $data['docName'] = $user_doctor['user_name'];// 姓名(医师、护师、技师) - $data['certificateNum'] = $user_doctor_info['qualification_cert_num']; // 执业资格证号 - $data['patientName'] = $order_inquiry['patient_name']; // 患者姓名 - $data['patientAge'] = (int)$order_inquiry['patient_age']; // 患者年龄 - $data['patientSex'] = $order_inquiry['patient_sex'] == 0 ?: 1; // 患者性别 - $data['patientIdcardType'] = 1; // 证件类型 - $data['patientIdcardNum'] = $patient_family['id_number']; // 患者证件号码 - $data['serviceType'] = 1; // 服务类型 1网络咨询 2网络门诊 - $data['consultNo'] = $order_inquiry['inquiry_no']; // 网络咨询或网络门诊编号 订单编号 - $data['consultType'] = 1; // 咨询类别 1、图文咨询 2语音咨询3、视频咨询 - $data['consultApplyTime'] = date('Y-m-d H:i:s',strtotime($order_inquiry['created_at'])); // 咨询申请时间 - $data['consultStartTime'] = date('Y-m-d H:i:s',strtotime($order_inquiry['reception_time'])); // 咨询开始时间 - $data['consultEndTime'] = date('Y-m-d H:i:s',strtotime($order_inquiry['complete_time'])); // 咨询结束时间 - $data['feeType'] = 1; // 费别 1自费 2医保 - $data['price'] = $order_inquiry['payment_amount_total']; // 咨询价格 元 - $data['isReply'] = 1; //咨询是否回复 0未回复 1已回复 - $data['patientEvaluate'] = 1; //患者满意度 1-5 1代表非常满意 5代表非常不满意 - $data['complainInfo'] = "无"; //投诉举报信息 - $data['disposeResult'] = "无"; //处理结果信息 - $data['isRiskWarn'] = 1; //是否进行诊前风险提示 0否 1是 - $data['isPatientSign'] = 1; //是否确认患者为签约对象 0否 1是 - $data['uploadTime'] = date('Y-m-d H:i:s', time()); //上传时间 - $data['medicalHistory'] = $order_inquiry_case['disease_desc']; //患者病史描述 - $data['docAdvice'] = $order_prescription['doctor_advice'] ?? "无"; // 医生建议描述 医嘱 - $data['cityId'] = "510100"; // 城市ID(参考地区字段) - $data['isMark'] = 1;//是否留痕 1:代表留痕;0代表未留痕 - } else { - $this->line("信息:患者复诊"); - // 获取患者首次问诊病例数据 - $params = array(); - $params['patient_id'] = $order_inquiry['patient_id']; - $params['pharmacist_audit_status'] = 1; - - $prescription_status_params = [2, 3, 4]; - $first_order_prescription = OrderPrescription::getStatusOne($params, $prescription_status_params); - if (empty($first_order_prescription)) { - // 复诊,但是未找到复诊处方单 - $this->line("错误:无初诊处方单"); - return false; - } - - $first_order_prescription = $first_order_prescription->toArray(); - - // 获取患者初诊疾病诊断数据 - $params = array(); - $params['order_prescription_id'] = $first_order_prescription['order_prescription_id']; - $first_order_prescription_icd = OrderPrescriptionIcd::getList($params); - if (empty($first_order_prescription_icd)) { - // 复诊,但是未找到关联疾病 - $this->line("错误:无初诊疾病诊断数据"); - return false; - } - - $first_icd_name_data = array_column($first_order_prescription_icd->toArray(), 'icd_name'); - if (empty($first_icd_name_data)){ - // 复诊,但是未找到关联疾病 - $this->line("错误:无初诊疾病诊断数据"); - return false; - } - - if (count($first_icd_name_data) > 1) { - $first_icd_name = implode('|', $first_icd_name_data); - } else { - $first_icd_name = $first_icd_name_data[0]; - } - - // 获取患者复诊疾病诊断数据 - $params = array(); - $params['order_prescription_id'] = $order_prescription['order_prescription_id']; - $order_prescription_icd = OrderPrescriptionIcd::getList($params); - if (empty($order_prescription_icd)) { - // 复诊,但是未找到关联疾病 - $this->line("错误:无复诊疾病诊断数据"); - return false; - } - - $icd_name_data = array_column($order_prescription_icd->toArray(), 'icd_name'); - if (!empty($icd_name_data)) { - if (count($icd_name_data) > 1) { - $icd_name = implode('|', $icd_name_data); - } else { - $icd_name = $icd_name_data[0]; - } - } - - // icd编码 - $icd_code_data = array_column($order_prescription_icd->toArray(), 'icd_code'); - if (!empty($icd_code_data)) { - if (count($icd_code_data) > 1) { - $icd_code = implode('|', $icd_code_data); - } else { - $icd_code = $icd_code_data[0]; - } - } - - // 网络复诊服务 - $data = array(); - $data['thirdUniqueid'] = $order_inquiry['order_inquiry_id']; // 唯一标识 - $data['orgName'] = "成都金牛欣欣相照互联网医院"; // 机构名称 - $data['orgCode'] = "MA6CGUDA251010619D2112"; // 机构编码 - $data['channelName'] = "成都金牛欣欣相照互联网医院";//平台名称 - $data['section'] = $hospital_department_custom['department_name'];//科室名称 - $data['sectionCode'] = $hospital_department_custom['department_code'];//科室编码 - $data['docName'] = $user_doctor['user_name'];// 复诊医师姓名 - $data['certificateNum'] = $user_doctor_info['qualification_cert_num']; // 执业资格证号 - $data['patientName'] = $order_inquiry['patient_name']; // 患者姓名 - $data['patientAge'] = (int)$order_inquiry['patient_age']; // 患者年龄 - $data['patientSex'] = $order_inquiry['patient_sex'] == 0 ?: 1; // 患者性别 - $data['patientIdcardType'] = 1; // 证件类型 - $data['patientIdcardNum'] = $patient_family['id_number']; // 患者证件号码 - $data['furtherConsultNo'] = $order_inquiry['order_inquiry_id']; // 网络复诊编号 - $data['furtherConsulType'] = "1"; // 复诊类别 1、图文诊疗 2、语音诊疗 3、视频诊疗 - $data['medicalHistory'] = $order_inquiry_case['disease_desc']; //患者病史描述 - $data['consultDiagnosisType'] = 1; // 首诊诊断类型 - $data['consultDiagnosis'] = $first_icd_name; // 首诊诊断 复诊患者在首诊医院的诊断,如有多条,使用“|”进行分隔;当传图片时,需要传图片的base64字符串 - $data['consultTime'] = date('Y-m-d H:i:s',strtotime($first_order_prescription['doctor_created_time'])); // 首诊时间 - $data['consultOrg'] = "成都金牛欣欣相照互联网医院"; // 首诊机构 - $data['furtherConsultApplyTime'] = date('Y-m-d H:i:s',strtotime($order_inquiry['created_at'])); // 复诊申请时间 - $data['furtherConsulStartTime'] = date('Y-m-d H:i:s',strtotime($order_inquiry['reception_time'])); // 复诊开始时间 - $data['furtherConsulEndTime'] = date('Y-m-d H:i:s',strtotime($order_inquiry['complete_time'])); // 复诊结束时间 - $data['furtherConsulIsReply'] = 1; // 复诊是否回复 0未回复 1已回复 - $data['feeType'] = 1; // 费别 1自费 2医保 - $data['furtherConsultDiagnosis'] = $icd_name; // 复诊诊断 复诊患者在实体医院的诊断名称,如有多条,使用“|”进行分隔 - $data['furtherConsultDiagnosisNo'] = $icd_code; // 复诊icd诊断编码 - $data['furtherConsultPrice'] = $order_inquiry['payment_amount_total']; // 复诊价格 - $data['patientEvaluate'] = 1; // 患者满意度 1-5 1代表非常满意 5代表非常不满意 - $data['complainInfo'] = "无"; // 投诉举报信息 - $data['disposeResult'] = "无"; // 处理结果信息 - $data['isRiskWarn'] = 1; // 是否进行诊前风险提示 0否 1是 - $data['isPatientSign'] = 1; // 是否确认患者为签约对象 0否 1是 - $data['isPrescription'] = 1; // 是否开具处方 0否 1是 - $data['uploadTime'] = date('Y-m-d H:i:s', time()); // 上传时间 - $data['cityId'] = "510100"; // 城市ID(参考地区字段) - $data['isMark'] = 1;//是否留痕 1:代表留痕;0代表未留痕 - } - return $data; - } - - /** - * 上报问诊 - * @param array|object $report_regulatory - * @param array|object $order_inquiry - * @param array|object $order_prescription - * @throws ContainerExceptionInterface - * @throws NotFoundExceptionInterface - */ - private function reportRegulatoryInquiry(array|object $report_regulatory,array|object $order_inquiry,array|object $order_prescription): void - { - if($report_regulatory['report_inquiry_int'] >= 5){ - $this->line("错误:超出最大执行次数,本条不执行"); - return ; - } - - // 检测患者是否首次问诊 - $is_first = $this->checkPatientFirstInquiry($order_prescription['patient_id'], $order_prescription['order_prescription_id']); - - try { - // 获取上报监管数据-问诊 - $report_inquiry_data = $this->getReportInquiryData($order_inquiry, $order_prescription, $is_first); - - // 上报监管平台-问诊 - $regulatoryPlatform = new regulatoryPlatform(); - if ($is_first) { - $result = $regulatoryPlatform->uploadConsult([$report_inquiry_data]); - } else { - $result = $regulatoryPlatform->uploadFurtherConsult([$report_inquiry_data]); - } - - $this->line("信息:上报成功" . json_encode($result,JSON_UNESCAPED_UNICODE)); - - // 上报成功 - $res = $this->modifyReportRegulatoryInquiry($report_regulatory, 1, $is_first ? 1 : 2); - if (!$res) { - // 记录失败 - $this->line("错误:上报成功,存储记录失败"); - return; - } - } catch (\Exception $e) { - $this->line("错误:" . $e->getMessage()); - // 上报失败 - $res = $this->modifyReportRegulatoryInquiry($report_regulatory, 2, $is_first ? 1 : 2, $e->getMessage()); - if (!$res) { - // 记录失败 - $this->line("错误:上报失败,存储记录失败"); - return; - } - } - } - - /** - * 获取上报监管数据-处方 + * 获取上报数据-处方 * @param array|object $order_inquiry * @param array|object $order_prescription * @return bool|array @@ -659,51 +461,6 @@ class ReportRegulatoryCommand extends HyperfCommand return $data; } - /** - * 上报处方 - * @param array|object $report_regulatory - * @param array|object $order_inquiry - * @param array|object $order_prescription - * @return void - * @throws ContainerExceptionInterface - * @throws NotFoundExceptionInterface - */ - private function reportRegulatoryPrescription(array|object $report_regulatory,array|object $order_inquiry,array|object $order_prescription): void - { - if ($report_regulatory['report_prescription_int'] >= 5){ - // 修改为上报失败 - $this->line("错误:超出最大执行次数,本条不执行"); - return ; - } - - try { - // 获取上报监管数据-处方 - $report_prescription_data = $this->getReportPrescriptionData($order_inquiry, $order_prescription); - - // 上报监管平台-处方 - $regulatoryPlatform = new regulatoryPlatform(); - $result = $regulatoryPlatform->uploadRecipe([$report_prescription_data]); - $this->line("信息:上报成功" . json_encode($result,JSON_UNESCAPED_UNICODE)); - - // 上报成功 - $res = $this->modifyReportRegulatoryPrescription($report_regulatory, 1); - if (!$res) { - // 记录失败 - $this->line("错误:上报成功,存储记录失败"); - return ; - } - }catch (\Exception $e){ - $this->line("错误:" . $e->getMessage()); - // 上报失败 - $res = $this->modifyReportRegulatoryPrescription($report_regulatory, 2, $e->getMessage()); - if (!$res) { - // 记录失败 - $this->line("错误:上报失败,存储记录失败"); - return ; - } - } - } - /** * 获取处方商品数据 * @param string $order_prescription_id @@ -778,4 +535,224 @@ class ReportRegulatoryCommand extends HyperfCommand return $result; } + + /** + * 获取上报数据-网络咨询 + * @param array|object $order_inquiry + * @return array + */ + private function getConsultData(array|object $order_inquiry): array + { + // 获取医生数据 + $params = array(); + $params['doctor_id'] = $order_inquiry['doctor_id']; + $user_doctor = UserDoctor::getOne($params); + if (empty($user_doctor)) { + $this->line("错误:医生数据错误"); + return []; + } + + $params = array(); + $params['doctor_id'] = $order_inquiry['doctor_id']; + $user_doctor_info = UserDoctorInfo::getOne($params); + if (empty($user_doctor_info)) { + $this->line("错误:医生详情数据错误"); + return []; + } + + // 获取医生自定义科室数据 + $params = array(); + $params['department_custom_id'] = $user_doctor['department_custom_id']; + $hospital_department_custom = HospitalDepartmentCustom::getOne($params); + if (empty($hospital_department_custom)) { + $this->line("错误:医生自定义数据错误"); + return []; + } + + // 获取问诊患者数据 + $params = array(); + $params['family_id'] = $order_inquiry['family_id']; + $patient_family = PatientFamily::getOne($params); + if (empty($patient_family)) { + $this->line("错误:问诊患者数据错误"); + return []; + } + + // 获取患者问诊病例 + $params = array(); + $params['order_inquiry_id'] = $order_inquiry['order_inquiry_id']; + $params['status'] = 1; + $order_inquiry_case = OrderInquiryCase::getOne($params); + if (empty($order_inquiry_case)) { + $this->line("错误:患者问诊病例错误"); + return []; + } + + // 网络咨询(网络门诊)服务 + $data = array(); + $data['thirdUniqueid'] = $order_inquiry['order_inquiry_id']; // 唯一标识 + $data['orgName'] = "成都金牛欣欣相照互联网医院"; // 机构名称 + $data['orgCode'] = "MA6CGUDA251010619D2112"; // 机构编码 + $data['channelName'] = "成都金牛欣欣相照互联网医院";//平台名称 + $data['section'] = $hospital_department_custom['department_name'];//科室名称 + $data['sectionCode'] = $hospital_department_custom['department_code'];//科室编码 + $data['docName'] = $user_doctor['user_name'];// 姓名(医师、护师、技师) + $data['certificateNum'] = $user_doctor_info['qualification_cert_num']; // 执业资格证号 + $data['patientName'] = $order_inquiry['patient_name']; // 患者姓名 + $data['patientAge'] = (int)$order_inquiry['patient_age']; // 患者年龄 + $data['patientSex'] = $order_inquiry['patient_sex'] == 0 ?: 1; // 患者性别 + $data['patientIdcardType'] = 1; // 证件类型 + $data['patientIdcardNum'] = $patient_family['id_number']; // 患者证件号码 + $data['serviceType'] = 1; // 服务类型 1网络咨询 2网络门诊 + $data['consultNo'] = $order_inquiry['inquiry_no']; // 网络咨询或网络门诊编号 订单编号 + $data['consultType'] = 1; // 咨询类别 1、图文咨询 2语音咨询3、视频咨询 + $data['consultApplyTime'] = date('Y-m-d H:i:s',strtotime($order_inquiry['created_at'])); // 咨询申请时间 + $data['consultStartTime'] = date('Y-m-d H:i:s',strtotime($order_inquiry['reception_time'])); // 咨询开始时间 + $data['consultEndTime'] = date('Y-m-d H:i:s',strtotime($order_inquiry['complete_time'])); // 咨询结束时间 + $data['feeType'] = 1; // 费别 1自费 2医保 + $data['price'] = $order_inquiry['payment_amount_total']; // 咨询价格 元 + $data['isReply'] = 1; //咨询是否回复 0未回复 1已回复 + $data['patientEvaluate'] = 1; //患者满意度 1-5 1代表非常满意 5代表非常不满意 + $data['complainInfo'] = "无"; //投诉举报信息 + $data['disposeResult'] = "无"; //处理结果信息 + $data['isRiskWarn'] = 1; //是否进行诊前风险提示 0否 1是 + $data['isPatientSign'] = 1; //是否确认患者为签约对象 0否 1是 + $data['uploadTime'] = date('Y-m-d H:i:s', time()); //上传时间 + $data['medicalHistory'] = $order_inquiry_case['disease_desc']; //患者病史描述 + $data['docAdvice'] = $order_prescription['doctor_advice'] ?? "无"; // 医生建议描述 医嘱 + $data['cityId'] = "510100"; // 城市ID(参考地区字段) + $data['isMark'] = 1;//是否留痕 1:代表留痕;0代表未留痕 + + return $data; + } + + /** + * 获取上报数据-复诊 + * @param array|object $order_inquiry + * @param array|object $order_prescription + * @return array + */ + private function getFurtherConsultData(array|object $order_inquiry,array|object $order_prescription): array + { + // 获取医生数据 + $params = array(); + $params['doctor_id'] = $order_inquiry['doctor_id']; + $user_doctor = UserDoctor::getOne($params); + if (empty($user_doctor)) { + $this->line("医生数据错误"); + return []; + } + + $params = array(); + $params['doctor_id'] = $order_inquiry['doctor_id']; + $user_doctor_info = UserDoctorInfo::getOne($params); + if (empty($user_doctor_info)) { + $this->line("医生详情数据错误"); + return []; + } + + // 获取医生自定义科室数据 + $params = array(); + $params['department_custom_id'] = $user_doctor['department_custom_id']; + $hospital_department_custom = HospitalDepartmentCustom::getOne($params); + if (empty($hospital_department_custom)) { + $this->line("医生自定义数据错误"); + return []; + } + + // 获取问诊患者数据 + $params = array(); + $params['family_id'] = $order_inquiry['family_id']; + $patient_family = PatientFamily::getOne($params); + if (empty($patient_family)) { + $this->line("问诊患者数据错误"); + return []; + } + + // 获取患者问诊病例 + $params = array(); + $params['order_inquiry_id'] = $order_inquiry['order_inquiry_id']; + $params['status'] = 1; + $order_inquiry_case = OrderInquiryCase::getOne($params); + if (empty($order_inquiry_case)) { + $this->line("患者问诊病例错误"); + return []; + } + + // 获取患者复诊疾病诊断数据 + $params = array(); + $params['order_prescription_id'] = $order_prescription['order_prescription_id']; + $order_prescription_icd = OrderPrescriptionIcd::getList($params); + if (empty($order_prescription_icd)) { + // 复诊,但是未找到关联疾病 + $this->line("无复诊疾病诊断数据"); + return []; + } + + $icd_name_data = array_column($order_prescription_icd->toArray(), 'icd_name'); + if (count($icd_name_data) > 1) { + $icd_name = implode('|', $icd_name_data); + } else { + $icd_name = $icd_name_data[0]; + } + + if (empty($icd_name)){ + $this->line("无疾病名称数据"); + return []; + } + + $icd_code_data = array_column($order_prescription_icd->toArray(), 'icd_code'); + if (count($icd_code_data) > 1) { + $icd_code = implode('|', $icd_code_data); + } else { + $icd_code = $icd_code_data[0]; + } + + if (empty($icd_code)){ + $this->line("无icd编码数据"); + return []; + } + + // 网络复诊服务 + $data = array(); + $data['thirdUniqueid'] = $order_inquiry['order_inquiry_id']; // 唯一标识 + $data['orgName'] = "成都金牛欣欣相照互联网医院"; // 机构名称 + $data['orgCode'] = "MA6CGUDA251010619D2112"; // 机构编码 + $data['channelName'] = "成都金牛欣欣相照互联网医院";//平台名称 + $data['section'] = $hospital_department_custom['department_name'];//科室名称 + $data['sectionCode'] = $hospital_department_custom['department_code'];//科室编码 + $data['docName'] = $user_doctor['user_name'];// 复诊医师姓名 + $data['certificateNum'] = $user_doctor_info['qualification_cert_num']; // 执业资格证号 + $data['patientName'] = $order_inquiry['patient_name']; // 患者姓名 + $data['patientAge'] = (int)$order_inquiry['patient_age']; // 患者年龄 + $data['patientSex'] = $order_inquiry['patient_sex'] == 0 ?: 1; // 患者性别 + $data['patientIdcardType'] = 1; // 证件类型 + $data['patientIdcardNum'] = $patient_family['id_number']; // 患者证件号码 + $data['furtherConsultNo'] = $order_inquiry['order_inquiry_id']; // 网络复诊编号 + $data['furtherConsulType'] = "1"; // 复诊类别 1、图文诊疗 2、语音诊疗 3、视频诊疗 + $data['medicalHistory'] = $order_inquiry_case['disease_desc']; //患者病史描述 + $data['consultDiagnosisType'] = 1; // 首诊诊断类型 + $data['consultDiagnosis'] = $order_inquiry_case['disease_class_name']; // 首诊诊断 复诊患者在首诊医院的诊断,如有多条,使用“|”进行分隔;当传图片时,需要传图片的base64字符串 + $data['consultTime'] = date('Y-m-d H:i:s',strtotime($order_inquiry_case['diagnosis_date'])); // 首诊时间(使用确诊时间) + $data['consultOrg'] = "成都金牛欣欣相照互联网医院"; // 首诊机构 + $data['furtherConsultApplyTime'] = date('Y-m-d H:i:s',strtotime($order_inquiry['created_at'])); // 复诊申请时间 + $data['furtherConsulStartTime'] = date('Y-m-d H:i:s',strtotime($order_inquiry['reception_time'])); // 复诊开始时间 + $data['furtherConsulEndTime'] = date('Y-m-d H:i:s',strtotime($order_inquiry['complete_time'])); // 复诊结束时间 + $data['furtherConsulIsReply'] = 1; // 复诊是否回复 0未回复 1已回复 + $data['feeType'] = 1; // 费别 1:自费 2:医保 + $data['furtherConsultDiagnosis'] = $icd_name; // 复诊诊断 复诊患者在实体医院的诊断名称,如有多条,使用“|”进行分隔 + $data['furtherConsultDiagnosisNo'] = $icd_code; // 复诊icd诊断编码 + $data['furtherConsultPrice'] = $order_inquiry['payment_amount_total']; // 复诊价格 + $data['patientEvaluate'] = 1; // 患者满意度 1-5 1:代表非常满意 5:代表非常不满意 + $data['complainInfo'] = "无"; // 投诉举报信息 + $data['disposeResult'] = "无"; // 处理结果信息 + $data['isRiskWarn'] = 1; // 是否进行诊前风险提示 0否 1是 + $data['isPatientSign'] = 1; // 是否确认患者为签约对象 0否 1是 + $data['isPrescription'] = 1; // 是否开具处方 0否 1是 + $data['uploadTime'] = date('Y-m-d H:i:s', time()); // 上传时间 + $data['cityId'] = "510100"; // 城市ID(参考地区字段) + $data['isMark'] = 1;//是否留痕 1:代表留痕;0:代表未留痕 + + return $data; + } } diff --git a/app/Command/getCaCertCommand.php b/app/Command/getCaCertCommand.php deleted file mode 100644 index 143b539..0000000 --- a/app/Command/getCaCertCommand.php +++ /dev/null @@ -1,193 +0,0 @@ -setDescription('Ca证书申请'); - } - - public function handle() - { - $this->line('开始'); - - // 获取全部医生 - $params = array(); - $params['status'] = 1; - $params['idcard_status'] = 1; - $params['iden_auth_status'] = 1; - $user_doctors = UserDoctor::getList($params); - if (empty($user_doctors)){ - $this->line('结束,无医生需处理'); - return; - } - - // 获取医院数据 - $params = array(); - $params['is_system'] = 1; - $params['type'] = 2; - $user_ca_cert = UserCaCert::getOne($params); - if (empty($user_ca_cert)){ - $CaOnline = new CaOnline(); - - // 申请医院证书 - $data = array(); - $data['user_id'] = "5345345461"; - $data['mobile'] = "18601047315"; - $data['org_name'] = "成都金牛欣欣相照互联网医院有限公司"; - $data['org_number'] = "91510106MABTJY4K9R"; - - $result = $CaOnline->getCloudCert($data,'Organizational'); - - $data = array(); - $data['is_system'] = 1; - $data['type'] = 2; - $data['cert_base64'] = $result['certBase64']; - $data['cert_chain_p7'] = $result['certP7']; - $data['cert_serial_number'] = $result['certSerialnumber']; - $data['ca_pin'] = "5345345461"; - $doctor_pharmacist_cert = UserCaCert::addUserCaCert($data); - if (empty($doctor_pharmacist_cert)){ - $this->line('错误:医院证书错误'); - return; - } - } - - foreach ($user_doctors as $user_doctor){ - try { - // 获取医生ca证书数据 - $params = array(); - $params['user_id'] = $user_doctor['user_id']; - $user_ca_cert = UserCaCert::getOne($params); - if (!empty($user_ca_cert)){ - continue; - } - - // 获取用户数据 - $params = array(); - $params['user_id'] = $user_doctor['user_id']; - $user = User::getOne($params); - if (empty($user)){ - continue; - } - - $params = array(); - $params['user_id'] = $user_doctor['user_id']; - $user_doctor_info = UserDoctorInfo::getOne($params); - if (empty($user_doctor_info)){ - continue; - } - - $CaOnline = new CaOnline(); - - $data = array(); - $data['user_id'] = $user_doctor['user_id']; - $data['mobile'] = $user['mobile']; - $data['card_name'] = $user_doctor_info['card_name']; - $data['card_num'] = $user_doctor_info['card_num']; - $data['orgDept'] = $user_doctor['department_custom_name']; - $result = $CaOnline->getCloudCert($data); - - $data = array(); - $data['user_id'] = $user_doctor['user_id']; - $data['type'] = 2; - $data['cert_base64'] = $result['certBase64']; - $data['cert_chain_p7'] = $result['certP7']; - $data['cert_serial_number'] = $result['certSerialnumber']; - $data['ca_pin'] = $user_doctor['user_id']; - $doctor_pharmacist_cert = UserCaCert::addUserCaCert($data); - if (empty($doctor_pharmacist_cert)){ - $this->line('错误'); - return; - } - - $this->line('成功'); - }catch (\Exception $e){ - $this->line('错误:' . $e->getMessage()); - continue; - } - } - - // 获取药师数据 - $params = array(); - $params['status'] = 1; - $params['is_online'] = 1; - $user_pharmacist = UserPharmacist::getOne($params); - if (empty($user_pharmacist)){ - $this->line('结束,无药师需处理'); - return; - } - - // 获取医生ca证书数据 - $params = array(); - $params['user_id'] = $user_pharmacist['user_id']; - $user_ca_cert = UserCaCert::getOne($params); - if (!empty($user_ca_cert)){ - $this->line('结束,无药师需处理'); - return; - } - - // 获取用户数据 - $params = array(); - $params['user_id'] = $user_pharmacist['user_id']; - $user = User::getOne($params); - if (empty($user)){ - $this->line('结束,药师用户数据错误'); - return; - } - - $params = array(); - $params['user_id'] = $user_pharmacist['user_id']; - $user_pharmacist_info = UserPharmacistInfo::getOne($params); - if (empty($user_pharmacist_info)){ - $this->line('结束,无药师需处理'); - return; - } - - $CaOnline = new CaOnline(); - - $data = array(); - $data['user_id'] = $user_pharmacist_info['user_id']; - $data['mobile'] = $user['mobile']; - $data['card_name'] = $user_pharmacist_info['card_name']; - $data['card_num'] = $user_pharmacist_info['card_num']; - $result = $CaOnline->getCloudCert($data); - - $data = array(); - $data['user_id'] = $user_pharmacist_info['user_id']; - $data['type'] = 2; - $data['cert_base64'] = $result['certBase64']; - $data['cert_chain_p7'] = $result['certP7']; - $data['cert_serial_number'] = $result['certSerialnumber']; - $data['ca_pin'] = $user_pharmacist_info['user_id']; - $doctor_pharmacist_cert = UserCaCert::addUserCaCert($data); - if (empty($doctor_pharmacist_cert)){ - $this->line('错误'); - return; - } - - $this->line('全部结束'); - } -} diff --git a/app/Controller/CallBackController.php b/app/Controller/CallBackController.php index 9ba819c..10a06cf 100644 --- a/app/Controller/CallBackController.php +++ b/app/Controller/CallBackController.php @@ -77,14 +77,12 @@ class CallBackController extends AbstractController $app = $WechatPay->createApp(); $server = $app->getServer(); - $message = $server->getRequestMessage(); + // 获取解密消息 + $message = $server->getDecryptedMessage(); if (empty($message)) { return $this->response->withStatus(500)->withBody(new SwooleStream(strval(json_encode(['code' => 'ERROR', 'message' => "问诊微信支付回调数据为空"], JSON_UNESCAPED_UNICODE)))); } - // 验证推送消息签名 - $app->getValidator()->validate($app->getRequest()); - Log::getInstance()->info("问诊微信支付回调数据:" . json_encode($message->toArray(), JSON_UNESCAPED_UNICODE)); if (empty($message['out_trade_no'])) { @@ -245,15 +243,13 @@ class CallBackController extends AbstractController $app = $WechatPay->createApp(); $server = $app->getServer(); - $message = $server->getRequestMessage(); + // 获取解密消息 + $message = $server->getDecryptedMessage(); if (empty($message)) { Db::rollBack(); return $this->response->withStatus(500)->withBody(new SwooleStream(strval(json_encode(['code' => 'ERROR', 'message' => "回调数据为空"], JSON_UNESCAPED_UNICODE)))); } - // 验证推送消息签名 - $app->getValidator()->validate($app->getRequest()); - Log::getInstance("CallBackController-wxPayInquiryRefundCallBack")->info("微信退款回调数据:" . json_encode($message->toArray(), JSON_UNESCAPED_UNICODE)); if (empty($message['out_trade_no'])) { @@ -392,15 +388,12 @@ class CallBackController extends AbstractController $app = $WechatPay->createApp(); $server = $app->getServer(); - $message = $server->getRequestMessage(); - + // 获取解密消息 + $message = $server->getDecryptedMessage(); if (empty($message)) { return $this->response->withStatus(500)->withBody(new SwooleStream(strval(json_encode(['code' => 'ERROR', 'message' => "药品微信支付回调数据为空"], JSON_UNESCAPED_UNICODE)))); } - // 验证推送消息签名 - $app->getValidator()->validate($app->getRequest()); - Log::getInstance()->info("药品微信支付回调数据:" . json_encode($message->toArray(), JSON_UNESCAPED_UNICODE)); if (empty($message['out_trade_no'])) { @@ -549,15 +542,13 @@ class CallBackController extends AbstractController $app = $WechatPay->createApp(); $server = $app->getServer(); - $message = $server->getRequestMessage(); + // 获取解密消息 + $message = $server->getDecryptedMessage(); if (empty($message)) { Db::rollBack(); return $this->response->withStatus(500)->withBody(new SwooleStream(strval(json_encode(['code' => 'ERROR', 'message' => "回调数据为空"], JSON_UNESCAPED_UNICODE)))); } - // 验证推送消息签名 - $app->getValidator()->validate($app->getRequest()); - Log::getInstance("CallBackController-wxPayProductRefundCallBack")->info("微信退款回调数据:" . json_encode($message->toArray(), JSON_UNESCAPED_UNICODE)); if (empty($message['out_trade_no'])) { @@ -725,7 +716,7 @@ class CallBackController extends AbstractController { $request_params = $this->request->all(); try { - Log::getInstance("CallBackController-imCallBack")->info("Im回调数据:" . json_encode($request_params, JSON_UNESCAPED_UNICODE)); + Log::getInstance("CallBackController-imCallBack")->info(json_encode($request_params, JSON_UNESCAPED_UNICODE)); if (empty($request_params['RequestTime']) || empty($request_params['Sign'])) { return $this->ImErrorReturn("缺少时间时间戳/签名字段"); @@ -738,107 +729,26 @@ class CallBackController extends AbstractController return $this->ImErrorReturn("回调签名不匹配"); } - // 验证消息内容 - if (empty($request_params['MsgBody'])) { - return $this->ImErrorReturn("消息内容错误,缺少MsgBody"); + if (empty($request_params['CallbackCommand'])){ + return $this->ImErrorReturn("回调事件为空"); } - // 验证消息内容类型 - if (empty($request_params['MsgBody'][0]['MsgType'])) { - return $this->ImErrorReturn("消息内容错误,缺少MsgType"); - } + $userService = new UserService(); - // 验证消息内容详情 - if (empty($request_params['MsgBody'][0]['MsgContent'])) { - return $this->ImErrorReturn("消息内容错误,缺少MsgContent"); - } - - // 验证接收方user_id - if (empty($request_params['To_Account'])) { - return $this->ImErrorReturn("消息内容错误,接收用户错误"); - } - - // 验证消息唯一id - if (empty($request_params['MsgKey'])) { - return $this->ImErrorReturn("消息内容错误,消息唯一标识错误"); - } - - // 验证消息重复性 - $params = array(); - $params['message_key'] = $request_params['MsgKey']; - $message = MessageIm::getExists($params); - if ($message) { - // 消息重复 - Log::getInstance("CallBackController-imCallBack")->info("消息重复"); - return $this->ImSuccessReturn(); - } - - // 处理发送结果 - if ($request_params['SendMsgResult'] == 0) { - // im中0表示成功 - $message_send_result = 1; - } - - // 验证自定义消息内容 - $is_system = 0;// 是否系统操作发送(0:否 1:是) - if (!empty($request_params['CloudCustomData'])) { - $cloud_custom_data = json_decode($request_params['CloudCustomData'], true); - - if (!empty($cloud_custom_data['order_inquiry_id'])) { - // 获取订单数据 - $params = array(); - $params['order_inquiry_id'] = $cloud_custom_data['order_inquiry_id']; - $order_inquiry = OrderInquiry::getOne($params); - if (empty($order_inquiry)) { - return $this->ImErrorReturn("消息内容错误,非法订单"); - } - - $order_inquiry_id = $cloud_custom_data['order_inquiry_id']; + if ($request_params['CallbackCommand'] == "State.StateChange"){ + // 用户状态变更 + $result = $userService->userImLoginStatus($request_params); + if ($result['code'] == 0){ + return $this->ImErrorReturn($result['message']); } - - if (!empty($cloud_custom_data['is_system'])) { - if ($cloud_custom_data['is_system'] == 1) { - // 系统发送 - $is_system = 1; - } - } - } - - // 入库 - $data = array(); - if (!empty($request_params['From_Account'])) { - // 系统发送时不带参数 - $data['from_user_id'] = $request_params['From_Account']; - } - $data['to_user_id'] = $request_params['To_Account']; - $data['message_key'] = $request_params['MsgKey']; - $data['message_send_time'] = $request_params['RequestTime']; - $data['message_seq'] = $request_params['MsgSeq']; - $data['message_send_result'] = $message_send_result ?? 0; - $data['send_error_info'] = $request_params['ErrorInfo']; - $data['message_type'] = $request_params['MsgBody'][0]['MsgType']; - - $data['is_system'] = $is_system; - if (!empty($order_inquiry_id)) { - $data['order_inquiry_id'] = $order_inquiry_id; - } - - $message_content = $request_params['MsgBody'][0]['MsgContent']; - $data['message_content'] = json_encode($message_content, JSON_UNESCAPED_UNICODE); - $data['message_custom_content'] = $request_params['CloudCustomData'] ?? ""; - $message = MessageIm::addMessage($data); - if (empty($message)) { - return $this->ImErrorReturn("存储数据库失败"); - } - - // im消息通知 - if ($is_system == 0 && isset($message_send_result) && isset($order_inquiry_id)){ - try { - $UserService = new UserService(); - $UserService->userImMessageNotice($request_params['To_Account'],$order_inquiry_id,$request_params['MsgBody']); - }catch (\Throwable $e){ - Log::getInstance("CallBackController-imCallBack")->error("im消息通知失败"); + }elseif ($request_params['CallbackCommand'] == "C2C.CallbackAfterSendMsg"){ + // 用户im消息发送后回调 + $result = $userService->userImAfterSendMsg($request_params); + if ($result['code'] == 0){ + return $this->ImErrorReturn($result['message']); } + }else{ + return $this->ImErrorReturn("非法事件"); } } catch (\Exception $e) { // 验证失败 @@ -856,7 +766,7 @@ class CallBackController extends AbstractController */ protected function ImErrorReturn(string $message): ResponseInterface { - Log::getInstance("CallBackController-imCallBack")->error("Im回调数据处理失败:接收用户错误"); + Log::getInstance("CallBackController-imCallBack")->error($message); return $this->response ->withStatus(200) ->withBody( @@ -1240,14 +1150,12 @@ class CallBackController extends AbstractController $app = $WechatPay->createApp(); $server = $app->getServer(); - $message = $server->getRequestMessage(); + // 获取解密消息 + $message = $server->getDecryptedMessage(); if (empty($message)) { return $this->response->withStatus(500)->withBody(new SwooleStream(strval(json_encode(['code' => 'ERROR', 'message' => "问诊微信支付回调数据为空"], JSON_UNESCAPED_UNICODE)))); } - // 验证推送消息签名 - $app->getValidator()->validate($app->getRequest()); - Log::getInstance()->info("检测微信支付回调数据:" . json_encode($message->toArray(), JSON_UNESCAPED_UNICODE)); if (empty($message['out_trade_no'])) { @@ -1332,15 +1240,13 @@ class CallBackController extends AbstractController $app = $WechatPay->createApp(); $server = $app->getServer(); - $message = $server->getRequestMessage(); + // 获取解密消息 + $message = $server->getDecryptedMessage(); if (empty($message)) { Db::rollBack(); return $this->response->withStatus(500)->withBody(new SwooleStream(strval(json_encode(['code' => 'ERROR', 'message' => "回调数据为空"], JSON_UNESCAPED_UNICODE)))); } - // 验证推送消息签名 - $app->getValidator()->validate($app->getRequest()); - Log::getInstance()->info("微信退款回调数据:" . json_encode($message->toArray(), JSON_UNESCAPED_UNICODE)); if (empty($message['out_trade_no'])) { diff --git a/app/Controller/DoctorAccountController.php b/app/Controller/DoctorAccountController.php index 425cc92..e4acb19 100644 --- a/app/Controller/DoctorAccountController.php +++ b/app/Controller/DoctorAccountController.php @@ -32,7 +32,7 @@ class DoctorAccountController extends AbstractController } /** - * 获取我的账户日账单明细数据 + * 获取我的账户月账单明细数据 * @return ResponseInterface * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface diff --git a/app/Controller/PatientCaseController.php b/app/Controller/PatientCaseController.php new file mode 100644 index 0000000..9d55f5c --- /dev/null +++ b/app/Controller/PatientCaseController.php @@ -0,0 +1,96 @@ +container->get(PatientCaseRequest::class); + $request->scene('getPatientFamilyInquiryCaseSimple')->validateResolved(); + + $PatientCaseService = new PatientCaseService(); + $data = $PatientCaseService->getPatientFamilyInquiryCaseSimple(); + return $this->response->json($data); + } + + /** + * 获取问诊订单病例详情 + * @return ResponseInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function getPatientFamilyInquiryCase(): ResponseInterface + { + $request = $this->container->get(PatientCaseRequest::class); + $request->scene('getPatientFamilyInquiryCase')->validateResolved(); + + $PatientCaseService = new PatientCaseService(); + $data = $PatientCaseService->getPatientFamilyInquiryCase(); + return $this->response->json($data); + } + + /** + * 获取问诊订单病例缺少字段 + * @return ResponseInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function getPatientFamilyInquiryCaseUnfilledFields(): ResponseInterface + { + $request = $this->container->get(PatientCaseRequest::class); + $request->scene('getPatientFamilyInquiryCaseUnfilledFields')->validateResolved(); + + $PatientCaseService = new PatientCaseService(); + $data = $PatientCaseService->getPatientFamilyInquiryCaseUnfilledFields(); + return $this->response->json($data); + } + + /** + * 医生发送缺少字段至患者 + * @return ResponseInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function sendCaseUnfilledFieldsToPatient(): ResponseInterface + { + $request = $this->container->get(PatientCaseRequest::class); + $request->scene('sendCaseUnfilledFieldsToPatient')->validateResolved(); + + $PatientCaseService = new PatientCaseService(); + $data = $PatientCaseService->sendCaseUnfilledFieldsToPatient(); + return $this->response->json($data); + } + + /** + * 患者填写缺少字段至医生 + * @return ResponseInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function sendCaseUnfilledFieldsToDoctor(): ResponseInterface + { + $request = $this->container->get(PatientCaseRequest::class); + $request->scene('sendCaseUnfilledFieldsToDoctor')->validateResolved(); + + $PatientCaseService = new PatientCaseService(); + $data = $PatientCaseService->sendCaseUnfilledFieldsToDoctor(); + return $this->response->json($data); + } +} \ No newline at end of file diff --git a/app/Controller/PatientFamilyController.php b/app/Controller/PatientFamilyController.php index 49f73dc..443da1b 100644 --- a/app/Controller/PatientFamilyController.php +++ b/app/Controller/PatientFamilyController.php @@ -5,6 +5,7 @@ namespace App\Controller; use App\Constants\HttpEnumCode; use App\Request\PatientFamilyRequest; use App\Services\PatientFamilyService; +use App\Services\PatientPathographyService; use GuzzleHttp\Exception\GuzzleException; use Hyperf\Validation\Contract\ValidatorFactoryInterface; use Psr\Container\ContainerExceptionInterface; diff --git a/app/Controller/PatientPathographyController.php b/app/Controller/PatientPathographyController.php new file mode 100644 index 0000000..100a0b0 --- /dev/null +++ b/app/Controller/PatientPathographyController.php @@ -0,0 +1,83 @@ +container->get(PatientPathographyRequest::class); + $request->scene('existFamilyPathography')->validateResolved(); + + $PatientPathographyService = new PatientPathographyService(); + $data = $PatientPathographyService->existFamilyPathography(); + return $this->response->json($data); + }catch (\Throwable $e){ + return $this->response->json(fail()); + } + } + + /** + * 获取家庭成员病情记录列表-分页 + * @return ResponseInterface + */ + public function getFamilyPathographyPage(): ResponseInterface + { + try { + $request = $this->container->get(PatientPathographyRequest::class); + }catch (\Throwable $e){ + return $this->response->json(fail()); + } + + $request->scene('getFamilyPathographyPage')->validateResolved(); + + $PatientPathographyService = new PatientPathographyService(); + $data = $PatientPathographyService->getFamilyPathographyPage(); + return $this->response->json($data); + } + + /** + * 获取家庭成员病情记录详情 + * @return ResponseInterface + */ + public function getFamilyPathographyInfo(): ResponseInterface + { + $PatientPathographyService = new PatientPathographyService(); + $data = $PatientPathographyService->getFamilyPathographyInfo(); + return $this->response->json($data); + } + + /** + * 获取家庭成员病情记录分组 + * @return ResponseInterface + */ + public function getFamilyPathographyGroup(): ResponseInterface + { + $PatientPathographyService = new PatientPathographyService(); + $data = $PatientPathographyService->getFamilyPathographyGroup(); + return $this->response->json($data); + } + + /** + * 删除家庭成员病情记录 + * @return ResponseInterface + */ + public function deleteFamilyPathography(): ResponseInterface + { + $PatientPathographyService = new PatientPathographyService(); + $data = $PatientPathographyService->deleteFamilyPathography(); + return $this->response->json($data); + } +} \ No newline at end of file diff --git a/app/Controller/TestController.php b/app/Controller/TestController.php index 1c227d3..d039773 100644 --- a/app/Controller/TestController.php +++ b/app/Controller/TestController.php @@ -34,6 +34,7 @@ use App\Services\OrderProductService; use App\Services\PatientOrderService; use App\Services\UserDoctorService; use App\Utils\Data; +use App\Utils\Jwt; use App\Utils\Log; use App\Utils\Mask; use Extend\Alibaba\Oss; @@ -462,40 +463,62 @@ class TestController extends AbstractController } public function test_17(){ + $expertise_id = $this->request->input('expertise_id'); + $province_id = $this->request->input('province_id'); + $city_id = $this->request->input('city_id'); + $sort_order = $this->request->input('sort_order',1); + $keyword = $this->request->input('keyword',""); + $is_search_welfare_reception = $this->request->input('is_search_welfare_reception',0); // 是否参加公益图文问诊(0:否 1:是) + $is_first_online = $this->request->input('is_first_online',0); // 是否优先在线(1:是) + $page = $this->request->input('page',1); + $per_page = $this->request->input('per_page',10); - $re = \Hyperf\Context\ApplicationContext::getContainer()->get(CacheInterface::class); - $a = $re->set("wucongxing","1",100); - dump($a); - $b = $re->get("wucongxing"); - dump($b); + // 组合条件 + $hospital_params = array();// 医院搜索 + $doctor_params = array();// 医生搜索 + $doctor_expertise_params = array();// 医生专长搜索 - $redis = \Hyperf\Context\ApplicationContext::getContainer()->get(Redis::class); - $c = $redis->get("wucongxing"); - dump($c); + // 省市区 + if (!empty($province_id)) { + if (empty($city_id)) { + // 省份存在时需和城市在一块 + return fail(HttpEnumCode::CLIENT_HTTP_ERROR); + } + $hospital_params[] = ['province_id', '=', $province_id]; + $hospital_params[] = ['city_id', '=', $city_id]; + } + // 医生专长 + if (!empty($expertise_id)) { + $doctor_expertise_params['expertise_id'] = $expertise_id; + } -// -// $weChat = new Wechat(1); -// -// $env_version = "release"; -// $app_env = \Hyperf\Support\env("APP_ENV",'dev'); -// if ($app_env == "dev"){ -// $env_version = "trial"; -// } -// -// $options = [ -// "scene" => "?doctor_id=516900370252341248",// query 参数 -// "page" => "pages/expertDetail/expertDetail", -// "check_path" => false, -// "env_version" => $env_version, -// ]; -// -// $img_buffer = $weChat->getUnlimitedQRCode($options); -// -// $oss = new Oss(); -// -// $filename = "applet/doctor/card/516900370252341248.jpg"; -// -// $oss->putObject($filename, $img_buffer); + // 固定医生查询条件 + $doctor_params['status'] = 1; // 状态(0:禁用 1:正常 2:删除) + + $doctor_params["iden_auth_status"] = 1;// 身份认证状态(0:未认证 1:认证通过 2:审核中 3:认证失败) + $doctor_params["is_bind_bank"] = 1;// 是否已绑定结算银行卡(0:否 1:是) + + $fields = [ + "doctor_id", + "user_id", + "user_name", + "multi_point_status", + "is_bind_bank", + "is_recommend", + "avatar", + "doctor_title", + "department_custom_id", + "department_custom_name", + "hospital_id", + "served_patients_num", + "praise_rate", + "avg_response_time", + "number_of_fans", + "be_good_at", + ]; + + $user_doctors = UserDoctor::getInquiryDoctorPageTest($keyword,$hospital_params, $doctor_params,$doctor_expertise_params,$is_search_welfare_reception,$is_first_online, $sort_order, ['*'],$page,$per_page); + return success($user_doctors); } } \ No newline at end of file diff --git a/app/Middleware/Auth/AuthMiddleware.php b/app/Middleware/Auth/AuthMiddleware.php index 5263fd1..c23bc79 100644 --- a/app/Middleware/Auth/AuthMiddleware.php +++ b/app/Middleware/Auth/AuthMiddleware.php @@ -62,9 +62,9 @@ class AuthMiddleware implements MiddlewareInterface $white_api = $Auth->checkApiWhiteList($path_info, $method); if (!empty($token)){ + $res = $redis->get('jwt_black_' . $token); if ($white_api){ // 存在token,免鉴权 - $res = $redis->get('jwt_black_' . $token); if ($res && time() >= $res) { // token存在黑名单中 return $handler->handle($request); @@ -78,31 +78,37 @@ class AuthMiddleware implements MiddlewareInterface } }else{ // 存在token,鉴权 - $res = $redis->get('jwt_black_' . $token); if ($res && time() >= $res) { // token存在黑名单中 return $this->response->json(fail(HttpEnumCode::TOKEN_ERROR)); } - // jwt验证 - $result = $Jwt->decode($token); + try { + // jwt验证 + $result = $Jwt->decode($token); - // 处理即将过期token - $req = $Auth->checkTokenExpTime($result); - if ($req) { - // 即将过期,重新下发token - $new_token = $Jwt->encode($result['userInfo']); + // 处理即将过期token + $req = $Auth->checkTokenExpTime($result); + if ($req) { + // 即将过期,重新下发token + $new_token = $Jwt->encode($result['userInfo']); - // 旧token加入黑名单 5天有效期,5天内,无法继续进行访问 - $res = $redis->set('jwt_black_' . $token, $result['exp'], 30); - if (!$res) { - // 添加缓存失败 - return $this->response->json(fail(HttpEnumCode::SERVER_ERROR)); + // 旧token加入黑名单 5天有效期,5天内,无法继续进行访问 + $res = $redis->set('jwt_black_' . $token, $result['exp'], 30); + if (!$res) { + // 添加缓存失败 + return $this->response->json(fail(HttpEnumCode::SERVER_ERROR)); + } + + $response = Context::get(ResponseInterface::class); + $response = $response->withHeader('Authorization', $new_token); + Context::set(ResponseInterface::class, $response); } - - $response = Context::get(ResponseInterface::class); - $response = $response->withHeader('Authorization', $new_token); - Context::set(ResponseInterface::class, $response); + }catch (\Throwable $e){ + if ($e->getCode() == 405 || $e->getCode() == 406){ + return $this->response->json(fail($e->getCode())); + } + return $this->response->json(fail(HttpEnumCode::SERVER_ERROR)); } } }else{ diff --git a/app/Model/DoctorAccountDay.php b/app/Model/DoctorAccountDay.php index c6e3902..9e406cf 100644 --- a/app/Model/DoctorAccountDay.php +++ b/app/Model/DoctorAccountDay.php @@ -6,6 +6,9 @@ namespace App\Model; +use Hyperf\Database\Model\Builder; +use Hyperf\Database\Model\Collection; +use Hyperf\DbConnection\Db; use Hyperf\Snowflake\Concern\Snowflake; /** @@ -103,4 +106,19 @@ class DoctorAccountDay extends Model { return self::where($params)->decrement($field,$numeral); } + + /** + * 获取医生账户月份金额 + * @param array $params + * @param array $fields + * @return \Hyperf\Collection\Collection + */ + public static function getDoctorMonth(array $params,array $fields = ['*']): \Hyperf\Collection\Collection + { + return self::select(['month',Db::raw('SUM(total_amount) AS `total_amount`')]) + ->where($params) + ->groupBy(['month']) + ->orderBy('month') + ->get($fields); + } } diff --git a/app/Model/OrderInquiry.php b/app/Model/OrderInquiry.php index 669597b..d2d1de1 100644 --- a/app/Model/OrderInquiry.php +++ b/app/Model/OrderInquiry.php @@ -178,17 +178,19 @@ class OrderInquiry extends Model * 获取医生某一时间段接诊订单分页数据 * 已结束 * @param array $params - * @param array $reception_time 接诊时间区间 ['2023-01-02','2023-01-03'] + * @param array $reception_time 接诊时间区间 ['2023-01','2023-01'] + * @param array $inquiry_status_params * @param array $fields * @param int|null $page * @param int|null $per_page * @return int|mixed|string */ - public static function getDoctorCreatedDateOrderInquiryPage(array $params, array $reception_time, array $fields = ["*"], int $page = null, ?int $per_page = 10): mixed + public static function getDoctorCreatedDateOrderInquiryPage(array $params, array $reception_time, array $inquiry_status_params,array $fields = ["*"], int $page = null, ?int $per_page = 10): mixed { $raw = self::where($params) - ->whereBetween('created_at', $reception_time) - ->orderBy('created_at') + ->whereIn('inquiry_status', $inquiry_status_params) + ->whereBetween('reception_time', $reception_time) + ->orderBy('reception_time') ->paginate($per_page, $fields, "page", $page); $data = array(); diff --git a/app/Model/OrderInquiryCase.php b/app/Model/OrderInquiryCase.php index 1584daf..536fa3e 100644 --- a/app/Model/OrderInquiryCase.php +++ b/app/Model/OrderInquiryCase.php @@ -14,6 +14,9 @@ use Hyperf\Snowflake\Concern\Snowflake; * @property int $patient_id 患者id * @property int $order_inquiry_id 订单-问诊id * @property int $family_id 家庭成员id + * @property int $disease_class_id 疾病分类id-系统 + * @property int $nation_id 民族 + * @property int $job_id 职业id * @property int $relation 与患者关系(1:本人 2:父母 3:爱人 4:子女 5:亲戚 6:其他 ) * @property int $status 状态(1:正常 2:删除) * @property string $name 患者名称 @@ -21,7 +24,7 @@ use Hyperf\Snowflake\Concern\Snowflake; * @property int $age 患者年龄 * @property string $height 身高(cm) * @property string $weight 体重(kg) - * @property int $disease_class_id 疾病分类id-系统 + * @property int $marital_status 婚姻状况(0:未婚 1:已婚 2:离异) * @property string $disease_class_name 疾病名称-系统 * @property string $diagnosis_date 确诊日期 * @property string $disease_desc 病情描述(主诉) @@ -33,8 +36,17 @@ use Hyperf\Snowflake\Concern\Snowflake; * @property int $is_pregnant 是否备孕、妊娠、哺乳期(0:否 1:是) * @property string $pregnant 备孕、妊娠、哺乳期描述 * @property int $is_taboo 是否服用过禁忌药物,且无相关禁忌(0:否 1:是)问诊购药时存在 - * @property int $nation_id 民族 + * @property int $is_take_medicine 正在服药(0:否 1:是) + * @property string $drugs_name 正在服药名称 * @property string $nation_name 民族名称 + * @property string $job_name 职业名称 + * @property string $diagnosis_hospital 确诊医院 + * @property int $is_operation 是否存在手术(0:否 1:是) + * @property string $operation 手术描述 + * @property int $drink_wine_status 饮酒状态(1:从不 2:偶尔 3:经常 4:每天 5:已戒酒) + * @property int $smoke_status 吸烟状态(1:从不 2:偶尔 3:经常 4:每天 5:已戒烟) + * @property int $chemical_compound_status 化合物状态(1:从不 2:偶尔 3:经常 4:每天) + * @property string $chemical_compound_describe 化合物描述 * @property \Carbon\Carbon $created_at 创建时间 * @property \Carbon\Carbon $updated_at 修改时间 * @property-read BasicJob|null $BasicJob @@ -53,7 +65,7 @@ class OrderInquiryCase extends Model /** * The attributes that are mass assignable. */ - protected array $fillable = ['inquiry_case_id', 'user_id', 'patient_id', 'order_inquiry_id', 'family_id', 'relation', 'status', 'name', 'sex', 'age', 'height', 'weight', 'disease_class_id', 'disease_class_name', 'diagnosis_date', 'disease_desc', 'diagnose_images', 'is_allergy_history', 'allergy_history', 'is_family_history', 'family_history', 'is_pregnant', 'pregnant', 'is_taboo', 'nation_id', 'nation_name', 'created_at', 'updated_at']; + protected array $fillable = ['inquiry_case_id', 'user_id', 'patient_id', 'order_inquiry_id', 'family_id', 'disease_class_id', 'nation_id', 'job_id', 'relation', 'status', 'name', 'sex', 'age', 'height', 'weight', 'marital_status', 'disease_class_name', 'diagnosis_date', 'disease_desc', 'diagnose_images', 'is_allergy_history', 'allergy_history', 'is_family_history', 'family_history', 'is_pregnant', 'pregnant', 'is_taboo', 'is_take_medicine', 'drugs_name', 'nation_name', 'job_name', 'diagnosis_hospital', 'is_operation', 'operation', 'drink_wine_status', 'smoke_status', 'chemical_compound_status', 'chemical_compound_describe', 'created_at', 'updated_at']; protected string $primaryKey = "inquiry_case_id"; diff --git a/app/Model/PatientFamily.php b/app/Model/PatientFamily.php index a2768fe..aa1bbfd 100644 --- a/app/Model/PatientFamily.php +++ b/app/Model/PatientFamily.php @@ -7,6 +7,7 @@ namespace App\Model; use Hyperf\Database\Model\Collection; +use Hyperf\Database\Model\Relations\HasOne; use Hyperf\Snowflake\Concern\Snowflake; /** diff --git a/app/Model/PatientFollow.php b/app/Model/PatientFollow.php index 596c5a1..bee9b94 100644 --- a/app/Model/PatientFollow.php +++ b/app/Model/PatientFollow.php @@ -67,6 +67,22 @@ class PatientFollow extends Model ); } + /** + * 远程关联用户表 + * @return HasOneThrough + */ + public function User(): HasOneThrough + { + return $this->hasOneThrough( + User::class, + UserDoctor::class, + "doctor_id", + "user_id", + "doctor_id", + "user_id", + ); + } + /** * 获取是否存在 * @param array $params @@ -109,8 +125,9 @@ class PatientFollow extends Model $query = self::with([ 'DoctorExpertise:doctor_expertise_id,doctor_id,expertise_id', 'DoctorExpertise.DiseaseClassExpertise:expertise_id,expertise_name', - "UserDoctor:doctor_id,user_name,avatar,doctor_title,hospital_id,multi_point_status,department_custom_name,be_good_at", - "UserDoctor.Hospital:hospital_id,hospital_name,hospital_level_name" + "UserDoctor:doctor_id,user_id,user_name,avatar,doctor_title,hospital_id,multi_point_status,department_custom_name,be_good_at", + "UserDoctor.Hospital:hospital_id,hospital_name,hospital_level_name", + "UserDoctor.User:user_id,is_online" ]) ->where($params) ->paginate($per_page, $fields, "page", $page); diff --git a/app/Model/PatientHistoryInquiry.php b/app/Model/PatientHistoryInquiry.php index 7aeed7f..e818406 100644 --- a/app/Model/PatientHistoryInquiry.php +++ b/app/Model/PatientHistoryInquiry.php @@ -66,6 +66,22 @@ class PatientHistoryInquiry extends Model ); } + /** + * 远程关联用户表 + * @return HasOneThrough + */ + public function User(): HasOneThrough + { + return $this->hasOneThrough( + User::class, + UserDoctor::class, + "doctor_id", + "user_id", + "doctor_id", + "user_id", + ); + } + /** * 关联医生专长表 * @return HasMany @@ -191,8 +207,9 @@ class PatientHistoryInquiry extends Model $query = self::with([ 'DoctorExpertise:doctor_expertise_id,doctor_id,expertise_id', 'DoctorExpertise.DiseaseClassExpertise:expertise_id,expertise_name', - "UserDoctor:doctor_id,user_name,avatar,doctor_title,hospital_id,multi_point_status,department_custom_name,be_good_at", - "UserDoctor.Hospital:hospital_id,hospital_name,hospital_level_name" + "UserDoctor:doctor_id,user_id,user_name,avatar,doctor_title,hospital_id,multi_point_status,department_custom_name,be_good_at", + "UserDoctor.Hospital:hospital_id,hospital_name,hospital_level_name", + "UserDoctor.User:user_id,is_online" ]) ->where($params) ->groupBy('doctor_id') diff --git a/app/Model/PatientPathography.php b/app/Model/PatientPathography.php new file mode 100644 index 0000000..7165f40 --- /dev/null +++ b/app/Model/PatientPathography.php @@ -0,0 +1,168 @@ +hasOne(OrderInquiry::class, 'order_inquiry_id', 'order_inquiry_id'); + } + + /** + * 获取信息-单条 + * @param array $params + * @param array $fields + * @return object|null + */ + public static function getOne(array $params, array $fields = ['*']): object|null + { + return self::where($params)->first($fields); + } + + /** + * 获取信息-单条 + * @param array $params + * @param array $fields + * @return object|null + */ + public static function getLastOne(array $params, array $fields = ['*']): object|null + { + return self::where($params)->latest("created_at")->first($fields); + } + + /** + * 获取数据-多 + * @param array $params + * @param array $fields + * @return Collection|array + */ + public static function getList(array $params = [], array $fields = ['*']): Collection|array + { + return self::where($params)->get($fields); + } + + /** + * 新增 + * @param array $data + * @return \Hyperf\Database\Model\Model|PatientPathography + */ + public static function addPatientPathography(array $data): \Hyperf\Database\Model\Model|PatientPathography + { + return self::create($data); + } + + /** + * 修改 + * @param array $params + * @param array $data + * @return int + */ + public static function edit(array $params = [], array $data = []): int + { + return self::where($params)->update($data); + } + + /** + * 获取家庭成员病情记录列表-分页 + * @param array $params + * @param array $fields + * @param int|null $page + * @param int|null $per_page + * @return array + */ + public static function getPatientPathographyPage(array $params,array $fields = ["*"], int $page = null, ?int $per_page = 10): array + { + $result = self::with(['OrderInquiry']) + ->where($params) + ->orderBy("created_at",'desc') + ->paginate($per_page, $fields, "page", $page); + + $data = array(); + $data['current_page'] = $result->currentPage();// 当前页码 + $data['total'] = $result->total();// 数据总数 + $data['data'] = $result->items();// 数据 + $data['per_page'] = $result->perPage();// 每页个数 + $data['last_page'] = $result->lastPage();// 最后一页 + + return $data; + } + + // 获取信息-分组 + public static function getFamilyPathographyGroup(array $params, array $fields = ['*']): object|null + { + return self::where($params) + ->groupBy(["family_id"]) + ->get($fields); + } +} diff --git a/app/Model/PatientPathographyProduct.php b/app/Model/PatientPathographyProduct.php new file mode 100644 index 0000000..e0cd5c5 --- /dev/null +++ b/app/Model/PatientPathographyProduct.php @@ -0,0 +1,79 @@ +first($fields); + } + + /** + * 获取数据-多 + * @param array $params + * @param array $fields + * @return Collection|array + */ + public static function getList(array $params = [], array $fields = ['*']): Collection|array + { + return self::where($params)->get($fields); + } + + /** + * 新增 + * @param array $data + * @return \Hyperf\Database\Model\Model|PatientPathographyProduct + */ + public static function addPatientPathographyProduct(array $data): \Hyperf\Database\Model\Model|PatientPathographyProduct + { + return self::create($data); + } + + /** + * 修改 + * @param array $params + * @param array $data + * @return int + */ + public static function edit(array $params = [], array $data = []): int + { + return self::where($params)->update($data); + } + +} diff --git a/app/Model/Product.php b/app/Model/Product.php index 7059df5..42dfb44 100644 --- a/app/Model/Product.php +++ b/app/Model/Product.php @@ -13,6 +13,9 @@ use Hyperf\Snowflake\Concern\Snowflake; /** * @property int $product_id 主键id * @property int $product_platform_id 处方平台商品id + * @property int $product_status 商品状态(1:正常 2:下架) + * @property int $is_delete 是否删除(0:否 1:是) + * @property int $prescription_num 处方可开具的数量 * @property string $product_name 商品名称 * @property string $common_name 商品通用名 * @property string $product_price 商品价格 @@ -32,6 +35,7 @@ use Hyperf\Snowflake\Concern\Snowflake; * @property string $product_remarks 商品备注 * @property \Carbon\Carbon $created_at 创建时间 * @property \Carbon\Carbon $updated_at 修改时间 + * @property-read ProductPlatformAmount|null $ProductPlatformAmount */ class Product extends Model { @@ -45,7 +49,7 @@ class Product extends Model /** * The attributes that are mass assignable. */ - protected array $fillable = ['product_id', 'product_platform_id', 'product_name', 'common_name', 'product_price', 'mnemonic_code', 'product_type', 'product_platform_code', 'product_pharmacy_code', 'product_cover_img', 'product_spec', 'license_number', 'manufacturer', 'single_unit', 'single_use', 'packaging_unit', 'frequency_use', 'available_days', 'product_remarks', 'created_at', 'updated_at']; + protected array $fillable = ['product_id', 'product_platform_id', 'product_status', 'is_delete', 'prescription_num', 'product_name', 'common_name', 'product_price', 'mnemonic_code', 'product_type', 'product_platform_code', 'product_pharmacy_code', 'product_cover_img', 'product_spec', 'license_number', 'manufacturer', 'single_unit', 'single_use', 'packaging_unit', 'frequency_use', 'available_days', 'product_remarks', 'created_at', 'updated_at']; protected string $primaryKey = "product_id"; diff --git a/app/Model/ReportRegulatory.php b/app/Model/ReportRegulatory.php index 32a051a..29b737f 100644 --- a/app/Model/ReportRegulatory.php +++ b/app/Model/ReportRegulatory.php @@ -15,11 +15,16 @@ use Hyperf\Snowflake\Concern\Snowflake; * @property int $order_inquiry_id 订单-问诊id * @property int $order_prescription_id 订单-处方表id(无需上报处方时为null) * @property int $order_product_id 订单-商品表id(无需上报处方时为null) - * @property int $report_inquiry_status 问诊上报状态(0:未上报 1:已上报 2:上报失败) - * @property int $report_inquiry_int 问诊上报次数 - * @property int $report_inquiry_type 问诊上报类型(1:网络初诊 2:网络复诊) - * @property string $report_inquiry_time 问诊上报时间 - * @property string $report_inquiry_fail_reason 问诊上报失败原因 + * @property int $report_consult_status 上报网络咨询状态(0:未上报 1:已上报 2:上报失败) + * @property int $report_consult_int 网络咨询上报次数 + * @property string $report_consult_time 网络咨询上报时间 + * @property string $report_consult_fail_reason 网络咨询上报失败原因 + * @property int $is_further_consult 是否需要上报网络复诊(0:否 1:是) + * @property int $report_further_consult_status 上报网络复诊状态(0:未上报 1:已上报 2:上报失败) + * @property int $report_further_consult_int 网络复诊上报次数 + * @property string $report_further_consult_time 网络复诊上报时间 + * @property string $report_further_consult_fail_reason 网络复诊上报失败原因 + * @property int $is_prescription 是否需要上报处方(0:否 1:是) * @property int $report_prescription_status 处方上报状态(0:未上报 1:已上报 2:上报失败) * @property int $report_prescription_int 处方上报次数 * @property string $report_prescription_time 处方上报时间 @@ -39,11 +44,10 @@ class ReportRegulatory extends Model /** * The attributes that are mass assignable. */ - protected array $fillable = ['report_regulatory_id', 'order_inquiry_id', 'order_prescription_id', 'order_product_id', 'report_inquiry_status', 'report_inquiry_int', 'report_inquiry_type', 'report_inquiry_time', 'report_inquiry_fail_reason', 'report_prescription_status', 'report_prescription_int', 'report_prescription_time', 'report_prescription_fail_reason', 'created_at', 'updated_at']; + protected array $fillable = ['report_regulatory_id', 'order_inquiry_id', 'order_prescription_id', 'order_product_id', 'report_consult_status', 'report_consult_int', 'report_consult_time', 'report_consult_fail_reason', 'is_further_consult', 'report_further_consult_status', 'report_further_consult_int', 'report_further_consult_time', 'report_further_consult_fail_reason', 'is_prescription', 'report_prescription_status', 'report_prescription_int', 'report_prescription_time', 'report_prescription_fail_reason', 'created_at', 'updated_at']; protected string $primaryKey = "report_regulatory_id"; - /** * 获取信息-单条 * @param array $params @@ -117,18 +121,36 @@ class ReportRegulatory extends Model } /** - * 列表 + * 检测是否存在 * @param array $params - * @param array $or_params + * @return bool + */ + public static function getExists(array $params): bool + { + return self::where($params)->exists(); + } + + + /** + * 获取未上报监管平台列表 * @param array $fields * @return Collection|array */ - public static function getNotReportList(array $params = [],array $fields = ["*"]): Collection|array + public static function getNotReportList(array $fields = ["*"]): Collection|array { - return self::where($params) - ->Where(function ($query) { - $query->orWhere('report_inquiry_status','!=',1); - $query->orWhere('report_prescription_status','!=',1); + return self::orWhere(function ($query) { + $query->Where('is_further_consult','=',1); + $query->Where('report_further_consult_status','!=',1); + $query->Where('report_further_consult_int','<',5); + }) + ->orWhere(function ($query) { + $query->Where('is_prescription','=',1); + $query->Where('report_prescription_status','!=',1); + $query->Where('report_prescription_int','<',5); + }) + ->orWhere(function ($query) { + $query->Where('report_consult_status','!=',1); + $query->Where('report_consult_int','<',5); }) ->get($fields); } diff --git a/app/Model/User.php b/app/Model/User.php index 40bc14d..99d7c37 100644 --- a/app/Model/User.php +++ b/app/Model/User.php @@ -23,9 +23,11 @@ use Hyperf\Snowflake\Concern\Snowflake; * @property int $age 年龄 * @property int $sex 性别(0:未知 1:男 2:女) * @property string $avatar 头像 + * @property int $is_online 是否在线(0:不在线 1:在线) + * @property string $login_at 小程序登陆时间 + * @property string $im_login_at im登陆时间 * @property string $login_ip 登陆ip - * @property string $last_login_at 最后登陆时间 - * @property string $created_by 创建者id(后台用户表id null:自己注册) + * @property string $created_by 创建者id(后台用户表id,前台用户表id) * @property \Carbon\Carbon $created_at 创建时间 * @property \Carbon\Carbon $updated_at 修改时间 */ @@ -41,7 +43,7 @@ class User extends Model /** * The attributes that are mass assignable. */ - protected array $fillable = ['user_id', 'user_name', 'user_account', 'mobile', 'wx_mobile', 'user_password', 'salt', 'user_type', 'user_status', 'register_method', 'age', 'sex', 'avatar', 'login_ip', 'last_login_at', 'created_by', 'created_at', 'updated_at']; + protected array $fillable = ['user_id', 'user_name', 'user_account', 'mobile', 'wx_mobile', 'user_password', 'salt', 'user_type', 'user_status', 'register_method', 'age', 'sex', 'avatar', 'is_online', 'login_at', 'im_login_at', 'login_ip', 'created_by', 'created_at', 'updated_at']; protected string $primaryKey = "user_id"; diff --git a/app/Model/UserDoctor.php b/app/Model/UserDoctor.php index 3515e15..78ff19a 100644 --- a/app/Model/UserDoctor.php +++ b/app/Model/UserDoctor.php @@ -32,7 +32,7 @@ use Hyperf\Utils\Arr; * @property int $is_bind_bank 是否已绑定结算银行卡(0:否 1:是) * @property int $is_recommend 是否首页推荐(0:否 1:是) * @property string $avatar 头像 - * @property int $doctor_title 医生职称(1:主任中医师 2:主任医师 3:副主任中医师 4:副主任医师 5:主治医师 6:住院医师) + * @property int $doctor_title 医生职称(1:主任医师 2:主任中医师 3:副主任医师 4:副主任中医师 5:主治医师 6:住院医师) * @property int $department_custom_id 科室id-自定义 * @property string $department_custom_name 科室名称(如未自己输入,填入标准科室名称) * @property string $department_custom_mobile 科室电话 @@ -41,21 +41,21 @@ use Hyperf\Utils\Arr; * @property string $praise_rate 好评率(百分制。订单平均评价中超过4-5分的订单总数 / 总订单数 * 5) * @property string $avg_response_time 平均响应时间(分钟制) * @property int $number_of_fans 被关注数量 - * @property int $is_online 是否在线(0:不在线 1:在线) * @property int $is_img_expert_reception 是否参加专家图文接诊(0:否 1:是) * @property int $is_img_welfare_reception 是否参加公益图文问诊(0:否 1:是) * @property int $is_img_quick_reception 是否参加快速图文接诊(0:否 1:是) * @property int $is_platform_deep_cooperation 是否平台深度合作医生(0:否 1:是) * @property int $is_enterprise_deep_cooperation 是否企业深度合作医生(0:否 1:是) + * @property int $is_sys_diagno_cooperation 是否先思达合作医生(0:否 1:是) * @property string $qr_code 分享二维码 * @property string $be_good_at 擅长 * @property string $brief_introduction 医生简介 * @property \Carbon\Carbon $created_at 创建时间 * @property \Carbon\Carbon $updated_at 修改时间 - * @property-read \Hyperf\Database\Model\Collection|DoctorExpertise[] $DoctorExpertise - * @property-read \Hyperf\Database\Model\Collection|DoctorInquiryConfig[] $DoctorInquiryConfig - * @property-read Hospital $Hospital - * @property-read \Hyperf\Database\Model\Collection|OrderInquiry[] $OrderInquiry + * @property-read \Hyperf\Database\Model\Collection|DoctorExpertise[]|null $DoctorExpertise + * @property-read \Hyperf\Database\Model\Collection|DoctorInquiryConfig[]|null $DoctorInquiryConfig + * @property-read Hospital|null $Hospital + * @property-read \Hyperf\Database\Model\Collection|OrderInquiry[]|null $OrderInquiry */ class UserDoctor extends Model { @@ -69,7 +69,7 @@ class UserDoctor extends Model /** * The attributes that are mass assignable. */ - protected array $fillable = ['doctor_id', 'user_id', 'user_name', 'open_id', 'union_id', 'wx_session_key', 'status', 'idcard_status', 'iden_auth_status', 'iden_auth_time', 'iden_auth_fail_reason', 'multi_point_status', 'multi_point_time', 'multi_point_fail_reason', 'is_bind_bank', 'is_recommend', 'avatar', 'doctor_title', 'department_custom_id', 'department_custom_name', 'department_custom_mobile', 'hospital_id', 'served_patients_num', 'praise_rate', 'avg_response_time', 'number_of_fans', 'is_online', 'is_img_expert_reception', 'is_img_welfare_reception', 'is_img_quick_reception', 'is_platform_deep_cooperation', 'is_enterprise_deep_cooperation', 'qr_code', 'be_good_at', 'brief_introduction', 'created_at', 'updated_at']; + protected array $fillable = ['doctor_id', 'user_id', 'user_name', 'open_id', 'union_id', 'wx_session_key', 'status', 'idcard_status', 'iden_auth_status', 'iden_auth_time', 'iden_auth_fail_reason', 'multi_point_status', 'multi_point_time', 'multi_point_fail_reason', 'is_bind_bank', 'is_recommend', 'avatar', 'doctor_title', 'department_custom_id', 'department_custom_name', 'department_custom_mobile', 'hospital_id', 'served_patients_num', 'praise_rate', 'avg_response_time', 'number_of_fans', 'is_img_expert_reception', 'is_img_welfare_reception', 'is_img_quick_reception', 'is_platform_deep_cooperation', 'is_enterprise_deep_cooperation', 'is_sys_diagno_cooperation', 'qr_code', 'be_good_at', 'brief_introduction', 'created_at', 'updated_at']; protected string $primaryKey = "doctor_id"; @@ -81,6 +81,14 @@ class UserDoctor extends Model return $this->hasOne(Hospital::class, 'hospital_id', 'hospital_id'); } + /** + * 关联用户表 + */ + public function User(): HasOne + { + return $this->hasOne(User::class, 'user_id', 'user_id'); + } + /** * 关联问诊配置表(一对多) * @return HasMany @@ -108,13 +116,6 @@ class UserDoctor extends Model return $this->hasMany(OrderInquiry::class, "doctor_id", "doctor_id"); } -// /** -// * 关联职称表 -// */ -// public function BasicDoctorTitle(): HasOne -// { -// return $this->hasOne(BasicDoctorTitle::class, 'doctor_title_id', 'doctor_title_id'); -// } /** * 获取医生信息-单条 @@ -180,8 +181,8 @@ class UserDoctor extends Model // 身份认证状态(0:未认证 1:认证通过 2:审核中 3:认证失败) $params["iden_auth_status"] = 1; - // 是否在线(0:不在线 1:在线) - $params["is_online"] = 1; +// // 是否在线(0:不在线 1:在线) +// $params["is_online"] = 1; // // 是否参加专家图文接诊(0:否 1:是) // $params["is_img_expert_reception"] = 1; @@ -189,6 +190,7 @@ class UserDoctor extends Model $datas = self::with([ 'Hospital:hospital_id,hospital_name,hospital_level_name', "DoctorInquiryConfig", + "User" ]) ->where($params) ->orderBy("is_recommend", "desc") @@ -202,108 +204,6 @@ class UserDoctor extends Model return $datas; } -// /** -// * 获取问诊医生列表 -// * 专家问诊-公益问诊共用 -// * @param string $keyword -// * @param array $hospital_params 医院搜索条件 -// * @param array $doctor_params 医生搜索条件 -// * @param array $doctor_expertise_params -// * @param string|int $sort_order -// * @param array $fields -// * @param int|null $page -// * @param int|null $per_page -// * @return array -// */ -// public static function getInquiryDoctorPage(string $keyword = "", array $hospital_params = [], array $doctor_params = [], array $doctor_expertise_params = [], string|int $sort_order = 1, array $fields = ["*"], int $page = null, ?int $per_page = 10): array -// { -// $query = self::with([ -// "Hospital:hospital_id,hospital_name,hospital_status,hospital_level_name,province_id,city_id", -// "DoctorExpertise", -// "DoctorInquiryConfig" => function ($query) use ($sort_order) { -// $query->whereIn('inquiry_type', [1, 3]) -// ->where('inquiry_mode', 1); -// }, -// ]) -// ->where($doctor_params) -// ->when($keyword, function ($query, $keyword) { -// $query->where(function ($query) use ($keyword) { -// $query->orwhere("user_name", 'like', '%' . $keyword . '%'); -// $query->orwhere("department_custom_name", 'like', '%' . $keyword . '%'); -// $query->orWhereHas('Hospital', function ($query) use ($keyword) { -// $query->where('hospital_name', 'like', '%' . $keyword . '%'); -// }); -// }); -// }) -// ->whereHas('Hospital', function ($query) use ($hospital_params) { -// $query->where($hospital_params); -// }) -// ->whereHas('DoctorExpertise', function ($query) use ($doctor_expertise_params) { -// $query->where($doctor_expertise_params); -// }) -// ->whereHas('DoctorInquiryConfig', function ($query) { -// $params = array(); -// $params['inquiry_mode'] = 1;// 接诊方式:图文 -// $query->where($params)->whereIn('inquiry_type', [1, 3]); -// }); -// -// if (!empty($sort_order)){ -// if (in_array($sort_order,[1,3,4])){ -// $query = $query->join('doctor_inquiry_config', function ($query) { -// $query->on('user_doctor.doctor_id', '=', 'doctor_inquiry_config.doctor_id') -// ->whereIn('inquiry_type', [1, 3]) -// ->where('inquiry_mode', 1) -// ->orderBy('inquiry_price', 'desc') -// ->take(1); -// }) -// ->select("user_doctor.*") -// ->groupBy("user_doctor.doctor_id"); -// } -// -// if ($sort_order == 1) { -// // 综合-价格从低到高 -// $query->orderBy('is_recommend', 'desc');// 是否首页推荐(0:否 1:是) -// $query->orderByRaw('avg_response_time = 0 ASC'); -// $query->orderBy('avg_response_time'); -// $query->orderBy('served_patients_num', 'desc');// 服务数从多到少 -// $query->orderBy(Db::raw("convert(substr(user_name,1,1) using `GBK`)"), 'asc');// 名称排名 -// $query->orderBy('doctor_inquiry_config.inquiry_price', 'asc'); -// } elseif ($sort_order == 2) { -// // 响应时间快 -// $query->orderByRaw('avg_response_time = 0 ASC'); -// $query->orderBy('avg_response_time'); -// $query->orderBy(Db::raw("convert(substr(user_name,1,1) using `GBK`)"), 'asc');// 名称排名 -// } elseif ($sort_order == 3) { -// // 价格从低到高 -// $query->orderBy('doctor_inquiry_config.inquiry_price', 'asc'); -// $query->orderByRaw('avg_response_time = 0 ASC'); -// $query->orderBy('avg_response_time'); -// $query->orderBy(Db::raw("convert(substr(user_name,1,1) using `GBK`)"), 'asc');// 名称排名 -// } elseif ($sort_order == 4) { -// // 价格从高到低 -// $query->orderBy('doctor_inquiry_config.inquiry_price', 'desc'); -// $query->orderByRaw('avg_response_time = 0 ASC'); -// $query->orderBy('avg_response_time'); -// $query->orderBy(Db::raw("convert(substr(user_name,1,1) using `GBK`)"), 'asc');// 名称排名 -// } elseif ($sort_order == 5) { -// // 服务数从多到少 -// $query->orderBy('served_patients_num', 'desc'); -// $query->orderBy(Db::raw("convert(substr(user_name,1,1) using `GBK`)"), 'asc');// 名称排名 -// } -// } -// -// $result = $query->paginate($per_page, $fields, "page", $page); -// -// $data = array(); -// $data['current_page'] = $result->currentPage();// 当前页码 -// $data['total'] = $result->total();//数据总数 -// $data['data'] = $result->items();//数据 -// $data['per_page'] = $result->perPage();//每页个数 -// $data['last_page'] = $result->lastPage();//最后一页 -// -// return $data; -// } - /** * 获取问诊医生列表 * 专家问诊-公益问诊共用 @@ -312,13 +212,14 @@ class UserDoctor extends Model * @param array $doctor_params 医生搜索条件 * @param array $doctor_expertise_params * @param int $is_search_welfare_reception 是否搜索公益问诊 + * @param string|int $is_first_online 是否优先在线(1:是) * @param string|int $sort_order * @param array $fields * @param int|null $page * @param int|null $per_page * @return array */ - public static function getInquiryDoctorPage(string $keyword = "", array $hospital_params = [], array $doctor_params = [], array $doctor_expertise_params = [],int $is_search_welfare_reception = 0, string|int $sort_order = 1, array $fields = ["*"], int $page = null, ?int $per_page = 10): array + public static function getInquiryDoctorPage(string $keyword = "", array $hospital_params = [], array $doctor_params = [], array $doctor_expertise_params = [],int $is_search_welfare_reception = 0,string|int $is_first_online = 0, string|int $sort_order = 1, array $fields = ["*"], int $page = null, ?int $per_page = 10): array { $query = self::with([ "Hospital:hospital_id,hospital_name,hospital_status,hospital_level_name,province_id,city_id", @@ -330,6 +231,7 @@ class UserDoctor extends Model $query->where('is_enable', 1); } }, + "User:user_id,is_online" ]) ->where($doctor_params) ->when($keyword, function ($query, $keyword) { @@ -353,7 +255,7 @@ class UserDoctor extends Model if (!empty($is_search_welfare_reception)){ $params['is_enable'] = 1; } - + $query->where($params); if (!empty($is_search_welfare_reception)){ @@ -361,6 +263,14 @@ class UserDoctor extends Model } }); + if ($is_first_online == 1){ + $query->join('user as u', function ($query) { + $query->on('user_doctor.user_id', '=', 'u.user_id'); + }) + ->select("user_doctor.*") + ->orderBy('u.is_online', 'desc'); + } + if (!empty($sort_order)){ if (in_array($sort_order,[1,3,4])){ $query = $query->join('doctor_inquiry_config', function ($query) { @@ -380,29 +290,29 @@ class UserDoctor extends Model $query->orderByRaw('avg_response_time = 0 ASC'); $query->orderBy('avg_response_time'); $query->orderBy('served_patients_num', 'desc');// 服务数从多到少 - $query->orderBy(Db::raw("convert(substr(user_name,1,1) using `GBK`)"), 'asc');// 名称排名 + $query->orderBy(Db::raw("convert(substr(gdxz_user_doctor.user_name,1,1) using `GBK`)"), 'asc');// 名称排名 $query->orderBy('doctor_inquiry_config.inquiry_price', 'asc'); } elseif ($sort_order == 2) { // 响应时间快 $query->orderByRaw('avg_response_time = 0 ASC'); $query->orderBy('avg_response_time'); - $query->orderBy(Db::raw("convert(substr(user_name,1,1) using `GBK`)"), 'asc');// 名称排名 + $query->orderBy(Db::raw("convert(substr(gdxz_user_doctor.user_name,1,1) using `GBK`)"), 'asc');// 名称排名 } elseif ($sort_order == 3) { // 价格从低到高 $query->orderBy('doctor_inquiry_config.inquiry_price', 'asc'); $query->orderByRaw('avg_response_time = 0 ASC'); $query->orderBy('avg_response_time'); - $query->orderBy(Db::raw("convert(substr(user_name,1,1) using `GBK`)"), 'asc');// 名称排名 + $query->orderBy(Db::raw("convert(substr(gdxz_user_doctor.user_name,1,1) using `GBK`)"), 'asc');// 名称排名 } elseif ($sort_order == 4) { // 价格从高到低 $query->orderBy('doctor_inquiry_config.inquiry_price', 'desc'); $query->orderByRaw('avg_response_time = 0 ASC'); $query->orderBy('avg_response_time'); - $query->orderBy(Db::raw("convert(substr(user_name,1,1) using `GBK`)"), 'asc');// 名称排名 + $query->orderBy(Db::raw("convert(substr(gdxz_user_doctor.user_name,1,1) using `GBK`)"), 'asc');// 名称排名 } elseif ($sort_order == 5) { // 服务数从多到少 $query->orderBy('served_patients_num', 'desc'); - $query->orderBy(Db::raw("convert(substr(user_name,1,1) using `GBK`)"), 'asc');// 名称排名 + $query->orderBy(Db::raw("convert(substr(gdxz_user_doctor.user_name,1,1) using `GBK`)"), 'asc');// 名称排名 } } @@ -418,6 +328,62 @@ class UserDoctor extends Model return $data; } + /** + * 获取问诊医生列表 + * 专家问诊-公益问诊共用 + * @param string $keyword + * @param array $hospital_params 医院搜索条件 + * @param array $doctor_params 医生搜索条件 + * @param array $doctor_expertise_params + * @param int $is_search_welfare_reception 是否搜索公益问诊 + * @param string|int $is_first_online 是否优先在线(1:是) + * @param string|int $sort_order + * @param array $fields + * @param int|null $page + * @param int|null $per_page + * @return array + */ + public static function getInquiryDoctorPageTest(string $keyword = "", array $hospital_params = [], array $doctor_params = [], array $doctor_expertise_params = [],int $is_search_welfare_reception = 0,string|int $is_first_online = 0, string|int $sort_order = 1, array $fields = ["*"], int $page = null, ?int $per_page = 10): array + { + $doctors = UserDoctor::join('user', function ($query) { + $query->on('user_doctor.user_id', '=', 'user.user_id'); + }) + ->select("user_doctor.*") + ->orderBy('user.is_online', 'desc') + ->get(); + + dump($doctors->toArray()); + return $doctors; + +// $query = self::orderBy('served_patients_num', 'desc'); +// +// if ($is_first_online == 1){ +// $query = $query->join('user', function ($query) { +// $query->on('user_doctor.user_id', '=', 'user.user_id')s +// ->orderBy('user.is_online', 'desc'); +// }) +// ->select(['user_doctor.*','user.is_online']); +// }q + +// if (!empty($sort_order)){ +// if ($sort_order == 1) { +// // 综合-价格从低到高 +// $query->orderBy('served_patients_num', 'desc');// 服务数从多到少 +// } +// } + +// $result = $query->paginate($per_page, $fields, "page", $page); +// +// $data = array(); +// $data['current_page'] = $result->currentPage();// 当前页码 +// $data['total'] = $result->total();//数据总数 +// $data['data'] = $result->items();//数据 +// $data['per_page'] = $result->perPage();//每页个数 +// $data['last_page'] = $result->lastPage();//最后一页 + +// return $data; + } + /** * 获取是否存在 diff --git a/app/Model/UserPharmacist.php b/app/Model/UserPharmacist.php index 7034343..ea6def1 100644 --- a/app/Model/UserPharmacist.php +++ b/app/Model/UserPharmacist.php @@ -16,7 +16,6 @@ use Hyperf\Snowflake\Concern\Snowflake; * @property string $union_id 微信开放平台唯一标识 * @property string $wx_session_key 微信会话密钥 * @property int $status 状态(0:禁用 1:正常 2:删除) - * @property int $is_online 是否在线(0:不在线 1:在线) * @property string $avatar 头像 * @property int $pharmacist_title 职称 * @property int $department_custom_id 科室id-自定义 @@ -39,7 +38,7 @@ class UserPharmacist extends Model /** * The attributes that are mass assignable. */ - protected array $fillable = ['pharmacist_id', 'user_id', 'user_name', 'open_id', 'union_id', 'wx_session_key', 'status', 'is_online', 'avatar', 'pharmacist_title', 'department_custom_id', 'department_custom_name', 'department_custom_mobile', 'medical_institution', 'worker_date', 'created_at', 'updated_at']; + protected array $fillable = ['pharmacist_id', 'user_id', 'user_name', 'open_id', 'union_id', 'wx_session_key', 'status', 'avatar', 'pharmacist_title', 'department_custom_id', 'department_custom_name', 'department_custom_mobile', 'medical_institution', 'worker_date', 'created_at', 'updated_at']; protected string $primaryKey = "pharmacist_id"; diff --git a/app/Request/InquiryRequest.php b/app/Request/InquiryRequest.php index 78d8cda..9486c49 100644 --- a/app/Request/InquiryRequest.php +++ b/app/Request/InquiryRequest.php @@ -20,8 +20,6 @@ class InquiryRequest extends FormRequest 'is_allergy_history',// 过敏史 'is_family_history', // 家族病史 'is_pregnant',// 备孕、妊娠、哺乳期 - 'height', - 'weight', 'inquiry_type', // 订单类型(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药) 'inquiry_mode', // 订单问诊方式(1:图文 2:视频 3:语音 4:电话 5:会员) 'client_type', // 客户端类型(1:手机 2:电脑) diff --git a/app/Request/PatientCaseRequest.php b/app/Request/PatientCaseRequest.php new file mode 100644 index 0000000..ad7fe03 --- /dev/null +++ b/app/Request/PatientCaseRequest.php @@ -0,0 +1,58 @@ + [ // 获取问诊订单病例详情-基础 + 'order_inquiry_id', + ], + 'getPatientFamilyInquiryCase' => [ // 获取问诊订单病例详情 + 'order_inquiry_id', + ], + 'getPatientFamilyInquiryCaseUnfilledFields' => [ // 获取问诊订单病例缺少字段 + 'order_inquiry_id', + ], + 'sendCaseUnfilledFieldsToPatient' => [ // 医生发送缺少字段至患者 + 'order_inquiry_id', + ], + 'sendCaseUnfilledFieldsToDoctor' => [ // 患者填写缺少字段至医生 + 'order_inquiry_id', + ], + ]; + + /** + * Determine if the user is authorized to make this request. + */ + public function authorize(): bool + { + return true; + } + + /** + * Get the validation rules that apply to the request. + */ + public function rules(): array + { + return [ + 'order_inquiry_id' => 'required', + ]; + } + + /** + * 获取已定义验证规则的错误消息. + */ + public function messages(): array + { + return [ + 'order_inquiry_id.required' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), + ]; + } +} diff --git a/app/Request/PatientDoctorRequest.php b/app/Request/PatientDoctorRequest.php index 06fbe19..8fc12fb 100644 --- a/app/Request/PatientDoctorRequest.php +++ b/app/Request/PatientDoctorRequest.php @@ -15,7 +15,8 @@ class PatientDoctorRequest extends FormRequest 'province_id', 'city_id', 'sort_order', - 'keyword' + 'keyword', + 'is_first_online' // 是否优先在线(1:是) ], 'getDoctorInquiryCheck' => [ // 检测是否可以接诊 'inquiry_type', // 订单类型(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药) @@ -45,6 +46,7 @@ class PatientDoctorRequest extends FormRequest 'inquiry_type' => 'required|integer|min:1|max:4', 'inquiry_mode' => 'required|integer|min:1|max:5', 'my_doctor_type' => 'required|integer|min:1|max:2', + 'is_first_online' => 'integer|min:0|max:1', ]; } @@ -69,6 +71,9 @@ class PatientDoctorRequest extends FormRequest 'my_doctor_type.integer' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), 'my_doctor_type.min' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), 'my_doctor_type.max' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), + 'is_first_online.integer' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), + 'is_first_online.min' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), + 'is_first_online.max' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), ]; } } diff --git a/app/Request/PatientPathographyRequest.php b/app/Request/PatientPathographyRequest.php new file mode 100644 index 0000000..b7045f5 --- /dev/null +++ b/app/Request/PatientPathographyRequest.php @@ -0,0 +1,57 @@ + [ // 检测家庭成员是否存在病情记录 + 'family_id', + ], + 'getFamilyPathographyPage' => [ // 获取家庭成员病情记录列表-分页 + 'family_id', + ], + 'getFamilyPathographyGroup' => [ // 获取家庭成员病情记录分组 + 'family_id', + ], + ]; + + /** + * Determine if the user is authorized to make this request. + */ + public function authorize(): bool + { + return true; + } + + /** + * Get the validation rules that apply to the request. + */ + public function rules(): array + { + return [ + 'family_id' => 'required', + ]; + } + + /** + * 获取已定义验证规则的错误消息. + */ + public function messages(): array + { + return [ + 'family_id.required' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), +// 'user_coupon_status.min' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), +// 'user_coupon_status.max' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), +// 'product_id.required' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), +// +// 'shopping_cart_num.required' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), +// 'shopping_cart_num.numeric' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), +// 'shopping_cart_num.min' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), +// 'shopping_cart_num.max' => "请勿超出最大添加数量", + ]; + } +} \ No newline at end of file diff --git a/app/Services/BasicDataService.php b/app/Services/BasicDataService.php index 06c4ce0..04d6b0f 100644 --- a/app/Services/BasicDataService.php +++ b/app/Services/BasicDataService.php @@ -226,6 +226,7 @@ class BasicDataService extends BaseService $fields = [ 'product_id', 'product_platform_id', + 'prescription_num', 'product_name', 'product_price', 'product_cover_img', @@ -239,7 +240,8 @@ class BasicDataService extends BaseService ]; $params = array(); - + $params['product_status'] = 1; + $params['is_delete'] = 0; $product = Product::getSearchKeywordList($params, $product_keyword,$fields); if (empty($product)) { return success(); @@ -445,8 +447,8 @@ class BasicDataService extends BaseService ]; $params = array(); - - + $params['product_status'] = 1; + $params['is_delete'] = 0; $product = Product::getWithAmountPage($params, $keyword,$fields, $page, $per_page); if (empty($product['data'])) { return success($product); diff --git a/app/Services/DoctorAccountService.php b/app/Services/DoctorAccountService.php index cb4221e..080386d 100644 --- a/app/Services/DoctorAccountService.php +++ b/app/Services/DoctorAccountService.php @@ -28,64 +28,65 @@ class DoctorAccountService extends BaseService { $user_info = $this->request->getAttribute("userInfo") ?? []; - $date = $this->request->input('date'); + $year = $this->request->input('date'); + + $date = date('Y-m-d',time()); + + // 今日接诊收入 + $inquiryService = new InquiryService(); + $doctor_today_inquiry_total = $inquiryService->getDoctorDayAmountTotal($user_info['client_user_id'],$date); + + // 今日已完成收入 + $doctor_day_completed_amount_total = $inquiryService->getDoctorDayCompletedAmountTotal($user_info['client_user_id'],$date); // 获取医生账户余额 $balance_account = $this->getDoctorBalanceAccount($user_info['client_user_id']); - // 获取医生月度余额 - $amount_total_month = $this->getDoctorMonthAmountTotal($user_info['client_user_id'], $date); +// // 获取医生月度余额 +// $amount_total_month = $this->getDoctorMonthAmountTotal($user_info['client_user_id'], $date); +// +// // 获取医生月度已提现金额-审核通过时间为准 +// $params = array(); +// $params['doctor_id'] = $user_info['client_user_id']; +// +// $start_time = date('Y-m-01',strtotime($date)); +// $end_time = date('Y-m-t 24:00:00',strtotime($date)); +// $created_at = [$start_time,$end_time]; +// $doctor_withdrawal = DoctorWithdrawal::getOneLatestTime($params,$created_at,['*']); +// if (empty($doctor_withdrawal)) { +// $withdrawal_amount_month = 0; +// } else { +// $withdrawal_amount_month = $doctor_withdrawal['actual_withdrawal_amount']; +// } - // 获取医生月度已提现金额-审核通过时间为准 - $params = array(); - $params['doctor_id'] = $user_info['client_user_id']; - - $start_time = date('Y-m-01',strtotime($date)); - $end_time = date('Y-m-t 24:00:00',strtotime($date)); - $created_at = [$start_time,$end_time]; - $doctor_withdrawal = DoctorWithdrawal::getOneLatestTime($params,$created_at,['*']); - if (empty($doctor_withdrawal)) { - $withdrawal_amount_month = 0; - } else { - $withdrawal_amount_month = $doctor_withdrawal['actual_withdrawal_amount']; - } - - // 获取医生每日账单数据 + // 获取医生每月账单数据 $bill = []; - $fields = [ - 'total_amount', - 'month', - 'day', - ]; - $params = array(); $params['doctor_id'] = $user_info['client_user_id']; - $params['year'] = date('Y', strtotime($date)); - $params['month'] = date('m', strtotime($date)); - $doctor_account_days = DoctorAccountDay::getList($params, $fields); + $params['year'] = $year; + $doctor_account_days = DoctorAccountDay::getDoctorMonth($params); if (!empty($doctor_account_days)) { foreach ($doctor_account_days as $doctor_account_day) { $data = array(); - $data['total_amount'] = floor($doctor_account_day['total_amount'] * 100) / 100; + $data['total_amount'] = bcmul($doctor_account_day['total_amount'],1,2); $data['month'] = $doctor_account_day['month']; - $data['day'] = $doctor_account_day['day']; $bill[] = $data; } unset($doctor_account_days); } $result = array(); - $result['balance_account'] = floor($balance_account * 100) / 100;; // 账户余额 - $result['amount_total_month'] = floor($amount_total_month * 100) / 100; // 月余额 - $result['withdrawal_amount_month'] = floor($withdrawal_amount_month * 100) / 100; // 月已提现金额 + $result['doctor_today_inquiry_total'] = bcmul($doctor_today_inquiry_total,0.75,2); // 今日接诊收入 + $result['doctor_day_completed_amount_total'] = bcmul($doctor_day_completed_amount_total ,0.75,2); // 今日已完成收入 + $result['balance_account'] = bcmul($balance_account ,1,2); // 账户余额 $result['bill'] = $bill; // 账单 return success($result); } /** - * 获取我的账户日账单明细数据 + * 获取我的账户月账单明细数据 * @return array */ public function getDoctorAccountInfo(): array @@ -96,11 +97,12 @@ class DoctorAccountService extends BaseService $page = $this->request->input('page', 1); $per_page = $this->request->input('per_page', 10); - // 获取当天开始时间 - $start_date = date('Y-m-d 00:00:00', strtotime($date)); + // 获取当月开始时间 + $start_date = date('Y-m-01 00:00:00', strtotime($date)); - // 获取当天结束时间 - $end_date = date('Y-m-d 23:59:59', strtotime($date)); + // 获取当月结束时间 + // 获取给定月份的下一个月的第一天,然后减去一天得到当月的最后一天 + $end_date = date("Y-m-d 23:59:59", strtotime("+1 month", strtotime($start_date)) - 1); $reception_time = [$start_date, $end_date]; @@ -119,18 +121,32 @@ class DoctorAccountService extends BaseService 'patient_name', 'patient_sex', 'patient_age', + 'cancel_reason', + 'cancel_remarks', 'created_at', ]; $params = array(); $params['doctor_id'] = $user_info['client_user_id']; - $params['inquiry_status'] = 6; // inquiry_status:问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消) - $params['inquiry_refund_status'] = 0; // inquiry_refund_status:问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭) - - $order_inquiry = OrderInquiry:: getDoctorCreatedDateOrderInquiryPage($params, $reception_time, $fields,$page,$per_page); + $inquiry_status_params = [4,5,6,7]; // 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消) + $order_inquiry = OrderInquiry:: getDoctorCreatedDateOrderInquiryPage($params, $reception_time, $inquiry_status_params,$fields,$page,$per_page); if (!empty($order_inquiry['data'])) { foreach ($order_inquiry['data'] as &$item) { - $item['estimate_income'] = floor($item['amount_total'] * 0.75 * 100) / 100; + $item['estimate_income'] = bcmul($item['amount_total'],0.75,2); + + // 入账状态 + if ($item['inquiry_status'] == 4 || $item['inquiry_status'] == 5){ + $item['entry_status'] = 1;// 入账中 + }elseif ($item['inquiry_status'] == 6){ + $item['entry_status'] = 2;// 入账成功 + }elseif ($item['inquiry_status'] == 7){ + $item['entry_status'] = 3;// 入账失败 + if (!empty($item['cancel_reason'])){ + $item['cancel_reason'] = inquiryCancelReasonToPushString($item['cancel_reason']); + } + }else{ + $item['entry_status'] = 0;// 未知 + } } } @@ -230,18 +246,19 @@ class DoctorAccountService extends BaseService } } - $amount_total = $amount_total * 0.75; + $amount_total = bcmul($amount_total,0.75,2); // 计算医生个人所得税 $income_tax = $this->computeIndividualIncomeTax($amount_total); - $withdrawal_amount = floor(($amount_total - $income_tax) * 100) / 100; + $withdrawal_amount = bcsub($amount_total,$income_tax,2); - $income_tax = floor($income_tax * 100) / 100; + $income_tax = bcmul($income_tax,1,2); $result = array(); $result['bank'] = $bank;//银行数据 + $result['amount_total'] = $amount_total; // 账户余额 $result['withdrawal_amount'] = $withdrawal_amount; // 提现金额 $result['income_tax'] = $income_tax; // 个人所得税 $result['order_inquiry_ids'] = $order_inquiry_id_array; // 订单合集 diff --git a/app/Services/ImService.php b/app/Services/ImService.php index f7c4dc8..2b9680c 100644 --- a/app/Services/ImService.php +++ b/app/Services/ImService.php @@ -775,4 +775,87 @@ class ImService extends BaseService throw new BusinessException($e->getMessage()); } } + + /** + * 问诊表-发送患者 + * @param array|object $order_inquiry 问诊表数据 + * @param string|int $doctor_user_id 医生用户id + * @param string|int $patient_user_id 患者用户id + * @param string $case_fields 医生选择需填写的病例字段 + * @return void + */ + public function CaseUnfilledFieldsToPatient(array|object $order_inquiry,string|int $doctor_user_id,string|int $patient_user_id,string $case_fields): void + { + try { + // 发送消息 + $cloud_custom_data = array(); + $cloud_custom_data['order_inquiry_id'] = $order_inquiry['order_inquiry_id']; + $cloud_custom_data['is_system'] = 1; + $cloud_custom_data['inquiry_type'] = $order_inquiry['inquiry_type']; + $cloud_custom_data['message_rounds'] = 0; + $cloud_custom_data['patient_family_data']['patient_name'] = $order_inquiry['patient_name']; + $cloud_custom_data['patient_family_data']['patient_sex'] = $order_inquiry['patient_sex']; + $cloud_custom_data['patient_family_data']['patient_age'] = $order_inquiry['patient_age']; + + // 消息内容 + $message_content_data = array(); + $message_content_data['message_type'] = 12; + $message_content_data['title'] = "问诊表"; + $message_content_data['desc'] = ""; + $message_content_data['data']['order_inquiry_id'] = $order_inquiry['order_inquiry_id']; + $message_content_data['data']['order_no'] = $order_inquiry['inquiry_no']; + $message_content_data['data']['message_path'] = "/pages/sickForm/sickForm"; // 跳转地址(小程序内页) + $message_content_data['data']['case_not_fill_fields'] = $case_fields; // 病例字段,json格式,医生端发送患者端使用(此字段仅针对message_type为12的情况) + $message_content = [ + 'Data' => json_encode($message_content_data, JSON_UNESCAPED_UNICODE), + ]; + + $this->sendMessage($doctor_user_id, $patient_user_id, $message_content, "TIMCustomElem", $cloud_custom_data); + + } catch (\Throwable $e) { + throw new BusinessException($e->getMessage()); + } + } + + /** + * 问诊表-发送医生 + * @param array|object $order_inquiry 问诊表数据 + * @param string|int $doctor_user_id 医生用户id + * @param string|int $patient_user_id 患者用户id + * @param string $case_fields 患者填写的病例字段 + * @return void + */ + public function CaseUnfilledFieldsToDoctor(array|object $order_inquiry,string|int $doctor_user_id,string|int $patient_user_id,string $case_fields): void + { + try { + // 发送消息 + $cloud_custom_data = array(); + $cloud_custom_data['order_inquiry_id'] = $order_inquiry['order_inquiry_id']; + $cloud_custom_data['is_system'] = 1; + $cloud_custom_data['inquiry_type'] = $order_inquiry['inquiry_type']; + $cloud_custom_data['message_rounds'] = 0; + $cloud_custom_data['patient_family_data']['patient_name'] = $order_inquiry['patient_name']; + $cloud_custom_data['patient_family_data']['patient_sex'] = $order_inquiry['patient_sex']; + $cloud_custom_data['patient_family_data']['patient_age'] = $order_inquiry['patient_age']; + + // 消息内容 + $message_content_data = array(); + $message_content_data['message_type'] = 12; + $message_content_data['title'] = "问诊表-已填写"; + $message_content_data['desc'] = ""; + $message_content_data['data']['order_inquiry_id'] = $order_inquiry['order_inquiry_id']; + $message_content_data['data']['order_no'] = $order_inquiry['inquiry_no']; + $message_content_data['data']['message_path'] = "/Pages/yishi/sick_detail/index"; // 跳转地址(小程序内页) + $message_content_data['data']['case_patient_message_path'] = "/pages/sickDetail/sickDetail"; // 跳转地址(小程序内页) + $message_content_data['data']['case_filled_fields'] = $case_fields; // 病例字段,json格式,患者端发送医生端使用(此字段仅针对message_type为12的情况) + $message_content = [ + 'Data' => json_encode($message_content_data, JSON_UNESCAPED_UNICODE), + ]; + + $this->sendMessage($patient_user_id, $doctor_user_id, $message_content, "TIMCustomElem", $cloud_custom_data); + + } catch (\Throwable $e) { + throw new BusinessException($e->getMessage()); + } + } } \ No newline at end of file diff --git a/app/Services/IndexService.php b/app/Services/IndexService.php index da99fa0..a2b2517 100644 --- a/app/Services/IndexService.php +++ b/app/Services/IndexService.php @@ -332,7 +332,6 @@ class IndexService extends BaseService "user_name", "status", "avatar", - "is_online", ]; $user_pharmacist = UserPharmacist::getOne($params,$fields); @@ -350,6 +349,16 @@ class IndexService extends BaseService $user_pharmacist['avatar'] = addAliyunOssWebsite($user_pharmacist['avatar']); + // 获取用户数据 + $params = array(); + $params['user_id'] = $user_pharmacist['user_id']; + $user = User::getOne($params); + if (empty($user)){ + return fail(); + } + + $user_pharmacist['is_online'] = $user['is_online']; + // 获取药师审方数量 $params = array(); $params['pharmacist_id'] = $user_pharmacist['pharmacist_id']; diff --git a/app/Services/InquiryService.php b/app/Services/InquiryService.php index 0e7f9de..b4051b2 100644 --- a/app/Services/InquiryService.php +++ b/app/Services/InquiryService.php @@ -80,6 +80,16 @@ class InquiryService extends BaseService return fail(HttpEnumCode::HTTP_ERROR, "患者信息错误"); } + // 获取患者家庭成员信息表-健康情况 + $params = array(); + $params['family_id'] = $request_params['family_id']; + $patient_family_health = PatientFamilyHealth::getOne($params); + + // 获取患者家庭成员信息表-个人情况 + $params = array(); + $params['family_id'] = $request_params['family_id']; + $patient_family_personal = PatientFamilyPersonal::getOne($params); + // 检测是否存在同类型未完成的问诊订单 $PatientOrderService = new PatientOrderService(); $order_inquiry_id = $PatientOrderService->getNotFinishedOrderInquiry($request_params['inquiry_type'], $user_info['client_user_id']); @@ -90,7 +100,7 @@ class InquiryService extends BaseService return success($result); } - // 是否为孕妇 + // 是否备孕、妊娠、哺乳期(0:否 1:是) if ($request_params['is_pregnant'] == 1) { return fail(HttpEnumCode::HTTP_ERROR, "请您到线下问诊"); } @@ -174,6 +184,13 @@ class InquiryService extends BaseService $inquiry_pay_channel = 2; } + // 处理复诊凭证 + if (!empty($request_params['diagnose_images'])) { + // 医师资格证 + $diagnose_images = implode(',', $request_params['diagnose_images']); + $diagnose_images = PcreMatch::pregRemoveOssWebsite($diagnose_images); + } + Db::beginTransaction(); $generator = $this->container->get(IdGeneratorInterface::class); @@ -214,13 +231,6 @@ class InquiryService extends BaseService return fail(HttpEnumCode::SERVER_ERROR, "订单创建失败"); } - // 处理复诊凭证 - if (!empty($request_params['diagnose_images'])) { - // 医师资格证 - $diagnose_images = implode(',', $request_params['diagnose_images']); - $diagnose_images = PcreMatch::pregRemoveOssWebsite($diagnose_images); - } - // 增加患者问诊病例 $data = array(); $data['user_id'] = $user_info['user_id']; @@ -229,37 +239,121 @@ class InquiryService extends BaseService $data['family_id'] = $patient_family['family_id']; // 家庭成员id $data['relation'] = $patient_family['relation']; // 与患者关系(1:本人 2:父母 3:爱人 4:子女 5:亲戚 6:其他 ) $data['name'] = $patient_family['card_name']; // 患者名称 - $data['sex'] = $patient_family['sex'] ?? 0; // 患者性别(0:未知 1:男 2:女) - $data['age'] = $patient_family['age'] ?? null; // 患者年龄 - $data['height'] = $request_params['height'] ?? $patient_family['height'] ?: null; // 身高(cm) - $data['weight'] = $request_params['weight'] ?? $patient_family['weight'] ?: null;; // 体重(kg) + $data['sex'] = $patient_family['sex']; // 患者性别(0:未知 1:男 2:女) $data['disease_class_id'] = $disease_class['disease_class_id']; // 疾病分类id-系统 $data['disease_class_name'] = $disease_class['disease_class_name']; // 疾病名称-系统 - $data['diagnosis_date'] = $request_params['diagnosis_date'] ?: null; // 确诊日期 - $data['disease_desc'] = $request_params['disease_desc'] ?: null; // 病情描述(主诉) + $data['diagnosis_date'] = $request_params['diagnosis_date']; // 确诊日期 + $data['disease_desc'] = $request_params['disease_desc']; // 病情描述(主诉) $data['diagnose_images'] = $diagnose_images ?? ""; // 复诊凭证(多个使用逗号分隔) - if (isset($request_params['is_allergy_history'])) { + + if ($patient_family['age'] != null){ + $data['age'] = $patient_family['age'];// 患者年龄 + } + + // 身高(cm) + if ($patient_family['height'] != null){ + $data['height'] = $patient_family['height']; + } + + // 体重(kg) + if ($patient_family['weight'] != null){ + $data['weight'] = $patient_family['weight']; + } + + // 职业id-职业名称 + if ($patient_family['job_id'] != null){ + $data['job_id'] = $patient_family['job_id']; + if ($patient_family['job_name'] != null){ + $data['job_name'] = $patient_family['job_name']; + } + } + + // 民族id-民族名称 + if ($patient_family['nation_id'] != null){ + $data['nation_id'] = $patient_family['nation_id']; + if ($patient_family['nation_name'] != null){ + $data['nation_name'] = $patient_family['nation_name']; + } + } + + // 婚姻状况 + if ($patient_family['marital_status'] != null){ + $data['marital_status'] = $patient_family['marital_status']; + } + + // 家庭成员-健康情况 + if (!empty($patient_family_health)){ + if ($patient_family_health['diagnosis_hospital'] != null){ + $data['diagnosis_hospital'] = $patient_family_health['diagnosis_hospital']; // 确诊医院 + } + + if ($patient_family_health['is_take_medicine'] != null){ + $data['is_take_medicine'] = $patient_family_health['is_take_medicine']; // 正在服药 + if ($patient_family_health['drugs_name'] != null){ + $data['drugs_name'] = $patient_family_health['drugs_name']; // 正在服药名称 + } + } + } + + // 家庭成员-个人情况 + if (!empty($patient_family_personal)){ + if ($patient_family_personal['drink_wine_status'] != null){ + $data['drink_wine_status'] = $patient_family_personal['drink_wine_status']; // 饮酒状态 + } + + if ($patient_family_personal['smoke_status'] != null){ + $data['smoke_status'] = $patient_family_personal['smoke_status']; // 吸烟状态 + } + + if ($patient_family_personal['chemical_compound_status'] != null){ + $data['chemical_compound_status'] = $patient_family_personal['chemical_compound_status']; // 化合物状态 + if ($patient_family_personal['chemical_compound_describe'] != null){ + $data['chemical_compound_describe'] = $patient_family_personal['chemical_compound_describe']; // 化合物描述 + } + } + + if ($patient_family_personal['is_operation'] != null){ + $data['is_operation'] = $patient_family_personal['is_operation']; // 是否存在手术 + if ($patient_family_personal['operation'] != null){ + $data['operation'] = $patient_family_personal['operation']; // 手术描述 + } + } + } + + // 过敏史 + if (array_key_exists("is_allergy_history",$request_params)){ if ($request_params['is_allergy_history'] !== null) { $data['is_allergy_history'] = $request_params['is_allergy_history']; // 是否存在过敏史(0:否 1:是) + if ($request_params['allergy_history'] != ""){ + $data['allergy_history'] = $request_params['allergy_history']; // 过敏史描述 + } } } - $data['allergy_history'] = $request_params['allergy_history'] ?? null; // 过敏史描述 - if (isset($request_params['is_family_history'])) { + + // 家族病史 + if (array_key_exists("is_family_history",$request_params)){ if ($request_params['is_family_history'] !== null) { $data['is_family_history'] = $request_params['is_family_history']; // 是否存在家族病史(0:否 1:是) + if ($request_params['family_history'] != ""){ + $data['family_history'] = $request_params['family_history']; // 家族病史描述 + } } } - $data['family_history'] = $request_params['family_history'] ?? null; // 家族病史描述 - if (isset($request_params['is_pregnant'])) { + + // 是否备孕、妊娠、哺乳期(0:否 1:是) + if (array_key_exists("is_pregnant",$request_params)){ if ($request_params['is_pregnant'] !== null) { $data['is_pregnant'] = $request_params['is_pregnant']; // 是否备孕、妊娠、哺乳期(0:否 1:是) } } - if (isset($request_params['is_taboo'])) { + + // 是否存在禁忌药物(0:否 1:是)问诊购药时存在 + if (array_key_exists("is_taboo",$request_params)){ if ($request_params['is_taboo'] !== null) { $data['is_taboo'] = $request_params['is_taboo']; // 是否存在禁忌药物(0:否 1:是)问诊购药时存在 } } + $order_inquiry_case = OrderInquiryCase::addOrderInquiryCase($data); if (empty($order_inquiry_case)) { Db::rollBack(); @@ -827,6 +921,7 @@ class InquiryService extends BaseService $result['patient_user_id'] = $order_inquiry['user_id']; $result['doctor_id'] = $order_inquiry['doctor_id']; $result['patient_id'] = $order_inquiry['patient_id']; + $result['family_id'] = $order_inquiry['family_id']; $result['order_inquiry_id'] = $order_inquiry['order_inquiry_id']; $result['patient_family_name'] = $order_inquiry['patient_name']; $result['patient_family_sex'] = $order_inquiry['patient_sex']; @@ -996,7 +1091,6 @@ class InquiryService extends BaseService $message = new AutoFinishInquiryDelayDirectProducer($data); $message->setDelayMs(1000 * 60 * 60 * 24 * 3); -// $message->setDelayMs(1000 * 60 * 2); $producer = $this->container->get(Producer::class); $res = $producer->produce($message); if (!$res) { @@ -1006,7 +1100,7 @@ class InquiryService extends BaseService Db::commit(); } catch (\Exception $e) { Db::rollBack(); - Log::getInstance()->error("错误:" . $e->getMessage()); + Log::getInstance("InquiryService-putFinishInquiry")->error($e->getMessage()); return fail(HttpEnumCode::SERVER_ERROR, $e->getMessage()); } @@ -1025,8 +1119,8 @@ class InquiryService extends BaseService // 患者-发送通知消息-患者的问诊服务结束 $MessagePush = new MessagePush($order_inquiry['user_id'], $order_inquiry['order_inquiry_id']); $MessagePush->patientInquiryFinish(); - } catch (\Exception $e) { - return success([], HttpEnumCode::HTTP_SUCCESS, "消息发送失败"); + } catch (\Throwable $e) { + Log::getInstance("InquiryService-putFinishInquiry")->error($e->getMessage()); } return success(); @@ -1111,7 +1205,7 @@ class InquiryService extends BaseService /** * 获取医生当日接诊的订单金额 - * 状态:已接诊-已完成 + * 状态:已接诊 * @param string $doctor_id * @param string $date * @return float @@ -1133,7 +1227,38 @@ class InquiryService extends BaseService $reception_time = [$start_date, $end_date]; - $inquiry_status_params = [4, 5]; // 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消) + $inquiry_status_params = [4,5]; // 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消) + + $amount_total_sum = OrderInquiry::getOrderInquiryBetweenTimeAmountTotalSum($params, $reception_time, $inquiry_status_params); + + return $amount_total_sum ?: 0; + } + + /** + * 获取医生当日已完成未结束的订单金额 + * 状态:已完成 + * @param string $doctor_id + * @param string $date + * @return float + */ + public function getDoctorDayCompletedAmountTotal(string $doctor_id, string $date): float + { + // 获取当天开始时间 + $start_date = date('Y-m-d 00:00:00', strtotime($date)); + + // 获取当天结束时间 + $end_date = date('Y-m-d 23:59:59', strtotime($date)); + + // 获取医生当日接诊订单金额 + $params = array(); + $params['doctor_id'] = $doctor_id; + $params['inquiry_refund_status'] = 0; // 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭) + $params['inquiry_pay_status'] = 2; // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款) + $params['is_withdrawal'] = 0; // 是否提现(0:否 1:是 2:提现中) + + $reception_time = [$start_date, $end_date]; + + $inquiry_status_params = [5]; // 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消) $amount_total_sum = OrderInquiry::getOrderInquiryBetweenTimeAmountTotalSum($params, $reception_time, $inquiry_status_params); diff --git a/app/Services/LoginService.php b/app/Services/LoginService.php index 54a374a..d78bd84 100644 --- a/app/Services/LoginService.php +++ b/app/Services/LoginService.php @@ -38,22 +38,32 @@ class LoginService extends BaseService $wx_code = $this->request->input('wx_code'); $user_type = $this->request->input('user_type'); + // 获取微信用户数据 try { $weChat = new Wechat($user_type); // 获取手机号 $phone_info = $weChat->getPhone($phone_code); - if (empty($phone_info) || empty($phone_info['phone_info']) || empty($phone_info['phone_info']['purePhoneNumber'])) { + if (empty($phone_info)){ + return fail(HttpEnumCode::GET_WX_ERROR); + } + + if (empty($phone_info['phone_info']) || empty($phone_info['phone_info']['purePhoneNumber'])) { return fail(HttpEnumCode::GET_WX_ERROR); } // 获取用户openid $wx_info_data = $weChat->codeToSession($wx_code); + if (empty($wx_info_data)){ + return fail(HttpEnumCode::GET_WX_ERROR); + } + if (empty($wx_info_data['session_key']) || empty($wx_info_data['openid'])) { return fail(HttpEnumCode::GET_WX_ERROR); } }catch (\Throwable $e){ + Log::getInstance("LoginService-wechatMobileLogin")->error($e->getMessage()); return fail(HttpEnumCode::GET_WX_ERROR); } @@ -86,10 +96,8 @@ class LoginService extends BaseService $data['mobile'] = $phone_info['phone_info']['purePhoneNumber']; $data['wx_mobile'] = $phone_info['phone_info']['purePhoneNumber']; $data['user_type'] = $user_type; - $data['register_method'] = 1;//注册方式(1:小程序授权 2:手机号 ) + $data['register_method'] = 1;// 注册方式(1:小程序授权 2:手机号) $data['avatar'] = $avatar; - $data['login_ip'] = (new Http())->getIp() ?? "";// 登陆ip - $data['last_login_at'] = date('Y-m-d H:i:s', time());// 最后登陆时间 $user = UserModel::addUser($data); if (empty($user)) { Db::rollBack(); @@ -285,7 +293,7 @@ class LoginService extends BaseService $data = array(); $data['login_ip'] = $login_ip ?? ""; - $data['last_login_at'] = date('Y-m-d H:i:s', time()); + $data['login_at'] = date('Y-m-d H:i:s', time()); UserModel::editUser($params, $data); @@ -379,8 +387,6 @@ class LoginService extends BaseService $data['user_type'] = $user_type; $data['register_method'] = 2; $data['avatar'] = $avatar; - $data['login_ip'] = (new Http())->getIp() ?? "";// 登陆ip - $data['last_login_at'] = date('Y-m-d H:i:s', time());// 最后登陆时间 $user = UserModel::addUser($data); if (empty($user)) { Db::rollBack(); @@ -582,7 +588,7 @@ class LoginService extends BaseService $data = array(); $data['login_ip'] = $login_ip ?? ""; - $data['last_login_at'] = date('Y-m-d H:i:s', time()); + $data['login_at'] = date('Y-m-d H:i:s', time()); UserModel::editUser($params, $data); // 组合生成token的数据 diff --git a/app/Services/MessagePush.php b/app/Services/MessagePush.php index 4eaa234..8f9706d 100644 --- a/app/Services/MessagePush.php +++ b/app/Services/MessagePush.php @@ -1177,7 +1177,7 @@ class MessagePush extends BaseService $data['notice_brief_title'] = "{$this->order_inquiry['patient_name']}患者的问诊您还未接诊,请及时处理。"; $data['notice_title'] = "{$this->order_inquiry['patient_name']}患者的问诊您还未接诊,请及时处理。"; $data['notice_content'] = "{$this->order_inquiry['patient_name']}患者的问诊您还未接诊,请及时处理。"; - $data['link_type'] = 3; // 问诊消息列表页 + $data['link_type'] = 3; // 问诊消息列表页. $link_params = array(); $link_params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id']; diff --git a/app/Services/PatientCaseService.php b/app/Services/PatientCaseService.php new file mode 100644 index 0000000..d666f6f --- /dev/null +++ b/app/Services/PatientCaseService.php @@ -0,0 +1,633 @@ +request->input('order_inquiry_id'); + + // 获取订单数据 + $params = array(); + $params['order_inquiry_id'] = $order_inquiry_id; + $order_inquiry = OrderInquiry::getOne($params); + if (empty($order_inquiry)) { + return fail(); + } + + // 获取病例信息 + $params = array(); + $params['order_inquiry_id'] = $order_inquiry_id; + $params['status'] = 1; + $order_inquiry_case = OrderInquiryCase::getOne($params); + if (empty($order_inquiry_case)) { + return fail(); + } + + $result = array(); + $result['patient_name'] = $order_inquiry['patient_name']; + $result['patient_sex'] = $order_inquiry['patient_sex']; + $result['patient_age'] = $order_inquiry['patient_age']; + $result['disease_desc'] = $order_inquiry_case['disease_desc']; + $result['reception_time'] = $order_inquiry['reception_time']; // 接诊时间 + + return success($result); + } + + /** + * 获取问诊订单病例详情 + * @return array + */ + public function getPatientFamilyInquiryCase(): array + { + $user_info = $this->request->getAttribute("userInfo") ?? []; + $order_inquiry_id = $this->request->input('order_inquiry_id'); + + // 获取订单数据 + $params = array(); + $params['order_inquiry_id'] = $order_inquiry_id; + $order_inquiry = OrderInquiry::getOne($params); + if (empty($order_inquiry)) { + return fail(); + } + + // 获取病例信息 + $params = array(); + $params['order_inquiry_id'] = $order_inquiry_id; + $params['status'] = 1; + $order_inquiry_case = OrderInquiryCase::getOne($params); + if (empty($order_inquiry_case)) { + return fail(); + } + + $order_inquiry_case = $order_inquiry_case->toArray(); + +// // 获取患者家庭成员信息表-基本信息 +// $params = array(); +// $params['family_id'] = $order_inquiry_case['family_id']; +// $patient_family = PatientFamily::getOne($params); +// if (!empty($patient_family)){ +// $order_inquiry_case['height'] = $order_inquiry_case['height'] ?: $patient_family['height'] ?: NULL; +// $order_inquiry_case['weight'] = $order_inquiry_case['weight'] ?: $patient_family['weight'] ?: NULL; +// $order_inquiry_case['job_id'] = $order_inquiry_case['job_id'] ?: $patient_family['job_id'] ?: NULL; +// $order_inquiry_case['job_name'] = $order_inquiry_case['job_name'] ?: $patient_family['job_name'] ?: NULL; +// $order_inquiry_case['nation_id'] = $order_inquiry_case['nation_id'] ?: $patient_family['nation_id'] ?: NULL; +// $order_inquiry_case['nation_name'] = $order_inquiry_case['nation_name'] ?: $patient_family['nation_name'] ?: NULL; +// $order_inquiry_case['marital_status'] = $order_inquiry_case['marital_status'] ?: $patient_family['marital_status'] ?: NULL; +// } +// +// // 获取患者家庭成员信息表-健康情况 +// $params = array(); +// $params['family_id'] = $order_inquiry_case['family_id']; +// $patient_family_health = PatientFamilyHealth::getOne($params); +// if (!empty($patient_family_health)) { +// $order_inquiry_case['diagnosis_hospital'] = $order_inquiry_case['diagnosis_hospital'] ?: $patient_family_health['diagnosis_hospital'] ?: ""; +// $order_inquiry_case['is_take_medicine'] = $order_inquiry_case['is_take_medicine'] ?: $patient_family_health['is_take_medicine'] ?: null; +// $order_inquiry_case['drugs_name'] = $order_inquiry_case['drugs_name'] ?: $patient_family_health['drugs_name'] ?: ""; +// } +// +// // 获取患者家庭成员信息表-个人情况 +// $params = array(); +// $params['family_id'] = $order_inquiry_case['family_id']; +// $patient_family_personal = PatientFamilyPersonal::getOne($params); +// if (!empty($patient_family_personal)) { +// $order_inquiry_case['drink_wine_status'] = $order_inquiry_case['drink_wine_status'] ?: $patient_family_personal['drink_wine_status'] ?: null; +// $order_inquiry_case['smoke_status'] = $order_inquiry_case['smoke_status'] ?: $patient_family_personal['smoke_status'] ?: null; +// $order_inquiry_case['chemical_compound_status'] = $order_inquiry_case['chemical_compound_status'] ?: $patient_family_personal['chemical_compound_status'] ?: null; +// $order_inquiry_case['chemical_compound_describe'] = $order_inquiry_case['chemical_compound_describe'] ?: $patient_family_personal['chemical_compound_describe'] ?: ""; +// $order_inquiry_case['is_operation'] = $order_inquiry_case['is_operation'] ?: $patient_family_personal['is_operation'] ?: null; +// $order_inquiry_case['operation'] = $order_inquiry_case['operation'] ?: $patient_family_personal['operation'] ?: ""; +// } + + // 获取用药意向 + $product = []; + $fields = [ + 'inquiry_case_id', + 'product_id', + 'case_product_num', + ]; + $params = array(); + $params['inquiry_case_id'] = $order_inquiry_case['inquiry_case_id']; + $inquiry_case_product = InquiryCaseProduct::getWithProductList($params, $fields); + if (!empty($inquiry_case_product)) { + foreach ($inquiry_case_product as &$item) { + if (!empty($item['Product'])) { + $product[] = $item['Product']['product_name'] . ' ' . $item['Product']['product_spec'] . '(' . $item['case_product_num'] . $item['Product']['packaging_unit'] . ')'; + } + } + } + + $order_inquiry_case['product'] = $product; + unset($inquiry_case_product); + + // 复诊凭证 + if (!empty($order_inquiry_case['diagnose_images'])) { + $diagnose_images = explode(',', $order_inquiry_case['diagnose_images']); + foreach ($diagnose_images as &$item) { + $item = addAliyunOssWebsite($item); + } + + $order_inquiry_case['diagnose_images'] = $diagnose_images; + } + + // 检测项目 + $order_inquiry_case['detection_project'] = null; + if ($order_inquiry['inquiry_type'] == 5) { + // 获取检测订单 + $params = array(); + $params['order_inquiry_id'] = $order_inquiry['order_inquiry_id']; + $order_detection = OrderDetection::getOne($params); + if (!empty($order_detection)) { + // 获取检测项目 + $params = array(); + $params['detection_project_id'] = $order_detection['detection_project_id']; + $detection_project = DetectionProject::getOne($params); + if (!empty($detection_project)) { + $order_inquiry_case['detection_project']['detection_project_name'] = $detection_project['detection_project_name']; // 检测项目名称 + $order_inquiry_case['detection_project']['detection_time'] = $order_detection['detection_time']; // 检测时间 + $order_inquiry_case['detection_project']['detection_link'] = addAliyunOssWebsite($order_detection['detection_result_pdf']); // 检测结果链接 + } + } + } + + // 获取处方数据 + $order_inquiry_case['order_prescription'] = null; + + $params = array(); + $params['order_inquiry_id'] = $order_inquiry['order_inquiry_id']; + $order_prescription = OrderPrescription::getOne($params); + if (!empty($order_prescription)){ + $order_inquiry_case['order_prescription']['doctor_created_time'] = $order_prescription['doctor_created_time']; // 医生开具处方时间 + $order_inquiry_case['order_prescription']['doctor_advice'] = $order_prescription['doctor_advice'];// 医嘱 + + // 获取处方疾病数据 + $params = array(); + $params['order_prescription_id'] = $order_prescription['order_prescription_id']; + $order_prescription_icds = OrderPrescriptionIcd::getList($params); + if (empty($order_prescription_icds)){ + return fail(); + } + + $icd_name = array_column($order_prescription_icds->toArray(),"icd_name"); + $order_inquiry_case['order_prescription']['icd_name'] = implode(";",$icd_name); + + // 获取处方药品名称 + $params = array(); + $params['order_prescription_id'] = $order_prescription['order_prescription_id']; + $order_prescription_products = OrderPrescriptionProduct::getList($params); + if (empty($order_prescription_products)){ + return fail(); + } + + $order_inquiry_case['order_prescription']["product"] = $order_prescription_products->toArray(); + } + + return success($order_inquiry_case); + } + + /** + * 获取问诊订单病例缺少字段 + * @return array + */ + public function getPatientFamilyInquiryCaseUnfilledFields(): array + { + $user_info = $this->request->getAttribute("userInfo") ?? []; + $order_inquiry_id = $this->request->input('order_inquiry_id'); + + if ($user_info['user_type'] != 2){ + return fail(HttpEnumCode::HTTP_ERROR,"非法请求"); + } + + // 获取订单数据 + $params = array(); + $params['order_inquiry_id'] = $order_inquiry_id; + $order_inquiry = OrderInquiry::getOne($params); + if (empty($order_inquiry)) { + return fail(); + } + + // 获取病例信息 + $params = array(); + $params['order_inquiry_id'] = $order_inquiry_id; + $params['status'] = 1; + $order_inquiry_case = OrderInquiryCase::getOne($params); + if (empty($order_inquiry_case)) { + return fail(); + } + + $order_inquiry_case = $order_inquiry_case->toArray(); + + // 初始字段定义 + $fields = [ + "relation", // 与患者关系(1:本人 2:父母 3:爱人 4:子女 5:亲戚 6:其他 ) + "name", // 患者名称 + "sex", // 患者性别(0:未知 1:男 2:女) + "age", // 患者年龄 + "height", // 身高(cm) + "weight", // 体重(kg) + "marital_status", // 婚姻状况(0:未婚 1:已婚 2:离异) + "nation_id", // 民族名称 + "job_id", // 职业名称 + "is_allergy_history", // 是否存在过敏史(0:否 1:是) + "is_family_history", // 是否存在家族病史(0:否 1:是) + "is_pregnant", // 是否备孕、妊娠、哺乳期(0:否 1:是) + "is_operation", // 是否存在手术(0:否 1:是) + "drink_wine_status", // 饮酒状态(1:从不 2:偶尔 3:经常 4:每天 5:已戒酒) + "smoke_status", // 吸烟状态(1:从不 2:偶尔 3:经常 4:每天 5:已戒烟) + "chemical_compound_status", // 化合物状态(1:从不 2:偶尔 3:经常 4:每天) + "diagnosis_hospital", // 确诊医院 + "is_take_medicine", // 正在服药(0:否 1:是) + ]; + + try { + /** + * 获取缓存 + * 缓存格式 + * { + "height":{ + "value":1, + "is_filled":1 + }, + "weight":{ + "value":1, + "is_filled":1 + } + * } + */ + $redis = $this->container->get(Redis::class); + $redis_key = "patient_family_inquiry_case_unfilled_fields_" . $order_inquiry_id; + $redis_value = $redis->get($redis_key); + + // 缓存 + if (!empty($redis_value)){ + $redis_value = json_decode($redis_value,true); + } + + }catch (\Throwable $e){ + return fail(); + } + + // 处理字段 + $result = null; + foreach ($fields as $field){ + if (array_key_exists($field,$order_inquiry_case)){ + if ($order_inquiry_case[$field] !== null){ + continue; + } + } + + // 缓存 + if (!empty($redis_value)){ + if (array_key_exists($field,$redis_value)){ + continue; + } + } + + $result[] = $field; + } + + return success($result); + } + + /** + * 医生发送缺少字段至患者 + * @return array + */ + public function sendCaseUnfilledFieldsToPatient(): array + { + $user_info = $this->request->getAttribute("userInfo") ?? []; + if ($user_info['user_type'] != 2){ + return fail(HttpEnumCode::HTTP_ERROR,"非法请求"); + } + + $request_params = $this->request->all(); + + $order_inquiry_id = $request_params['order_inquiry_id']; + + if (empty($request_params['fields'])){ + return fail(HttpEnumCode::CLIENT_HTTP_ERROR,"请选择需要发送的信息"); + } + + // 获取订单数据 + $params = array(); + $params['order_inquiry_id'] = $order_inquiry_id; + $order_inquiry = OrderInquiry::getOne($params); + if (empty($order_inquiry)) { + return fail(HttpEnumCode::HTTP_ERROR,"订单数据错误"); + } + + // 获取医生数据 + $params = array(); + $params['doctor_id'] = $order_inquiry['doctor_id']; + $doctor = UserDoctor::getOne($params); + if (empty($doctor)){ + return fail(); + } + + // 初始字段定义 + $fields = [ + "relation", // 与患者关系(1:本人 2:父母 3:爱人 4:子女 5:亲戚 6:其他 ) + "name", // 患者名称 + "sex", // 患者性别(0:未知 1:男 2:女) + "age", // 患者年龄 + "height", // 身高(cm) + "weight", // 体重(kg) + "marital_status", // 婚姻状况(0:未婚 1:已婚 2:离异) + "nation_id", // 民族名称 + "job_id", // 职业名称 + "disease_class_name", // 疾病名称-系统 + "diagnosis_date", // 确诊日期 + "disease_desc", // 病情描述(主诉) + "is_allergy_history", // 是否存在过敏史(0:否 1:是) + "allergy_history", // 过敏史描述 + "is_family_history", // 是否存在家族病史(0:否 1:是) + "family_history", // 家族病史描述 + "is_pregnant", // 是否备孕、妊娠、哺乳期(0:否 1:是) + "pregnant", // 备孕、妊娠、哺乳期描述 + "is_taboo", // 是否服用过禁忌药物,且无相关禁忌(0:否 1:是)问诊购药时存在 + "is_take_medicine", // 正在服药(0:否 1:是) + "drugs_name", // 正在服药名称 + "diagnosis_hospital", // 确诊医院 + "is_operation", // 是否存在手术(0:否 1:是) + "operation", // 手术描述 + "drink_wine_status", // 饮酒状态(1:从不 2:偶尔 3:经常 4:每天 5:已戒酒) + "smoke_status", // 吸烟状态(1:从不 2:偶尔 3:经常 4:每天 5:已戒烟) + "chemical_compound_status", // 化合物状态(1:从不 2:偶尔 3:经常 4:每天) + "chemical_compound_describe", // 化合物描述 + ]; + + try { + $redis = $this->container->get(Redis::class); + $redis_key = "patient_family_inquiry_case_unfilled_fields_" . $order_inquiry_id; + + // 获取缓存 + $redis_value = $redis->get($redis_key); + if (!empty($redis_value)){ + $redis_value = json_decode($redis_value,true); + } + + // 患者病例字段 + $case_fields = []; + foreach ($request_params['fields'] as $key){ + if (!in_array($key,$fields)){ + return fail(HttpEnumCode::HTTP_ERROR,"数据选择错误"); + } + + $case_fields[] = $key; + + // 处理缓存 + if (!empty($redis_value)){ + if (array_key_exists($key,$redis_value)){ + continue; + } + } + + $redis_value[$key] = [ + "value" => "", + "is_filled" => 0 + ]; + } + + if (empty($case_fields)){ + return fail(); + } + + $case_fields = json_encode($case_fields,JSON_UNESCAPED_UNICODE); + + // 发送im消息 + $imService = new ImService(); + $imService->CaseUnfilledFieldsToPatient($order_inquiry,$doctor['user_id'],$order_inquiry['user_id'],$case_fields); + + // 添加缓存-逗号分割字符串 + if (!empty($redis_value)){ + $redis_value = json_encode($redis_value,JSON_UNESCAPED_UNICODE); + $res = $redis->set($redis_key,$redis_value,31 * 24 * 60 * 60); + if (!$res){ + return fail(); + } + } + }catch (\Throwable $e){ + return fail(); + } + + return success(); + } + + /** + * 患者填写缺少字段至医生 + * @return array + */ + public function sendCaseUnfilledFieldsToDoctor(): array + { + $user_info = $this->request->getAttribute("userInfo") ?? []; + if ($user_info['user_type'] != 1){ + return fail(HttpEnumCode::HTTP_ERROR,"非法请求"); + } + + $request_params = $this->request->all(); + + $order_inquiry_id = $request_params['order_inquiry_id']; + + if (empty($request_params['fields'])){ + return fail(HttpEnumCode::CLIENT_HTTP_ERROR,"请填写后发送"); + } + + // 获取订单数据 + $params = array(); + $params['order_inquiry_id'] = $order_inquiry_id; + $order_inquiry = OrderInquiry::getOne($params); + if (empty($order_inquiry)) { + return fail(HttpEnumCode::HTTP_ERROR,"订单数据错误"); + } + + // 获取医生数据 + $params = array(); + $params['doctor_id'] = $order_inquiry['doctor_id']; + $doctor = UserDoctor::getOne($params); + if (empty($doctor)){ + return fail(); + } + + // 获取病例信息 + $params = array(); + $params['order_inquiry_id'] = $order_inquiry_id; + $order_inquiry_case = OrderInquiryCase::getOne($params); + if (empty($order_inquiry_case)) { + return fail(); + } + + $order_inquiry_case = $order_inquiry_case->toArray(); + + // 初始字段定义 + $fields = [ + "relation", // 与患者关系(1:本人 2:父母 3:爱人 4:子女 5:亲戚 6:其他 ) + "name", // 患者名称 + "sex", // 患者性别(0:未知 1:男 2:女) + "age", // 患者年龄 + "height", // 身高(cm) + "weight", // 体重(kg) + "marital_status", // 婚姻状况(0:未婚 1:已婚 2:离异) + "nation_id", // 民族名称 + "job_id", // 职业名称 + "disease_class_name", // 疾病名称-系统 + "diagnosis_date", // 确诊日期 + "disease_desc", // 病情描述(主诉) + "is_allergy_history", // 是否存在过敏史(0:否 1:是) + "allergy_history", // 过敏史描述 + "is_family_history", // 是否存在家族病史(0:否 1:是) + "family_history", // 家族病史描述 + "is_pregnant", // 是否备孕、妊娠、哺乳期(0:否 1:是) + "pregnant", // 备孕、妊娠、哺乳期描述 + "is_taboo", // 是否服用过禁忌药物,且无相关禁忌(0:否 1:是)问诊购药时存在 + "is_take_medicine", // 正在服药(0:否 1:是) + "drugs_name", // 正在服药名称 + "diagnosis_hospital", // 确诊医院 + "is_operation", // 是否存在手术(0:否 1:是) + "operation", // 手术描述 + "drink_wine_status", // 饮酒状态(1:从不 2:偶尔 3:经常 4:每天 5:已戒酒) + "smoke_status", // 吸烟状态(1:从不 2:偶尔 3:经常 4:每天 5:已戒烟) + "chemical_compound_status", // 化合物状态(1:从不 2:偶尔 3:经常 4:每天) + "chemical_compound_describe", // 化合物描述 + ]; + + Db::beginTransaction(); + + try { + $redis = $this->container->get(Redis::class); + $redis_key = "patient_family_inquiry_case_unfilled_fields_" . $order_inquiry_id; + $redis_value = $redis->get($redis_key); + if (!empty($redis_value)){ + $redis_value = json_decode($redis_value,true); + } + + // 患者病例字段 + $case_fields = []; + + // 修改字段 + $order_inquiry_case_data = []; + + foreach ($request_params['fields'] as $key => $value){ + if (!in_array($key,$fields)){ + if ($key != "order_inquiry_id"){ + Db::rollBack(); + return fail(HttpEnumCode::HTTP_ERROR,"存在非法数据"); + } + } + + // 跳过关联字段传空,如是否是否过敏史、过敏史描述 + if ($value === ""){ + continue; + } + + // 判断是否存在于缓存中 + if (!empty($redis_value)){ + if (array_key_exists($key,$redis_value)){ + if ($redis_value[$key]['is_filled'] == 1){ + Db::rollBack(); + return fail(HttpEnumCode::HTTP_ERROR,"请勿重复提交"); + } + + $redis_value[$key]['value'] = $value; + $redis_value[$key]['is_filled'] = 1; + } + } + + // 判断修改数据 + if (array_key_exists($key,$order_inquiry_case)){ + if ($order_inquiry_case[$key] == null){ + $order_inquiry_case_data[$key] = $value; + } + + // 处理职业 + if ($key == "job_id"){ + if ($order_inquiry_case["job_name"] == null){ + // 获取职业数据 + $params = array(); + $params['job_id'] = $value; + $basic_job = BasicJob::getOne($params); + if (!empty($basic_job)){ + $order_inquiry_case_data["job_name"] = $basic_job['job_name']; + } + } + } + + // 处理民族 + if ($key == "nation_id"){ + if ($order_inquiry_case["nation_name"] == null){ + // 获取职业数据 + $params = array(); + $params['nation_id'] = $value; + $basic_nation = BasicNation::getOne($params); + if (!empty($basic_nation)){ + $order_inquiry_case_data["nation_name"] = $basic_nation['nation_name']; + } + } + } + } + + $case_fields[$key] = $value; + } + + // 存储至问诊病例中 + if (!empty($order_inquiry_case_data)){ + $params = array(); + $params['inquiry_case_id'] = $order_inquiry_case['inquiry_case_id']; + $res = OrderInquiryCase::edit($params,$order_inquiry_case_data); + if (!$res){ + Db::rollBack(); + return fail(); + } + } + + // 发送im消息 + $case_fields = json_encode($case_fields,JSON_UNESCAPED_UNICODE); + + $imService = new ImService(); + $imService->CaseUnfilledFieldsToDoctor($order_inquiry,$doctor['user_id'],$user_info['user_id'],$case_fields); + + // 处理缓存 + if (!empty($redis_value)){ + $redis_value = json_encode($redis_value,JSON_UNESCAPED_UNICODE); + $res = $redis->set($redis_key,$redis_value,31 * 24 * 60 * 60); + if (!$res){ + return fail(); + } + } + + Db::commit(); + }catch (\Throwable $e){ + Db::rollBack(); + return fail(); + } + + return success(); + } +} \ No newline at end of file diff --git a/app/Services/PatientDoctorService.php b/app/Services/PatientDoctorService.php index 673883e..17425fa 100644 --- a/app/Services/PatientDoctorService.php +++ b/app/Services/PatientDoctorService.php @@ -15,135 +15,13 @@ use App\Model\PatientFollow; use App\Model\PatientHistoryInquiry as PatientHistoryInquiryModel; use App\Model\SystemInquiryConfig; use App\Model\SystemInquiryTime; +use App\Model\User; use App\Model\UserDoctor; use App\Model\UserDoctor as UserDoctorModel; use Hyperf\DbConnection\Db; class PatientDoctorService extends BaseService { -// /** -// * 获取问诊医生列表 -// * 专家问诊-公益问诊共用 -// * @return array -// */ -// public function getInquiryDoctorList(): array -// { -// $expertise_id = $this->request->input('expertise_id'); -// $province_id = $this->request->input('province_id'); -// $city_id = $this->request->input('city_id'); -// $sort_order = $this->request->input('sort_order',1); -// $keyword = $this->request->input('keyword',""); -// $is_search_welfare_reception = $this->request->input('is_search_welfare_reception',0); -// $page = $this->request->input('page',1); -// $per_page = $this->request->input('per_page',10); -// -// // 组合条件 -// $hospital_params = array();// 医院搜索 -// $doctor_params = array();// 医生搜索 -// $doctor_expertise_params = array();// 医生专长搜索 -// -// // 省市区 -// if (!empty($province_id)) { -// if (empty($city_id)) { -// // 省份存在时需和城市在一块 -// return fail(HttpEnumCode::CLIENT_HTTP_ERROR); -// } -// $hospital_params[] = ['province_id', '=', $province_id]; -// $hospital_params[] = ['city_id', '=', $city_id]; -// } -// -// // 医生专长 -// if (!empty($expertise_id)) { -// $doctor_expertise_params['expertise_id'] = $expertise_id; -// } -// -// // 固定医生查询条件 -// $doctor_params['status'] = 1; // 状态(0:禁用 1:正常 2:删除) -// -// $doctor_params["iden_auth_status"] = 1;// 身份认证状态(0:未认证 1:认证通过 2:审核中 3:认证失败) -// $doctor_params["is_bind_bank"] = 1;// 是否已绑定结算银行卡(0:否 1:是) -// -//// if (!empty($is_search_welfare_reception)){ -//// $doctor_params["is_img_welfare_reception"] = $is_search_welfare_reception;// 是否参加公益图文问诊(0:否 1:是) -//// } -// -// $fields = [ -// "doctor_id", -// "user_id", -// "user_name", -// "multi_point_status", -// "is_bind_bank", -// "is_recommend", -// "avatar", -// "doctor_title", -// "department_custom_id", -// "department_custom_name", -// "hospital_id", -// "served_patients_num", -// "praise_rate", -// "avg_response_time", -// "number_of_fans", -// "is_online", -// "be_good_at", -// ]; -// -// $user_doctors = UserDoctor::getInquiryDoctorPage($keyword,$hospital_params, $doctor_params,$doctor_expertise_params, $sort_order, $fields,$page,$per_page); -// -// if (!empty($user_doctors['data'])) { -// foreach ($user_doctors['data'] as &$user_doctor) { -// $user_doctor['doctor_title_name'] = empty($user_doctor['doctor_title']) ? "" : DoctorTitleCode::getMessage($user_doctor['doctor_title']); -// -// // 处理医生专长 -// if (!empty($user_doctor['DoctorExpertise'])) { -// foreach ($user_doctor['DoctorExpertise'] as &$data) { -// if (!empty($data['DiseaseClassExpertise'])) { -// $data['expertise_name'] = $data['DiseaseClassExpertise']['expertise_name']; -// } -// unset($data['DiseaseClassExpertise']); -// } -// } -// -// // 处理问诊价格 -// $user_doctor['price'] = 0; -// $user_doctor['free_clinic_price'] = 0; -// if (!empty($user_doctor['DoctorInquiryConfig'])) { -// foreach ($user_doctor['DoctorInquiryConfig'] as $doctor_inquiry_config) { -// if ($doctor_inquiry_config['inquiry_mode'] == 1) { -// if ($doctor_inquiry_config['inquiry_type'] == 1) { -// // 专家 -// $user_doctor['price'] = $doctor_inquiry_config['inquiry_price'] ?? 0; -// } -// if ($doctor_inquiry_config['inquiry_type'] == 3) { -// // 公益 -// $user_doctor['free_clinic_price'] = $doctor_inquiry_config['inquiry_price']; -// } -// } -// } -// } -// -// // 好评率-超过5个已结束的订单后展示 -// $user_doctor['praise_rate'] = floor($user_doctor['praise_rate'] * 0.05 * 100) / 100; -// // 响应时间-超过5个已结束的订单后展示 -// $user_doctor['avg_response_time'] = (float)floor($user_doctor['avg_response_time'] * 10) / 10; -// -// // 获取医生订单数 -// $params = array(); -// $params['doctor_id'] = $user_doctor['doctor_id']; -// $params['inquiry_status'] = 6; // 已结束 -// $inquiry_order_count = OrderInquiry::getCount($params); -// if (empty($inquiry_order_count) || $inquiry_order_count == 0) { -// $user_doctor['is_display_score'] = false; -// } else { -// $user_doctor['is_display_score'] = true; -// } -// -// // 头像 -// $user_doctor['avatar'] = addAliyunOssWebsite($user_doctor['avatar']); -// } -// } -// return success($user_doctors); -// } - /** * 获取问诊医生列表 * 专家问诊-公益问诊共用 @@ -157,6 +35,7 @@ class PatientDoctorService extends BaseService $sort_order = $this->request->input('sort_order',1); $keyword = $this->request->input('keyword',""); $is_search_welfare_reception = $this->request->input('is_search_welfare_reception',0); // 是否参加公益图文问诊(0:否 1:是) + $is_first_online = $this->request->input('is_first_online',0); // 是否优先在线(1:是) $page = $this->request->input('page',1); $per_page = $this->request->input('per_page',10); @@ -202,11 +81,10 @@ class PatientDoctorService extends BaseService "praise_rate", "avg_response_time", "number_of_fans", - "is_online", "be_good_at", ]; - $user_doctors = UserDoctor::getInquiryDoctorPage($keyword,$hospital_params, $doctor_params,$doctor_expertise_params,$is_search_welfare_reception, $sort_order, $fields,$page,$per_page); + $user_doctors = UserDoctor::getInquiryDoctorPage($keyword,$hospital_params, $doctor_params,$doctor_expertise_params,$is_search_welfare_reception,$is_first_online, $sort_order, $fields,$page,$per_page); if (!empty($user_doctors['data'])) { foreach ($user_doctors['data'] as &$user_doctor) { @@ -307,7 +185,6 @@ class PatientDoctorService extends BaseService "praise_rate", "avg_response_time", "number_of_fans", - "is_online", "be_good_at", "brief_introduction", ]; @@ -328,6 +205,7 @@ class PatientDoctorService extends BaseService $result['hospital'] = []; $result['days'] = 0; $result['doctor_inquiry_config'] = 0; + $result['is_online'] = 0; // 获取医生医院数据 $fields = [ @@ -437,6 +315,14 @@ class PatientDoctorService extends BaseService // 头像 $result['avatar'] = addAliyunOssWebsite($user_doctor['avatar']); + // 获取用户数据 + $params = array(); + $params['user_id'] = $user_doctor['user_id']; + $user = User::getOne($params); + if (!empty($user)){ + $result['is_online'] = $user['is_online']; + } + return success($result); } @@ -652,7 +538,8 @@ class PatientDoctorService extends BaseService * 获取我的问诊、关注医生列表 * @return array */ - public function getDoctorList(){ + public function getDoctorList(): array + { $user_info = $this->request->getAttribute("userInfo") ?? []; $my_doctor_type = $this->request->input('my_doctor_type'); // 医生类型(1:问诊 2:关注) @@ -739,7 +626,6 @@ class PatientDoctorService extends BaseService "doctor_title", "department_custom_name", "hospital_id", - "is_online", "be_good_at", ]; @@ -758,12 +644,15 @@ class PatientDoctorService extends BaseService $data['avatar'] = addAliyunOssWebsite($recommend_doctor['avatar']); $data['doctor_title'] = empty($recommend_doctor['doctor_title']) ? "" : DoctorTitleCode::getMessage($recommend_doctor['doctor_title']); $data['department_custom_name'] = $recommend_doctor['department_custom_name']; - $data['is_online'] = $recommend_doctor['is_online']; $data['be_good_at'] = $recommend_doctor['be_good_at']; $data['hospital_name'] = $recommend_doctor['Hospital']['hospital_name'] ?? ""; $data['hospital_level_name'] = $recommend_doctor['Hospital']['hospital_level_name'] ?? ""; $data['multi_point_enable'] = 0; // 是否开启问诊购药 + if (!empty($recommend_doctor['user'])){ + $data['is_online'] = $recommend_doctor['user']['is_online']; + } + // 处理接诊价格 $data['price'] = 0; $data['free_clinic_price'] = 0; @@ -935,6 +824,14 @@ class PatientDoctorService extends BaseService continue; } + // 获取用户数据 + $params = array(); + $params['user_id'] = $user_doctor['user_id']; + $user = User::getOne($params); + if (empty($user)){ + continue; + } + // 获取医生医院 $hospital_name = ""; if (!empty($user_doctor['hospital_id'])){ @@ -962,6 +859,9 @@ class PatientDoctorService extends BaseService $data['days'] = ceil((strtotime(date('Y-m-d', strtotime('+1 day'))) - strtotime($patient_history_doctor['created_at'])) / 86400); } + // 在线状态 + $data['is_online'] = $user['is_online']; + $results[] = $data; unset($data); diff --git a/app/Services/PatientFamilyService.php b/app/Services/PatientFamilyService.php index a67193d..4d06ae9 100644 --- a/app/Services/PatientFamilyService.php +++ b/app/Services/PatientFamilyService.php @@ -10,6 +10,7 @@ use App\Model\OrderProduct; use App\Model\PatientFamily as PatientFamilyModel; use App\Model\PatientFamilyHealth; use App\Model\PatientFamilyPersonal as PatientFamilyPersonalModel; +use App\Model\PatientPathography; use App\Utils\Mask; use Extend\VerifyDun\IdCard; use GuzzleHttp\Exception\GuzzleException; @@ -96,15 +97,15 @@ class PatientFamilyService extends BaseService } // 检测省市区 - if (!empty($request_params['county_id']) ){ - if (empty($request_params['city_id']) || empty($request_params['province_id'])){ + if (!empty($request_params['county_id'])) { + if (empty($request_params['city_id']) || empty($request_params['province_id'])) { // 区县存在时需和城市、省份在一块 return fail(HttpEnumCode::CLIENT_HTTP_ERROR); } } - if (!empty($request_params['city_id']) ){ - if (empty($request_params['province_id'])){ + if (!empty($request_params['city_id'])) { + if (empty($request_params['province_id'])) { // 城市存在时需和省份在一块 return fail(HttpEnumCode::CLIENT_HTTP_ERROR); } @@ -112,13 +113,13 @@ class PatientFamilyService extends BaseService $areaService = new AreaService(); - if (!empty($request_params['province_id'])){ - $req = $areaService->checkAreaById($request_params['province_id'],$request_params['city_id'],$request_params['county_id']); - if(empty($req)){ - return fail(HttpEnumCode::HTTP_ERROR,"地区选择错误"); + if (!empty($request_params['province_id'])) { + $req = $areaService->checkAreaById($request_params['province_id'], $request_params['city_id'], $request_params['county_id']); + if (empty($req)) { + return fail(HttpEnumCode::HTTP_ERROR, "地区选择错误"); } - $area = $areaService->getAreaById($request_params['province_id'],$request_params['city_id'],$request_params['county_id']); + $area = $areaService->getAreaById($request_params['province_id'], $request_params['city_id'], $request_params['county_id']); } if ($request_params['type'] == 1) { @@ -129,38 +130,38 @@ class PatientFamilyService extends BaseService } // 民族 - if (!empty($request_params['nation_id'])){ + if (!empty($request_params['nation_id'])) { $params = array(); $params['nation_id'] = $request_params['nation_id']; $nation = BasicNation::getOne($params); - if (empty($nation)){ - return fail(HttpEnumCode::HTTP_ERROR,"民族选择错误"); + if (empty($nation)) { + return fail(HttpEnumCode::HTTP_ERROR, "民族选择错误"); } } // 职业 - if (!empty($request_params['job_id'])){ + if (!empty($request_params['job_id'])) { $params = array(); $params['job_id'] = $request_params['job_id']; $job = BasicJob::getOne($params); - if (empty($job)){ - return fail(HttpEnumCode::HTTP_ERROR,"职位选择错误"); + if (empty($job)) { + return fail(HttpEnumCode::HTTP_ERROR, "职位选择错误"); } } // 实人认证-生产环境开启 - $app_env = config('app_env','dev'); - if ($app_env != "dev"){ + $app_env = config('app_env', 'dev'); + if ($app_env != "dev") { $IdCard = new IdCard(); - $params =array(); + $params = array(); $params['name'] = $request_params['card_name']; $params['cardNo'] = $request_params['id_number']; $res = $IdCard->checkIdCard($params); - if (!empty($res)){ - return fail(HttpEnumCode::HTTP_ERROR,$res); + if (!empty($res)) { + return fail(HttpEnumCode::HTTP_ERROR, $res); } } @@ -185,8 +186,8 @@ class PatientFamilyService extends BaseService // 新增 患者家庭成员信息表-基本信息(patient_family) $data = array(); $data['patient_id'] = $user_info['client_user_id']; - if (isset($request_params['relation'])){ - if ($request_params['relation'] != null){ + if (isset($request_params['relation'])) { + if ($request_params['relation'] != null) { $data['relation'] = $request_params['relation']; } } @@ -214,26 +215,26 @@ class PatientFamilyService extends BaseService $data['county'] = $area['county']['area_name'] ?? ""; } - if (!empty($request_params['height'])){ + if (!empty($request_params['height'])) { $data['height'] = $request_params['height']; } - if (!empty($request_params['weight'])){ + if (!empty($request_params['weight'])) { $data['weight'] = $request_params['weight']; } - if (isset($request_params['marital_status'])){ - if ($request_params['marital_status'] !== null){ + if (isset($request_params['marital_status'])) { + if ($request_params['marital_status'] !== null) { $data['marital_status'] = $request_params['marital_status']; } } - if (!empty($request_params['nation_id'])){ + if (!empty($request_params['nation_id'])) { $data['nation_id'] = $request_params['nation_id']; $data['nation_name'] = $nation['nation_name']; } - if (!empty($request_params['job_id'])){ + if (!empty($request_params['job_id'])) { $data['job_id'] = $request_params['job_id']; $data['job_name'] = $job['job_name']; } @@ -311,7 +312,7 @@ class PatientFamilyService extends BaseService $params['status'] = 1; $patient_family = PatientFamilyModel::getOne($params); - if (empty($patient_family)){ + if (empty($patient_family)) { return success(); } @@ -349,7 +350,7 @@ class PatientFamilyService extends BaseService $patient_familys = PatientFamilyModel::getList($params); if (!empty($patient_familys)) { foreach ($patient_familys as $value) { - if ($value['family_id'] == $family_id){ + if ($value['family_id'] == $family_id) { continue; } @@ -382,21 +383,21 @@ class PatientFamilyService extends BaseService } // 检测省市区 - if (isset($request_params['province_id']) && isset($request_params['city_id']) && isset($request_params['county_id'])){ - if ($request_params['province_id'] != $patient_family['province_id'] || $request_params['city_id'] != $patient_family['city_id'] || $request_params['county_id'] != $patient_family['county_id']){ + if (isset($request_params['province_id']) && isset($request_params['city_id']) && isset($request_params['county_id'])) { + if ($request_params['province_id'] != $patient_family['province_id'] || $request_params['city_id'] != $patient_family['city_id'] || $request_params['county_id'] != $patient_family['county_id']) { $areaService = new AreaService(); - $req = $areaService->checkAreaById($request_params['province_id'],$request_params['city_id'],$request_params['county_id']); - if(empty($req)){ - return fail(HttpEnumCode::HTTP_ERROR,"地区选择错误"); + $req = $areaService->checkAreaById($request_params['province_id'], $request_params['city_id'], $request_params['county_id']); + if (empty($req)) { + return fail(HttpEnumCode::HTTP_ERROR, "地区选择错误"); } - $area = $areaService->getAreaById($request_params['province_id'],$request_params['city_id'],$request_params['county_id']); + $area = $areaService->getAreaById($request_params['province_id'], $request_params['city_id'], $request_params['county_id']); } } // 检测证件号是否修改 - if ($patient_family['id_number'] != $request_params['id_number'] || $patient_family['card_name'] != $request_params['card_name']){ + if ($patient_family['id_number'] != $request_params['id_number'] || $patient_family['card_name'] != $request_params['card_name']) { // 解析年龄、性别字段 $age = getIdCardAge($this->request->input('id_number')); @@ -415,25 +416,25 @@ class PatientFamilyService extends BaseService } // 民族 - if (!empty($request_params['nation_id'])){ - if ($patient_family['nation_id'] != $request_params['nation_id']){ + if (!empty($request_params['nation_id'])) { + if ($patient_family['nation_id'] != $request_params['nation_id']) { $params = array(); $params['nation_id'] = $request_params['nation_id']; $nation = BasicNation::getOne($params); - if (empty($nation)){ - return fail(HttpEnumCode::HTTP_ERROR,"民族选择错误"); + if (empty($nation)) { + return fail(HttpEnumCode::HTTP_ERROR, "民族选择错误"); } } } // 职业 - if (!empty($request_params['job_id'])){ - if ($patient_family['job_id'] != $request_params['job_id']){ + if (!empty($request_params['job_id'])) { + if ($patient_family['job_id'] != $request_params['job_id']) { $params = array(); $params['job_id'] = $request_params['job_id']; $job = BasicJob::getOne($params); - if (empty($job)){ - return fail(HttpEnumCode::HTTP_ERROR,"职位选择错误"); + if (empty($job)) { + return fail(HttpEnumCode::HTTP_ERROR, "职位选择错误"); } } } @@ -458,13 +459,13 @@ class PatientFamilyService extends BaseService $data = array(); if (isset($request_params['relation'])) { - if ($request_params['relation'] != $patient_family['relation']){ + if ($request_params['relation'] != $patient_family['relation']) { $data['relation'] = $request_params['relation']; } } if (isset($request_params['is_default'])) { - if ($request_params['is_default'] !== $patient_family['is_default']){ + if ($request_params['is_default'] !== $patient_family['is_default']) { $data['is_default'] = $request_params['is_default']; } } @@ -477,7 +478,7 @@ class PatientFamilyService extends BaseService $data['id_number_mask'] = Mask::maskIdCard($request_params['id_number']); } - if(isset($request_params['mobile'])){ + if (isset($request_params['mobile'])) { if ($patient_family['mobile'] != $request_params['mobile']) { $data['mobile'] = $request_params['mobile']; $data['mobile_mask'] = Mask::maskPhoneStr($request_params['mobile']); @@ -494,55 +495,55 @@ class PatientFamilyService extends BaseService if (isset($area)) { // 如有改动,变量确定存在 - if ($request_params['province_id'] != $patient_family['province_id']){ + if ($request_params['province_id'] != $patient_family['province_id']) { $data['province_id'] = $request_params['province_id']; $data['province'] = $area['province']['area_name'] ?? ""; } - if ($request_params['city_id'] != $patient_family['city_id']){ + if ($request_params['city_id'] != $patient_family['city_id']) { $data['city_id'] = $request_params['city_id']; $data['city'] = $area['city']['area_name'] ?? ""; } - if ($request_params['county_id'] != $patient_family['county_id']){ + if ($request_params['county_id'] != $patient_family['county_id']) { $data['county_id'] = $request_params['county_id']; $data['county'] = $area['county']['area_name'] ?? ""; } } - if(isset($request_params['height'])){ - if ($request_params['height'] != $patient_family['height']){ + if (isset($request_params['height'])) { + if ($request_params['height'] != $patient_family['height']) { $data['height'] = $request_params['height']; } } - if(isset($request_params['weight'])){ - if ($request_params['weight'] != $patient_family['weight']){ + if (isset($request_params['weight'])) { + if ($request_params['weight'] != $patient_family['weight']) { $data['weight'] = $request_params['weight']; } } - if(isset($request_params['marital_status'])){ - if ($request_params['marital_status'] !== $patient_family['marital_status']){ + if (isset($request_params['marital_status'])) { + if ($request_params['marital_status'] !== $patient_family['marital_status']) { $data['marital_status'] = $request_params['marital_status']; } } - if(isset($request_params['nation_id'])){ - if ($request_params['nation_id'] != $patient_family['nation_id']){ + if (isset($request_params['nation_id'])) { + if ($request_params['nation_id'] != $patient_family['nation_id']) { $data['nation_id'] = $request_params['nation_id']; $data['nation_name'] = $nation['nation_name']; } } - if(isset($request_params['job_id'])){ - if ($request_params['job_id'] != $patient_family['job_id']){ + if (isset($request_params['job_id'])) { + if ($request_params['job_id'] != $patient_family['job_id']) { $data['job_id'] = $request_params['job_id']; $data['job_name'] = $job['job_name']; } } - if (!empty($data)){ + if (!empty($data)) { $data['updated_at'] = date('Y-m-d H:i:s', time()); PatientFamilyModel::edit($params, $data); } @@ -572,7 +573,7 @@ class PatientFamilyService extends BaseService $params['patient_id'] = $user_info['client_user_id']; $patient_family_personal = PatientFamilyPersonalModel::getOne($params); - if (empty($patient_family_personal)){ + if (empty($patient_family_personal)) { return success(); } @@ -600,76 +601,76 @@ class PatientFamilyService extends BaseService // 修改 $data = array(); - if (isset($request_params['is_allergy_history'])){ - if ($request_params['is_allergy_history'] !== $patient_family_personal['is_allergy_history']){ + if (isset($request_params['is_allergy_history'])) { + if ($request_params['is_allergy_history'] !== $patient_family_personal['is_allergy_history']) { // 是否存在过敏史(0:否 1:是) $data['is_allergy_history'] = $request_params['is_allergy_history']; } - if ($request_params['allergy_history'] != $patient_family_personal['allergy_history']){ + if ($request_params['allergy_history'] != $patient_family_personal['allergy_history']) { $data['allergy_history'] = $request_params['allergy_history']; } } - if (isset($request_params['is_family_history'])){ - if ($request_params['is_family_history'] !== $patient_family_personal['is_family_history']){ + if (isset($request_params['is_family_history'])) { + if ($request_params['is_family_history'] !== $patient_family_personal['is_family_history']) { // 是否存在家族病史(0:否 1:是) $data['is_family_history'] = $request_params['is_family_history']; } - if ($request_params['family_history'] != $patient_family_personal['family_history']){ + if ($request_params['family_history'] != $patient_family_personal['family_history']) { $data['family_history'] = $request_params['family_history']; } } - if (isset($request_params['is_pregnant'])){ - if ($request_params['is_pregnant'] !== $patient_family_personal['is_pregnant']){ + if (isset($request_params['is_pregnant'])) { + if ($request_params['is_pregnant'] !== $patient_family_personal['is_pregnant']) { // 是否备孕、妊娠、哺乳期(0:否 1:是) $data['is_pregnant'] = $request_params['is_pregnant']; } - if ($request_params['pregnant'] != $patient_family_personal['pregnant']){ + if ($request_params['pregnant'] != $patient_family_personal['pregnant']) { $data['pregnant'] = $request_params['pregnant']; } } - if (isset($request_params['is_operation'])){ - if ($request_params['is_operation'] !== $patient_family_personal['is_operation']){ + if (isset($request_params['is_operation'])) { + if ($request_params['is_operation'] !== $patient_family_personal['is_operation']) { // 是否存在手术(0:否 1:是) $data['is_operation'] = $request_params['is_operation']; } - if ($request_params['operation'] != $patient_family_personal['operation']){ + if ($request_params['operation'] != $patient_family_personal['operation']) { $data['operation'] = $request_params['operation']; } } - if (isset($request_params['drink_wine_status'])){ - if ($request_params['drink_wine_status'] !== $patient_family_personal['drink_wine_status']){ + if (isset($request_params['drink_wine_status'])) { + if ($request_params['drink_wine_status'] !== $patient_family_personal['drink_wine_status']) { // 饮酒状态(1:从不 2:偶尔 3:经常 4:每天 5:已戒酒) $data['drink_wine_status'] = $request_params['drink_wine_status']; } } - if (isset($request_params['smoke_status'])){ - if ($request_params['smoke_status'] !== $patient_family_personal['smoke_status']){ + if (isset($request_params['smoke_status'])) { + if ($request_params['smoke_status'] !== $patient_family_personal['smoke_status']) { // 吸烟状态(1:从不 2:偶尔 3:经常 4:每天 5:已戒烟) $data['smoke_status'] = $request_params['smoke_status']; } } - if (isset($request_params['chemical_compound_status'])){ - if ($request_params['chemical_compound_status'] !== $patient_family_personal['chemical_compound_status']){ + if (isset($request_params['chemical_compound_status'])) { + if ($request_params['chemical_compound_status'] !== $patient_family_personal['chemical_compound_status']) { // 化合物状态(1:从不 2:偶尔 3:经常 4:每天) $data['chemical_compound_status'] = $request_params['chemical_compound_status']; } - if ($request_params['chemical_compound_describe'] != $patient_family_personal['chemical_compound_describe']){ + if ($request_params['chemical_compound_describe'] != $patient_family_personal['chemical_compound_describe']) { $data['chemical_compound_describe'] = $request_params['chemical_compound_describe']; } } - if (!empty($data)){ + if (!empty($data)) { $data['updated_at'] = date('Y-m-d H:i:s', time()); $params = array(); $params['family_personal_id'] = $patient_family_personal['family_personal_id']; @@ -710,50 +711,50 @@ class PatientFamilyService extends BaseService $data = array(); $data['family_id'] = $request_params['family_id']; $data['patient_id'] = $user_info['client_user_id']; - if (isset($request_params['is_allergy_history'])){ - if ($request_params['is_allergy_history'] !== null){ + if (isset($request_params['is_allergy_history'])) { + if ($request_params['is_allergy_history'] !== null) { $data['is_allergy_history'] = $request_params['is_allergy_history']; $data['allergy_history'] = $request_params['allergy_history'] ?? ""; } } - if (isset($request_params['is_family_history'])){ - if ($request_params['is_family_history'] !== null){ + if (isset($request_params['is_family_history'])) { + if ($request_params['is_family_history'] !== null) { $data['is_family_history'] = $request_params['is_family_history']; $data['family_history'] = $request_params['family_history'] ?? ""; } } - if (isset($request_params['is_pregnant'])){ - if ($request_params['is_pregnant'] !== null){ + if (isset($request_params['is_pregnant'])) { + if ($request_params['is_pregnant'] !== null) { $data['is_pregnant'] = $request_params['is_pregnant']; $data['pregnant'] = $request_params['pregnant'] ?? ""; } } - if (isset($request_params['is_operation'])){ - if ($request_params['is_operation'] !== null){ + if (isset($request_params['is_operation'])) { + if ($request_params['is_operation'] !== null) { $data['is_operation'] = $request_params['is_operation']; $data['operation'] = $request_params['operation'] ?? ""; } } - if (isset($request_params['drink_wine_status'])){ - if ($request_params['drink_wine_status'] !== null){ + if (isset($request_params['drink_wine_status'])) { + if ($request_params['drink_wine_status'] !== null) { $data['drink_wine_status'] = $request_params['drink_wine_status']; $data['smoke_status'] = $request_params['smoke_status'] ?? ""; } } - if (isset($request_params['chemical_compound_status'])){ - if ($request_params['chemical_compound_status'] !== null){ + if (isset($request_params['chemical_compound_status'])) { + if ($request_params['chemical_compound_status'] !== null) { $data['chemical_compound_status'] = $request_params['chemical_compound_status']; $data['chemical_compound_describe'] = $request_params['chemical_compound_describe']; } } $patient_family_personal = PatientFamilyPersonalModel::addPatientFamilyPersonal($data); - if (empty($patient_family_personal)){ + if (empty($patient_family_personal)) { return fail(); } @@ -774,7 +775,7 @@ class PatientFamilyService extends BaseService $params['family_id'] = $family_id; $params['patient_id'] = $user_info['client_user_id']; $patient_family_health = PatientFamilyHealth::getOne($params); - if (empty($patient_family_health)){ + if (empty($patient_family_health)) { return success(); } @@ -801,8 +802,8 @@ class PatientFamilyService extends BaseService } $data = array(); - if (isset($request_params['disease_class_id'])){ - if ($request_params['disease_class_id'] != $patient_family_health['disease_class_id']){ + if (isset($request_params['disease_class_id'])) { + if ($request_params['disease_class_id'] != $patient_family_health['disease_class_id']) { // 疾病分类id-系统 $data['disease_class_id'] = $request_params['disease_class_id']; @@ -810,43 +811,43 @@ class PatientFamilyService extends BaseService $params = array(); $params['disease_class_id'] = $request_params['disease_class_id']; $disease_class = DiseaseClass::getOne($params); - if (empty($disease_class)){ - return fail(HttpEnumCode::HTTP_ERROR,"疾病数据错误"); + if (empty($disease_class)) { + return fail(HttpEnumCode::HTTP_ERROR, "疾病数据错误"); } $data['disease_class_name'] = $disease_class['disease_class_name']; } } - if (isset($request_params['diagnosis_date'])){ - if ($request_params['diagnosis_date'] != $patient_family_health['diagnosis_date']){ + if (isset($request_params['diagnosis_date'])) { + if ($request_params['diagnosis_date'] != $patient_family_health['diagnosis_date']) { $data['diagnosis_date'] = $request_params['diagnosis_date']; } } - if (isset($request_params['diagnosis_hospital'])){ - if ($request_params['diagnosis_hospital'] != $patient_family_health['diagnosis_hospital']){ + if (isset($request_params['diagnosis_hospital'])) { + if ($request_params['diagnosis_hospital'] != $patient_family_health['diagnosis_hospital']) { $data['diagnosis_hospital'] = $request_params['diagnosis_hospital']; } } - if (isset($request_params['is_take_medicine'])){ - if ($request_params['is_take_medicine'] !== $patient_family_health['is_take_medicine']){ + if (isset($request_params['is_take_medicine'])) { + if ($request_params['is_take_medicine'] !== $patient_family_health['is_take_medicine']) { $data['is_take_medicine'] = $request_params['is_take_medicine']; - if ($request_params['drugs_name'] != $patient_family_health['drugs_name']){ + if ($request_params['drugs_name'] != $patient_family_health['drugs_name']) { $data['drugs_name'] = $request_params['drugs_name']; } } } - if (!empty($data)){ + if (!empty($data)) { $data['updated_at'] = date('Y-m-d H:i:s', time()); $params = array(); $params['family_health_id'] = $patient_family_health['family_health_id']; - PatientFamilyHealth::edit($params,$data); + PatientFamilyHealth::edit($params, $data); } return success(); @@ -883,8 +884,8 @@ class PatientFamilyService extends BaseService $data['family_id'] = $request_params['family_id']; $data['patient_id'] = $user_info['client_user_id']; - if (isset($request_params['disease_class_id'])){ - if (!empty($request_params['disease_class_id'])){ + if (isset($request_params['disease_class_id'])) { + if (!empty($request_params['disease_class_id'])) { // 疾病分类id-系统 $data['disease_class_id'] = $request_params['disease_class_id']; @@ -892,35 +893,35 @@ class PatientFamilyService extends BaseService $params = array(); $params['disease_class_id'] = $request_params['disease_class_id']; $disease_class = DiseaseClass::getOne($params); - if (empty($disease_class)){ - return fail(HttpEnumCode::HTTP_ERROR,"疾病数据错误"); + if (empty($disease_class)) { + return fail(HttpEnumCode::HTTP_ERROR, "疾病数据错误"); } $data['disease_class_name'] = $disease_class['disease_class_name']; } } - if (isset($request_params['diagnosis_date'])){ - if (!empty($request_params['diagnosis_date'])){ + if (isset($request_params['diagnosis_date'])) { + if (!empty($request_params['diagnosis_date'])) { $data['diagnosis_date'] = $request_params['diagnosis_date']; } } - if (isset($request_params['diagnosis_hospital'])){ - if (!empty($request_params['diagnosis_hospital'])){ + if (isset($request_params['diagnosis_hospital'])) { + if (!empty($request_params['diagnosis_hospital'])) { $data['diagnosis_hospital'] = $request_params['diagnosis_hospital']; } } - if (isset($request_params['is_take_medicine'])){ - if ($request_params['is_take_medicine'] !== null){ + if (isset($request_params['is_take_medicine'])) { + if ($request_params['is_take_medicine'] !== null) { $data['is_take_medicine'] = $request_params['is_take_medicine']; $data['drugs_name'] = $request_params['drugs_name'] ?? ""; } } $patient_family_health = PatientFamilyHealth::addPatientFamilyHealth($data); - if (empty($patient_family_health)){ + if (empty($patient_family_health)) { return fail(); } @@ -935,13 +936,13 @@ class PatientFamilyService extends BaseService { $user_info = $this->request->getAttribute("userInfo"); - $family_id = $this->request->input('family_id',0); + $family_id = $this->request->input('family_id', 0); $page = $this->request->input('page', 1); $per_page = $this->request->input('per_page', 10); $params = array(); $params['patient_id'] = $user_info['client_user_id']; - if ($family_id != 0){ + if ($family_id != 0) { $params['family_id'] = $family_id; } @@ -956,11 +957,11 @@ class PatientFamilyService extends BaseService 'created_at', ]; - $result = OrderProduct::getProductRecordPage($params,$fields,$page,$per_page); - if (!empty($result['data'])){ - foreach ($result['data'] as &$item){ - if (!empty($item['OrderProductItem'])){ - foreach ($item['OrderProductItem'] as &$order_product_item){ + $result = OrderProduct::getProductRecordPage($params, $fields, $page, $per_page); + if (!empty($result['data'])) { + foreach ($result['data'] as &$item) { + if (!empty($item['OrderProductItem'])) { + foreach ($item['OrderProductItem'] as &$order_product_item) { $order_product_item['product_cover_img'] = addAliyunOssWebsite($order_product_item['product_cover_img']); } } @@ -990,10 +991,17 @@ class PatientFamilyService extends BaseService $params['patient_id'] = $user_info['client_user_id']; $patient_family_personal = PatientFamilyPersonalModel::getOne($params); - if (empty($patient_family_health) && empty($patient_family_personal)){ + if (empty($patient_family_health) && empty($patient_family_personal)) { return success(null); } + // 获取病情记录 + $params = array(); + $params['user_id'] = $user_info['user_id']; + $params['patient_id'] = $user_info['client_user_id']; + $params['family_id'] = $family_id; + $patient_pathography = PatientPathography::getLastOne($params); + $result = array(); $result['user_id'] = $user_info['user_id']; $result['patient_id'] = $user_info['client_user_id']; @@ -1007,24 +1015,34 @@ class PatientFamilyService extends BaseService $result['family_history'] = null; // 家族病史描述 $result['is_pregnant'] = null; // 是否备孕、妊娠、哺乳期(0:否 1:是) $result['pregnant'] = null; // 备孕、妊娠、哺乳期描述 + $result['disease_desc'] = ""; // 病情描述(主诉) - if (!empty($patient_family_personal)){ - if ($patient_family_personal['is_allergy_history'] != null){ + if (!empty($patient_family_personal)) { + if ($patient_family_personal['is_allergy_history'] != null) { $result['is_allergy_history'] = (int)$patient_family_personal['is_allergy_history']; // 是否存在过敏史(0:否 1:是) $result['allergy_history'] = $patient_family_personal['allergy_history']; // 过敏史描述 } - if ($patient_family_personal['is_family_history'] != null){ + if ($patient_family_personal['is_family_history'] != null) { $result['is_family_history'] = (int)$patient_family_personal['is_family_history']; // 是否存在家族病史(0:否 1:是) $result['family_history'] = $patient_family_personal['family_history']; // 家族病史描述 } - if ($patient_family_personal['is_pregnant'] != null){ + if ($patient_family_personal['is_pregnant'] != null) { $result['is_pregnant'] = (int)$patient_family_personal['is_pregnant']; // 是否备孕、妊娠、哺乳期(0:否 1:是) $result['pregnant'] = $patient_family_personal['pregnant']; // 备孕、妊娠、哺乳期描述 } } + // 病情主诉 + if (!empty($patient_pathography)){ + if ($patient_pathography['disease_desc'] != null){ + $result['disease_desc'] = $patient_pathography['disease_desc']; // 病情描述(主诉) + } + } + return success($result); } + + } \ No newline at end of file diff --git a/app/Services/PatientPathographyService.php b/app/Services/PatientPathographyService.php new file mode 100644 index 0000000..ed76afc --- /dev/null +++ b/app/Services/PatientPathographyService.php @@ -0,0 +1,319 @@ +request->getAttribute("userInfo") ?? []; + $family_id = $this->request->input('family_id'); + + // 获取家庭成员数据 + $params = array(); + $params['family_id'] = $family_id; + $patient_family = PatientFamily::getOne($params); + if (empty($patient_family)){ + return fail(); + } + + if ($user_info['user_type'] == 1){ + // 患者情况下 用户id需相同 + if ($patient_family['patient_id'] != $user_info['client_user_id']){ + return fail(); + } + } + + $result = array(); + $result['is_exist'] = 0; + + // 获取病情记录 + $params = array(); + $params['patient_id'] = $patient_family['patient_id']; + $params['family_id'] = $family_id; + $params['status'] = 1; + $patient_pathography = PatientPathography::getLastOne($params); + if (!empty($patient_pathography)){ + $result['is_exist'] = 1; + } + + return success($result); + } + + /** + * 获取家庭成员病情记录列表-分页 + * @return array + */ + public function getFamilyPathographyPage(): array + { + $user_info = $this->request->getAttribute("userInfo") ?? []; + $family_id = $this->request->input('family_id'); + $page = $this->request->input('page', 1); + $per_page = $this->request->input('per_page', 10); + + // 获取家庭成员数据 + $params = array(); + $params['family_id'] = $family_id; + $patient_family = PatientFamily::getOne($params); + if (empty($patient_family)){ + return fail(); + } + + if ($user_info['user_type'] == 1){ + // 患者情况下 用户id需相同 + if ($patient_family['patient_id'] != $user_info['client_user_id']){ + return fail(); + } + } + + // 获取病情记录列表 + $fields = [ + "pathography_id", + "order_inquiry_id", + "name", + "sex", + "age", + "created_at", + "disease_class_name", + "disease_desc" + ]; + + $params = array(); + $params['patient_id'] = $patient_family['patient_id']; + $params['family_id'] = $family_id; + $params['status'] = 1; + $patient_pathographys = PatientPathography::getPatientPathographyPage($params, $fields, $page, $per_page); + + foreach ($patient_pathographys['data'] as &$patient_pathography){ + $patient_pathography['reception_time'] = null; + if (!empty($patient_pathography['OrderInquiry'])){ + // 接诊时间 + $patient_pathography['reception_time'] = $patient_pathography['OrderInquiry']['reception_time']; + } + + unset($patient_pathography['OrderInquiry']); + } + + return success($patient_pathographys); + } + + /** + * 获取家庭成员病情记录详情 + * @return array + */ + public function getFamilyPathographyInfo(): array + { + $user_info = $this->request->getAttribute("userInfo") ?? []; + $pathography_id = $this->request->route('pathography_id'); + + $params = array(); + $params['pathography_id'] = $pathography_id; + $params['status'] = 1; + $patient_pathography = PatientPathography::getOne($params); + if (empty($patient_pathography)){ + return success(null); + } + + if ($user_info['user_type'] == 1){ + // 患者情况下 用户id需相同 + if ($patient_pathography['patient_id'] != $user_info['client_user_id']){ + return fail(); + } + + if ($patient_pathography['user_id'] != $user_info['user_id']){ + return fail(); + } + } + + $result = $patient_pathography->toArray(); + $result['order_prescription'] = null; // 处方数据 + $result['patient_pathography_product'] = array(); // 用药意向 + $result['diagnose_images'] = array(); // 复诊凭证 + + // 获取处方数据 + if (!empty($patient_pathography['order_prescription_id'])){ + $params = array(); + $params['order_prescription_id'] = $patient_pathography['order_prescription_id']; + $params['patient_id'] = $patient_pathography['patient_id']; + $params['family_id'] = $patient_pathography['family_id']; + $order_prescription = OrderPrescription::getOne($params); + if (!empty($order_prescription)){ + $result['order_prescription']['doctor_created_time'] = $order_prescription['doctor_created_time']; // 医生开具处方时间 + $result['order_prescription']['doctor_advice'] = $order_prescription['doctor_advice'];// 医嘱 + + // 获取处方疾病数据 + $params = array(); + $params['order_prescription_id'] = $order_prescription['order_prescription_id']; + $order_prescription_icds = OrderPrescriptionIcd::getList($params); + if (empty($order_prescription_icds)){ + return fail(); + } + + $icd_name = array_column($order_prescription_icds->toArray(),"icd_name"); + $result['order_prescription']['icd_name'] = implode(";",$icd_name); + + // 获取处方药品名称 + $params = array(); + $params['order_prescription_id'] = $order_prescription['order_prescription_id']; + $order_prescription_products = OrderPrescriptionProduct::getList($params); + if (empty($order_prescription_products)){ + return fail(); + } + + $result["order_prescription"]["product"] = $order_prescription_products->toArray(); + } + } + + // 获取用药意向 + $params = array(); + $params['pathography_id'] = $patient_pathography['pathography_id']; + $patient_pathography_products = PatientPathographyProduct::getList($params); + if (!empty($patient_pathography_products)){ + foreach ($patient_pathography_products as $patient_pathography_product){ + // 获取商品数据 + $params =array(); + $params['product_id'] = $patient_pathography_product['product_id']; + $product = Product::getOne($params); + if (empty($product)){ + return fail(); + } + + $item = array(); + $item['product_cover_img'] = addAliyunOssWebsite($product['product_cover_img']); + $item['product_name'] = $product['product_name']; // 名称 + $item['product_spec'] = $product['product_spec']; // 商品规格 + $item['packaging_unit'] = $product['packaging_unit']; // 基本包装单位(例:盒/瓶) + $item['case_product_num'] = $patient_pathography_product['case_product_num']; // 药品数量 + + $result['patient_pathography_product'][] = $item; + } + } + + // 复诊凭证 + if (!empty($patient_pathography['diagnose_images'])){ + $diagnose_images = explode(',', $patient_pathography['diagnose_images']); + foreach ($diagnose_images as &$item) { + $item = addAliyunOssWebsite($item); + } + + $result['diagnose_images'] = $diagnose_images; + } + + return success($result); + } + + /** + * 获取家庭成员病情记录分组 + * @return array + */ + public function getFamilyPathographyGroup(): array + { + $user_info = $this->request->getAttribute("userInfo") ?? []; + + // 获取家庭成员数据 + $params = array(); + $params['patient_id'] = $user_info['client_user_id']; + $patient_familys = PatientFamily::getList($params); + if (empty($patient_familys)){ + return success(); + } + + // 定义返回数据 + $results = array(); + + foreach ($patient_familys as $patient_family){ + // 定义返回数据 + $result = array(); + $result['user_id'] = $user_info['user_id']; + $result['patient_id'] = $patient_family['patient_id']; + $result['family_id'] = $patient_family['family_id']; + $result['status'] = $patient_family['status']; + $result['card_name'] = $patient_family['card_name']; + $result['sex'] = $patient_family['sex']; + $result['age'] = $patient_family['age']; + $result['count'] = 0; + + $params = array(); + $params['user_id'] = $user_info['user_id']; + $params['patient_id'] = $patient_family['patient_id']; + $params['family_id'] = $patient_family['family_id']; + $params['status'] = 1; + $patient_pathographys = PatientPathography::getList($params); + if (!empty($patient_pathographys)){ + $result['count'] = count($patient_pathographys); + } + + $results[] = $result; + } + + return success($results); + } + + /** + * 删除家庭成员病情记录 + * @return array + */ + public function deleteFamilyPathography(): array + { + $user_info = $this->request->getAttribute("userInfo") ?? []; + $pathography_id = $this->request->route('pathography_id'); + + // 获取病情记录 + $params = array(); + $params['pathography_id'] = $pathography_id; + $patient_pathography = PatientPathography::getOne($params); + if (empty($patient_pathography)){ + return fail(HttpEnumCode::HTTP_ERROR,"无该病例"); + } + + if ($user_info['user_type'] == 2){ + return fail(); + } + + if ($user_info['user_type'] == 1){ + // 患者情况下 用户id需相同 + if ($patient_pathography['patient_id'] != $user_info['client_user_id']){ + return fail(); + } + + if ($patient_pathography['user_id'] != $user_info['user_id']){ + return fail(); + } + } + + if ($patient_pathography['status'] == 2){ + return success(); + } + + $params = array(); + $params['pathography_id'] = $patient_pathography['pathography_id']; + + $data = array(); + $data['status'] = 2; + $res = PatientPathography::edit($params,$data); + if (!$res){ + return fail(); + } + + return success(); + } +} \ No newline at end of file diff --git a/app/Services/ReportRegulatoryService.php b/app/Services/ReportRegulatoryService.php new file mode 100644 index 0000000..73a5129 --- /dev/null +++ b/app/Services/ReportRegulatoryService.php @@ -0,0 +1,51 @@ + $coupon) { - // 处理优惠卷数量限制问题 if ($coupon['coupon_type'] == 3 && !empty($coupon['product_id'])){ // 数量是否足够标识字段 $quantity_quantity = 0; @@ -172,7 +172,14 @@ class UserCouponService extends BaseService continue; } - $product_price = bcadd($product_price,$coupon_product_data['product_price'],2); + $product_price = bcadd($product_price, + bcmul( // 商品价格*数量 + $coupon_product_data['product_price'], + $coupon_product_data['product_num'], + 2 + ), + 2 + ); } if ($coupon['with_amount'] > $product_price){ @@ -201,13 +208,15 @@ class UserCouponService extends BaseService continue; } - if (empty($selected_coupon)) { + if (empty($selected_coupons)) { $selected_coupons[] = $coupon; // 选中的优惠卷数据 $coupon_high_price = $coupon['coupon_price']; + continue; } + dump($coupon_high_price); // 处理存在互斥卷情况 if ($is_mutex == 1) { // 选择金额最高的为选中 diff --git a/app/Services/UserDoctorService.php b/app/Services/UserDoctorService.php index d732d70..2367f48 100644 --- a/app/Services/UserDoctorService.php +++ b/app/Services/UserDoctorService.php @@ -592,22 +592,22 @@ class UserDoctorService extends BaseService $user_doctor = $user_doctor->toArray(); // 获取医生账户余额-未提现金额 - $DoctorAccountService = new DoctorAccountService(); - $balance_account = $DoctorAccountService->getDoctorBalanceAccount($user_info['client_user_id']); - if ($balance_account > 0) { - $balance_account = floor($balance_account * 100) / 100; - } - - // 获取医生当日接诊的订单金额 - $InquiryService = new InquiryService(); - $estimate_income = $InquiryService->getDoctorDayAmountTotal($user_info['client_user_id'], date('Y-m-d', time())); - if (!empty($estimate_income)) { - $estimate_income = floor($estimate_income * 0.75 * 100) / 100; - } +// $DoctorAccountService = new DoctorAccountService(); +// $balance_account = $DoctorAccountService->getDoctorBalanceAccount($user_info['client_user_id']); +// if ($balance_account > 0) { +// $balance_account = floor($balance_account * 100) / 100; +// } +// +// // 获取医生当日接诊的订单金额 +// $InquiryService = new InquiryService(); +// $estimate_income = $InquiryService->getDoctorDayAmountTotal($user_info['client_user_id'], date('Y-m-d', time())); +// if (!empty($estimate_income)) { +// $estimate_income = floor($estimate_income * 0.75 * 100) / 100; +// } $user_doctor['avatar'] = addAliyunOssWebsite($user_doctor['avatar']); - $user_doctor['balance_account'] = $balance_account; - $user_doctor['estimate_income'] = $estimate_income; +// $user_doctor['balance_account'] = $balance_account; +// $user_doctor['estimate_income'] = $estimate_income; $user_doctor['doctor_title'] = DoctorTitleCode::getMessage($user_doctor['doctor_title']); return success($user_doctor); @@ -1433,6 +1433,23 @@ class UserDoctorService extends BaseService return fail(HttpEnumCode::SERVER_ERROR,"商品错误"); } + if ($product['product_status'] == 2){ + Db::rollBack(); + return fail(HttpEnumCode::HTTP_ERROR,"药品" . $product['product_name'] . "已下架"); + } + + if ($product['is_delete'] == 1){ + Db::rollBack(); + return fail(HttpEnumCode::HTTP_ERROR,"药品" . $product['product_name'] . "已被删除,无法开具"); + } + + // 检测药品是否超出最大可开数 + if ($item['prescription_product_num'] > $product['prescription_num']) { + // 库存不足 + Db::rollBack(); + return fail(HttpEnumCode::HTTP_ERROR, "药品" . $product['product_name'] . "超出最大可开方数"); + } + // 获取商品库存 $params =array(); $params['product_platform_id'] = $product['product_platform_id']; @@ -1444,9 +1461,12 @@ class UserDoctorService extends BaseService } if ($product_platform_amount['stock'] <= 0){ + Db::rollBack(); return fail(HttpEnumCode::HTTP_ERROR,"商品库存不足"); } + + // 检测药品库存数据 if ($item['prescription_product_num'] > $product['ProductPlatformAmount']['stock']) { // 库存不足 diff --git a/app/Services/UserPatientService.php b/app/Services/UserPatientService.php index 69b6e95..3064ae9 100644 --- a/app/Services/UserPatientService.php +++ b/app/Services/UserPatientService.php @@ -46,6 +46,7 @@ class UserPatientService extends BaseService // 获取福利数据 $coupon = UserCoupon::getUserObjectTypeCoupon($user_patient['user_id'],2); + $coupon = $coupon->toArray(); // 获取问诊数量-待支付 $InquiryService = new InquiryService(); @@ -278,6 +279,7 @@ class UserPatientService extends BaseService if (empty($product)){ return fail(); } + // 获取商品库存 $params =array(); $params['product_platform_id'] = $product['product_platform_id']; diff --git a/app/Services/UserPharmacistService.php b/app/Services/UserPharmacistService.php index 871e4bf..4e0f0a7 100644 --- a/app/Services/UserPharmacistService.php +++ b/app/Services/UserPharmacistService.php @@ -68,10 +68,13 @@ class UserPharmacistService extends BaseService $data = array(); $data['is_online'] = $is_online; + if ($is_online == 1){ + $data['login_at'] = date('Y-m_d,H:i:s',time()); + } $params = array(); - $params['pharmacist_id'] = $user_pharmacist['pharmacist_id']; - UserPharmacist::editUserPharmacist($params, $data); + $params['user_id'] = $user_info['user_id']; + User::editUser($params, $data); return success(); } diff --git a/app/Services/UserService.php b/app/Services/UserService.php index a5d2a85..a1d8f9e 100644 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -2,8 +2,11 @@ namespace App\Services; +use App\Amqp\Producer\UserImOffDelayDirectProducer; use App\Constants\HttpEnumCode; use App\Model\Area; +use App\Model\MessageIm; +use App\Model\OrderInquiry; use App\Model\Popup; use App\Model\SubTemplate; use App\Model\User; @@ -14,12 +17,14 @@ use App\Model\UserLocation; use App\Model\UserPatient; use App\Model\UserShipAddress; use App\Model\UserSystem; +use App\Utils\Log; use App\Utils\Mask; use App\Utils\PcreMatch; use Extend\Tencent\map\Location; use Extend\TencentIm\Profile; use Extend\Wechat\Wechat; use GuzzleHttp\Exception\GuzzleException; +use Hyperf\Amqp\Producer; use Hyperf\Amqp\Result; use Hyperf\DbConnection\Db; use Hyperf\Redis\Redis; @@ -883,7 +888,7 @@ class UserService extends BaseService break; case 'TIMSoundElem': - $message = "语音消息"; + $message = "[语音]"; break; case 'TIMImageElem': $message = "图像消息"; @@ -919,4 +924,323 @@ class UserService extends BaseService return true; } + + /** + * 处理用户im登陆状态 + * @param array $data im消息体 + * { + "CallbackCommand":"State.StateChange", + "Info":{ + "To_Account":"516898713896521728", + "Action":"Disconnect", + "Reason":"LinkClose" + }, + "EventTime":1701047839484, + "ClientIP":"221.216.35.130", + "OptPlatform":"Web", + "RequestId":"clhus7ir8lcc6oth83f0-144115242829354858-Disconnect-LinkClose", + "SdkAppid":"1400798221", + "contenttype":"json", + "Sign":"c32ed26bfab2b71ffc4d93f209dade65a7fb8736138d0ca6f44af4c11ba66d2d", + "RequestTime":"1701047839" + } + * @return array + */ + public function userImLoginStatus(array $msg_data): array + { + $result = array(); + $result['message'] = ""; + $result['code'] = 0; + + if (empty($msg_data['Info'])){ + $result['message'] = "消息内容错误,缺少Info"; + return $result; + } + + if (empty($msg_data['Info']['To_Account'])){ + $result['message'] = "消息内容错误,缺少Info.To_Account"; + return $result; + } + + if (empty($msg_data['Info']['Action'])){ + $result['message'] = "消息内容错误,缺少Info.Action"; + return $result; + } + + if (empty($msg_data['Info']['Reason'])){ + $result['message'] = "消息内容错误,缺少Info.Reason"; + return $result; + } + + if (empty($msg_data['RequestTime'])){ + $result['message'] = "消息内容错误,缺少RequestTime"; + return $result; + } + + // 获取用户数据 + $params = array(); + $params['user_id'] = $msg_data['Info']['To_Account']; + $user = User::getOne($params); + if (empty($user)){ + $result['message'] = "消息内容错误,接收用户错误"; + return $result; + } + + Db::beginTransaction(); + try { + if ($msg_data['Info']['Action'] == "Login"){ + // 登陆 + $im_login_at = date('Y-m-d H:i:s',$msg_data['RequestTime']); + + // 修改用户表在线状态 + $params = array(); + $params['user_id'] = $user['user_id']; + + $data = array(); + if ($user['is_online'] == 0){ + $data['is_online'] = 1; + } + $data['im_login_at'] = $im_login_at; + $res = User::editUser($params,$data); + if (!$res){ + $result['message'] = "在线状态存储失败"; + return $result; + } + + Log::getInstance("UserService-userImLoginStatus")->info("用户已上线"); + } elseif ($msg_data['Info']['Action'] == "Disconnect"){ + // 点右上角退出/断网(如手机开启飞行模式)/微信切后台/杀掉微信进程 + $time = time() - $msg_data['RequestTime'] + 30*60; + if ($time <= 0){ + $time = 30 * 60; + } + + $data = array(); + $data['user_id'] = $user['user_id']; + + $message = new UserImOffDelayDirectProducer($data); + $message->setDelayMs(1000 * $time); + $producer = $this->container->get(Producer::class); + $res = $producer->produce($message); + if (!$res) { + $result['message'] = "添加下线队列失败"; + return $result; + } + Log::getInstance("UserService-userImLoginStatus")->info("已添加延迟下线队列"); + } elseif ($msg_data['Info']['Action'] == "Logout"){ + // 主动退出 + // 修改用户表在线状态 + if ($user['is_online'] == 1){ + $params = array(); + $params['user_id'] = $user['user_id']; + + $data = array(); + $data['is_online'] = 0; + $res = User::editUser($params,$data); + if (!$res){ + $result['message'] = "在线状态存储失败"; + return $result; + } + } + + Log::getInstance("UserService-userImLoginStatus")->info("用户已设下线"); + } + + Db::commit(); + }catch (\Throwable $e){ + Db::rollBack(); + $result['message'] = $e->getMessage(); + return $result; + } + + $result['message'] = "成功"; + $result['code'] = 1; + return $result; + } + + /** + * 处理用户im发送消息后回调 + * @param array $data im消息体 + * { + "CloudCustomData":"{\"order_inquiry_id\":\"581144270615580673\",\"is_system\":1,\"inquiry_type\":\"2\",\"message_rounds\":0,\"patient_family_data\":{\"patient_name\":\"貂蝉一\",\"patient_sex\":\"2\",\"patient_age\":\"32\"}}", + "MsgVersion":0, + "MsgBody":[ + { + "MsgType":"TIMCustomElem", + "MsgContent":{ + "Desc":"", + "Data":"{\"message_type\":11,\"title\":\"患者信息\",\"desc\":\"\",\"data\":{\"order_no\":\"581144270615580672\",\"disease_desc\":\"ᵀᵒᵈᵃʸ ᴵ ʷᵃⁿᵗ ᵗᵒ ᵇᵉ ᵗʰᵉ ʰᵃᵖᵖⁱᵉˢᵗ ᶜʰⁱˡᵈ ⁱⁿ ᵗʰᵉ ʷʰᵒˡᵉ ᵘⁿⁱᵛᵉʳˢᵉ.今天也要做全宇宙最快乐的小朋友 ​​\",\"message_path\":\"\\\/Pages\\\/yishi\\\/case\\\/index?order_inquiry_id=581144270615580673\"}}", + "Ext":"", + "Sound":"" + } + } + ], + "CallbackCommand":"C2C.CallbackAfterSendMsg", + "From_Account":"1682282293411975168", + "To_Account":"581056776246890497", + "MsgRandom":299670010, + "MsgSeq":2064411751, + "MsgTime":1699515713, + "SupportMessageExtension":0, + "MsgKey":"2064411751_299670010_1699515713", + "OnlineOnlyFlag":0, + "SendMsgResult":0, + "ErrorInfo":"send msg succeed", + "UnreadMsgNum":8, + "EventTime":1699515713924, + "ClientIP":"139.155.127.177", + "OptPlatform":"RESTAPI", + "RequestId":"37677-144115242877083697-1699515713-299670010", + "SdkAppid":"1400798221", + "contenttype":"json", + "Sign":"f6069aeb0c62cf3d77336794f7cf5a8543ddbff8c285f7341419df37ac713ff2", + "RequestTime":"1699515713" + } + * @return array + */ + public function userImAfterSendMsg(array $msg_data): array + { + $result = array(); + $result['message'] = ""; + $result['code'] = 0; + + // 验证消息内容 + if (empty($msg_data['MsgBody'])) { + $result['message'] = "消息内容错误,缺少MsgBody"; + return $result; + } + + // 验证消息内容类型 + if (empty($msg_data['MsgBody'][0]['MsgType'])) { + $result['message'] = "消息内容错误,缺少MsgType"; + return $result; + } + + // 验证消息内容详情 + if (empty($msg_data['MsgBody'][0]['MsgContent'])) { + $result['message'] = "消息内容错误,缺少MsgContent"; + return $result; + } + + // 验证接收方user_id + if (empty($msg_data['To_Account'])) { + $result['message'] = "消息内容错误,接收用户错误"; + return $result; + } + + // 验证消息唯一id + if (empty($msg_data['MsgKey'])) { + $result['message'] = "消息内容错误,消息唯一标识错误"; + return $result; + } + + // 处理自定义消息 + if ($msg_data['MsgBody'][0]['MsgType'] == "TIMCustomElem"){ + if (empty($msg_data['MsgBody'][0]['MsgContent']['Data'])){ + $result['message'] = "自定义消息数据类型错误"; + return $result; + } + + $content = json_decode($msg_data['MsgBody'][0]['MsgContent']['Data'],true); + if (empty($content)){ + $result['message'] = "自定义消息数据内容错误"; + return $result; + } + + if ($content['message_type'] == 4 || $content['message_type'] == 5){ + // 4/5类型时不进行处理 + $result['message'] = "成功"; + $result['code'] = 1; + return $result; + } + } + + // 验证消息重复性 + $params = array(); + $params['message_key'] = $msg_data['MsgKey']; + $message = MessageIm::getExists($params); + if ($message) { + $result['message'] = "消息重复"; + return $result; + } + + // 处理发送结果 + if ($msg_data['SendMsgResult'] == 0) { + // im中0表示成功 + $message_send_result = 1; + } + + // 验证自定义消息内容 + $is_system = 0;// 是否系统操作发送(0:否 1:是) + if (!empty($msg_data['CloudCustomData'])) { + $cloud_custom_data = json_decode($msg_data['CloudCustomData'], true); + + if (!empty($cloud_custom_data['order_inquiry_id'])) { + // 获取订单数据 + $params = array(); + $params['order_inquiry_id'] = $cloud_custom_data['order_inquiry_id']; + $order_inquiry = OrderInquiry::getOne($params); + if (empty($order_inquiry)) { + $result['message'] = "消息内容错误,非法订单"; + return $result; + } + + $order_inquiry_id = $cloud_custom_data['order_inquiry_id']; + } + + if (!empty($cloud_custom_data['is_system'])) { + if ($cloud_custom_data['is_system'] == 1) { + // 系统发送 + $is_system = 1; + } + } + } + + try { + // 入库 + $data = array(); + if (!empty($msg_data['From_Account'])) { + // 系统发送时不带参数 + $data['from_user_id'] = $msg_data['From_Account']; + } + $data['to_user_id'] = $msg_data['To_Account']; + $data['message_key'] = $msg_data['MsgKey']; + $data['message_send_time'] = $msg_data['RequestTime']; + $data['message_seq'] = $msg_data['MsgSeq']; + $data['message_send_result'] = $message_send_result ?? 0; + $data['send_error_info'] = $msg_data['ErrorInfo']; + $data['message_type'] = $msg_data['MsgBody'][0]['MsgType']; + + $data['is_system'] = $is_system; + if (!empty($order_inquiry_id)) { + $data['order_inquiry_id'] = $order_inquiry_id; + } + + $message_content = $msg_data['MsgBody'][0]['MsgContent']; + $data['message_content'] = json_encode($message_content, JSON_UNESCAPED_UNICODE); + $data['message_custom_content'] = $msg_data['CloudCustomData'] ?? ""; + $message = MessageIm::addMessage($data); + if (empty($message)) { + $result['message'] = "存储数据库失败"; + return $result; + } + + // im消息通知 + if ($is_system == 0 && isset($message_send_result) && isset($order_inquiry_id)){ + try { + $UserService = new UserService(); + $UserService->userImMessageNotice($msg_data['To_Account'],$order_inquiry_id,$msg_data['MsgBody']); + }catch (\Throwable $e){ + Log::getInstance("UserService-userImAfterSendMsg")->error("im消息通知失败"); + } + } + }catch (\Throwable $e){ + $result['message'] = $e->getMessage(); + return $result; + } + + $result['message'] = "成功"; + $result['code'] = 1; + return $result; + } } \ No newline at end of file diff --git a/composer.json b/composer.json index 0737866..01aefbc 100644 --- a/composer.json +++ b/composer.json @@ -95,5 +95,15 @@ "Composer\\Config::disableProcessTimeout", "php ./bin/hyperf.php start" ] - } + }, + "repositories":[ + { + "type": "composer", + "url": "https://mirrors.aliyun.com/composer/" + }, + { + "type": "composer", + "url": "https://packagist.phpcomposer.com" + } + ] } diff --git a/config/routes.php b/config/routes.php index 6be0c8f..d218763 100644 --- a/config/routes.php +++ b/config/routes.php @@ -21,10 +21,11 @@ use App\Controller\InquiryController; use App\Controller\LoginController; use App\Controller\CodeController; use App\Controller\MessageNoticeController; -use App\Controller\PatientCenterController; +use App\Controller\PatientCaseController; use App\Controller\PatientDoctorController; use App\Controller\PatientFamilyController; use App\Controller\PatientOrderController; +use App\Controller\PatientPathographyController; use App\Controller\SafeController; use App\Controller\SystemController; use App\Controller\TestController; @@ -33,7 +34,6 @@ use App\Controller\UserDoctorController; use App\Controller\UserPatientController; use App\Controller\UserPharmacistController; use App\Middleware\Rule\LockRequestMiddleware; -use App\Services\SafeService; use Hyperf\HttpServer\Router\Router; @@ -81,9 +81,6 @@ Router::addGroup('/doctor', function () { // 修改医生问诊配置 Router::put('/config', [UserDoctorController::class, 'putInquiryConfig']); - // 获取患者问诊病例 - Router::get('/case', [InquiryController::class, 'getPatientInquiryCase']); - // 获取医生问诊消息列表 Router::get('/message', [UserDoctorController::class, 'getDoctorMessageList']); @@ -126,7 +123,7 @@ Router::addGroup('/doctor', function () { // 获取我的账户数据 Router::get('', [DoctorAccountController::class, 'getDoctorAccount']); - // 获取我的账户日账单明细数据 + // 获取我的账户月账单明细数据 Router::get('/info', [DoctorAccountController::class, 'getDoctorAccountInfo']); }); @@ -375,7 +372,7 @@ Router::addGroup('/patient', function () { Router::post('', [PatientFamilyController::class, 'addFamilyHealth']); }); - // 药品 + // 用药记录 Router::addGroup('/product', function () { // 获取家庭成员用药记录列表 Router::get('/record', [PatientFamilyController::class, 'getFamilyProductRecord']); @@ -485,6 +482,24 @@ Router::addGroup('/patient', function () { // 获取患者系统消息通知最后一条消息 Router::get('/system/last', [MessageNoticeController::class, 'getPatientMessageServiceLast']); }); + + // 病情记录 + Router::addGroup('/pathography', function () { + // 检测家庭成员是否存在病情记录 + Router::get('/exist', [PatientPathographyController::class, 'existFamilyPathography']); + + // 获取家庭成员病情记录列表-分页 + Router::get('', [PatientPathographyController::class, 'getFamilyPathographyPage']); + + // 获取家庭成员病情记录详情 + Router::get('/{pathography_id:\d+}', [PatientPathographyController::class, 'getFamilyPathographyInfo']); + + // 获取家庭成员病情记录分组 + Router::get('/group', [PatientPathographyController::class, 'getFamilyPathographyGroup']); + + // 删除家庭成员病情记录 + Router::delete('/{pathography_id:\d+}', [PatientPathographyController::class, 'deleteFamilyPathography']); + }); }); // 药师端api @@ -704,12 +719,30 @@ Router::addGroup('/user', function () { Router::put('/system', [UserController::class, 'putUserSystem']); }); -// 获取患者问诊病例 -Router::get('/case', [InquiryController::class, 'getPatientInquiryCase']); +// 病例 +Router::addGroup('/case', function () { + // 获取问诊订单病例详情-基础 + Router::get('/inquiry/simple', [PatientCaseController::class, 'getPatientFamilyInquiryCaseSimple']); + + // 获取问诊订单病例详情 + Router::get('/inquiry', [PatientCaseController::class, 'getPatientFamilyInquiryCase']); + + // 病例未填字段 + Router::addGroup('/fields', function () { + // 获取问诊订单病例缺少字段 + Router::get('/unfilled', [PatientCaseController::class, 'getPatientFamilyInquiryCaseUnfilledFields']); + + // 医生发送缺少字段至患者 + Router::post('/doctor', [PatientCaseController::class, 'sendCaseUnfilledFieldsToPatient']); + + // 患者填写缺少字段至医生 + Router::post('/patient', [PatientCaseController::class, 'sendCaseUnfilledFieldsToDoctor']); + }); +}); // 测试使用 Router::addGroup('/test', function () { - Router::get('', [TestController::class, 'test']); + Router::get('', [TestController::class, 'test_17']); // Router::get('/uninquiry', [TestController::class, 'uninquiry']); @@ -762,3 +795,21 @@ Router::addGroup('/inquiry', function () { // 获取弹窗数据 Router::get('/popup', [UserController::class, 'getUserPopup']); + +// 病情记录 +Router::addGroup('/pathography', function () { + // 检测家庭成员是否存在病情记录 + Router::get('/exist', [PatientPathographyController::class, 'existFamilyPathography']); + + // 获取家庭成员病情记录列表-分页 + Router::get('', [PatientPathographyController::class, 'getFamilyPathographyPage']); + + // 获取家庭成员病情记录详情 + Router::get('/{pathography_id:\d+}', [PatientPathographyController::class, 'getFamilyPathographyInfo']); + + // 获取家庭成员病情记录分组 + Router::get('/group', [PatientPathographyController::class, 'getFamilyPathographyGroup']); + + // 删除家庭成员病情记录 + Router::delete('/{pathography_id:\d+}', [PatientPathographyController::class, 'deleteFamilyPathography']); +}); \ No newline at end of file diff --git a/extend/RegulatoryPlatform/regulatoryPlatform.php b/extend/RegulatoryPlatform/regulatoryPlatform.php index dc5ab7c..1d25f32 100644 --- a/extend/RegulatoryPlatform/regulatoryPlatform.php +++ b/extend/RegulatoryPlatform/regulatoryPlatform.php @@ -9,7 +9,7 @@ use GuzzleHttp\Client; use GuzzleHttp\Exception\GuzzleException; use Hyperf\Di\Annotation\Inject; use Hyperf\Redis\Redis; -use Hyperf\Utils\ApplicationContext; +use Hyperf\Context\ApplicationContext; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; @@ -35,9 +35,9 @@ class regulatoryPlatform public function __construct() { // 请求地址 - $this->api_url = config('regulatory_platform.api_url'); - $this->client_id = config('regulatory_platform.client_id'); - $this->client_secret = config('regulatory_platform.client_secret'); + $this->api_url = \Hyperf\Config\config('regulatory_platform.api_url'); + $this->client_id = \Hyperf\Config\config('regulatory_platform.client_id'); + $this->client_secret = \Hyperf\Config\config('regulatory_platform.client_secret'); $this->container = ApplicationContext::getContainer(); $this->client = $this->container->get(Client::class); } diff --git a/extend/Wechat/WechatPay.php b/extend/Wechat/WechatPay.php index 897f07d..2c7cd88 100644 --- a/extend/Wechat/WechatPay.php +++ b/extend/Wechat/WechatPay.php @@ -114,7 +114,7 @@ class WechatPay try { $app = new Application($config); - $request = ApplicationContext::getContainer()->get(RequestInterface::class); + $request = \Hyperf\Context\ApplicationContext::getContainer()->get(RequestInterface::class); $app->setRequest($request); return $app; } catch (InvalidArgumentException $e) {