From e92ccdcc5ea1127e6213420c2971c0d9861b512f Mon Sep 17 00:00:00 2001 From: wucongxing8150 <815046773@qq.com> Date: Fri, 19 Apr 2024 10:24:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=9C=8D=E5=8A=A1=E5=8C=85?= =?UTF-8?q?=E9=97=AE=E8=AF=8A=E8=AE=A2=E5=8D=95=E5=A2=9E=E5=8A=A0=E5=8C=BB?= =?UTF-8?q?=E7=94=9F=E6=9C=89=E6=96=B0=E6=9C=8D=E5=8A=A1=E5=8C=85=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E7=9A=84=E6=B6=88=E6=81=AF=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/CallBackController.php | 6 +- app/Services/MessagePush.php | 218 ++++++++++++++++-- app/Services/MessagePushService.php | 9 +- .../MessagePushServicePackageService.php | 80 ++++++- app/Services/OrderServicePackageService.php | 27 ++- 5 files changed, 302 insertions(+), 38 deletions(-) diff --git a/app/Controller/CallBackController.php b/app/Controller/CallBackController.php index 07cf5ea..b6f6a76 100644 --- a/app/Controller/CallBackController.php +++ b/app/Controller/CallBackController.php @@ -2784,9 +2784,9 @@ class CallBackController extends AbstractController // 等待医生接诊 $imService->waitDoctorInquiry($order_inquiry, $user_doctor['user_id'], $order_inquiry['user_id']); - // 发送站内、订阅失败发送短信消息-医生有新问诊 - $MessagePush = new MessagePush($user_doctor['user_id'], $order_inquiry['order_inquiry_id']); - $MessagePush->doctorHaveNewInquiry(); + // 发送站内、订阅失败发送短信消息-医生有新服务包订单 + $MessagePush = new MessagePush($user_doctor['user_id'], $order_service_package['order_service_no']); + $MessagePush->doctorHaveNewServicePackage(); // 加入xx时间未接诊通知队列 $data = array(); diff --git a/app/Services/MessagePush.php b/app/Services/MessagePush.php index f3f54eb..14f99f8 100644 --- a/app/Services/MessagePush.php +++ b/app/Services/MessagePush.php @@ -10,6 +10,7 @@ use App\Exception\BusinessException; use App\Model\BasicDetectionOrgan; use App\Model\DetectionProject; use App\Model\DoctorWithdrawal; +use App\Model\Order; use App\Model\OrderDetection; use App\Model\OrderInquiry; use App\Model\OrderInquiryCase; @@ -17,6 +18,8 @@ use App\Model\OrderInquiryCoupon; use App\Model\OrderPrescription; use App\Model\OrderProduct; use App\Model\OrderProductItem; +use App\Model\OrderServicePackage; +use App\Model\OrderServicePackageInquiry; use App\Model\Product; use App\Model\SystemInquiryConfig; use App\Model\User; @@ -33,33 +36,97 @@ use Psr\Container\NotFoundExceptionInterface; */ class MessagePush extends BaseService { - // 用户数据(存在被推送者时存在,否则为空) - public array $user = []; + // 被推送者用户数据(存在被推送者时存在,否则为空) + public ?array $user = null; - // 问诊订单数据(可为空) - public array $order_inquiry = []; + // 订单数据 + public ?array $order = null; + + // 服务包订单数据 + public ?array $order_service_package = null; + + // 问诊订单数据 + public ?array $order_inquiry = null; + + // 药品订单数据 + public ?array $order_product = null; + + // 检测订单数据 + public ?array $order_detection = null; /** * @param string $to_user_id 用户id(存在被推送者时存在,否则为空) - * @param string $order_inquiry_id 问诊订单id + * @param string $order_no 问诊订单编号 */ - public function __construct(string $to_user_id = "", string $order_inquiry_id = "") + public function __construct(string $to_user_id, string $order_no) { - if (!empty($to_user_id)) { - $params = array(); - $params['user_id'] = $to_user_id; - $user = User::getOne($params); - if (!empty($user)) { - $this->user = $user->toArray(); - } + $params = array(); + $params['user_id'] = $to_user_id; + $user = User::getOne($params); + if (!empty($user)) { + $this->user = $user->toArray(); } - if (!empty($order_inquiry_id)) { - $params = array(); - $params['order_inquiry_id'] = $order_inquiry_id; - $order_inquiry = OrderInquiry::getOne($params); - if (!empty($order_inquiry)) { - $this->order_inquiry = $order_inquiry->toArray(); + // 获取订单数据 + $params = array(); + $params['order_no'] = $order_no; + $order = Order::getOne($params); + if (!empty($order)){ + $this->order = $order->toArray(); + + // 判断订单类型 + switch ($order['order_type']) { + case 1: // 问诊订单 + $params = array(); + $params['inquiry_no'] = $order['order_no']; + $order_inquiry = OrderInquiry::getOne($params); + if (!empty($order_inquiry)) { + $this->order_inquiry = $order_inquiry->toArray(); + } + + break; + case 2: // 药品订单 + $params = array(); + $params['order_product_no'] = $order['order_no']; + $order_product = OrderProduct::getOne($params); + if (!empty($order_product)) { + $this->order_product = $order_product->toArray(); + } + + break; + case 3: // 检测订单 + $params = array(); + $params['detection_no'] = $order['order_no']; + $order_detection = OrderDetection::getOne($params); + if (!empty($order_detection)) { + $this->order_detection = $order_detection->toArray(); + } + + break; + case 4: // 健康包订单 + case 5: // 随访包订单 + $params = array(); + $params['inquiry_no'] = $order_no; + $order_inquiry = OrderInquiry::getOne($params); + if (!empty($order_inquiry)) { + $this->order_inquiry = $order_inquiry->toArray(); + + $params = array(); + $params['order_inquiry_id'] = $order_inquiry['order_inquiry_id']; + $order_service_package_inquiry = OrderServicePackageInquiry::getOne($params); + if (!empty($order_service_package_inquiry)){ + $params = array(); + $params['order_service_no'] = $order_service_package_inquiry['order_service_no']; + $order_service_package = OrderServicePackage::getOne($params); + if (!empty($order_service_package)){ + $this->order_service_package = $order_service_package->toArray(); + } + } + } + + break; + default: + throw new BusinessException("订单类型错误"); } } } @@ -2586,4 +2653,117 @@ class MessagePush extends BaseService Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . $e->getMessage()); } } + + /** + * 医生-医生有新服务包订单 + * 站内、订阅失败发送短信 + * @return void + */ + public function doctorHaveNewServicePackage(): void + { + try { + // 获取医生数据 + $params = array(); + $params['doctor_id'] = $this->order_inquiry['doctor_id']; + $user_doctor = UserDoctor::getOne($params); + if (empty($user_doctor)) { + Log::getInstance("MessagePush")->error("错误:医生数据为空"); + return; + } + + // 获取问诊订单关联病例 + $params = array(); + $params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id']; + $order_inquiry_case = OrderInquiryCase::getOne($params); + if (empty($order_inquiry_case)) { + Log::getInstance("MessagePush")->error("病例数据为空"); + return; + } + + // 转换服务包订单类型为汉字 + $order_type = orderServiceTypeToString($this->order_service_package['order_service_type']); + + // 站内 + $data = array(); + $data['user_id'] = $this->user['user_id']; + $data['notice_type'] = 1; + $data['inquiry_type'] = $this->order_inquiry['inquiry_type']; // 问诊类型(医生端服务通知存在 1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药) + $data['from_name'] = "肝胆小秘书"; + $data['notice_brief_title'] = "您有新的{$order_type}服务等待接诊,请及时处理。"; + $data['notice_title'] = "您有新的{$order_type}服务等待接诊,请及时处理。"; + $data['notice_content'] = "您有新的{$order_type}服务等待接诊,请及时处理。"; + $data['link_type'] = 3; // 问诊消息列表页 + + $link_params = array(); + $link_params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id']; + $link_params['inquiry_type'] = $this->order_inquiry['inquiry_type']; + $link_params['doctor_user_id'] = $user_doctor['user_id']; + $link_params['patient_user_id'] = $this->order_inquiry['user_id']; + $data['link_params'] = json_encode($link_params, JSON_UNESCAPED_UNICODE);// 跳转参数 + + $message = new SendStationMessageProducer($data); + $producer = ApplicationContext::getContainer()->get(Producer::class); + $result = $producer->produce($message); + if (!$result) { + Log::getInstance("MessagePush")->error(json_encode($data, JSON_UNESCAPED_UNICODE)); + } + + // 订阅 + // 问诊内容-病情主诉 + $disease_desc = $order_inquiry_case['disease_desc']; + if (!empty($disease_desc)) { + if (strlen($disease_desc) > 15) { + $disease_desc = mb_substr($disease_desc, 0, 15); + if ($disease_desc) { + $disease_desc = $disease_desc . "..."; + } + } + } + + if ($this->order_inquiry['inquiry_type'] == 1 || $this->order_inquiry['inquiry_type'] == 3) { + // 专家、公益 + $thing6 = "24小时内未接诊,平台将自动取消问诊"; + } else { + // 快速、购药 + $thing6 = "5分钟内未接诊,平台将自动取消问诊"; + } + + $sub_data = array(); + $sub_data['push_user_id'] = $this->user['user_id']; + $sub_data['wx_template_id'] = "G1RIs0RYqsTQ2CuPQWalIMyb6_deuEEbJfajfhGvNzc";//咨询提醒 + $sub_data['params']['page'] = "Pages/yishi/wenzhen_v2/wenzhen"; + $sub_data['params']['data'] = [ + "thing1" => "您有一个{$order_type}服务等待接诊",// 提醒内容 + "name2" => (string)$this->order_inquiry['patient_name'],// 患者姓名 + "thing4" => (string)$disease_desc,// 病情描述 + "thing6" => $thing6,// 提示说明 + "thing5" => "72小时内未接诊,平台将自送取消服务",// 咨询内容 + ]; + + // 短信 + $sms_data = array(); + $sms_data['template_code'] = "SMS_272015117"; + $sms_data['scene_desc'] = "医生接到新服务包服务"; + $sms_data['phone'] = $this->user['mobile']; + $sms_data['user_id'] = $this->user['user_id']; + + $template_param = array(); + $template_param['type'] = $order_type; + $sms_data['template_param'] = $template_param; + + $data = array(); + $data['sub_data'] = $sub_data; + $data['sms_data'] = $sms_data; + + $message = new SendSubMessageProducer($data); + $producer = ApplicationContext::getContainer()->get(Producer::class); + $result = $producer->produce($message); + if (!$result) { + Log::getInstance("MessagePush")->error(json_encode($data, JSON_UNESCAPED_UNICODE)); + } + } catch (\Throwable $e) { + Log::getInstance("MessagePush")->error( $e->getMessage()); + } + } + } \ No newline at end of file diff --git a/app/Services/MessagePushService.php b/app/Services/MessagePushService.php index dd0321c..54e4bd1 100644 --- a/app/Services/MessagePushService.php +++ b/app/Services/MessagePushService.php @@ -31,7 +31,7 @@ class MessagePushService extends BaseService } if ($order['order_type'] == 4 || $order['order_type'] == 5){ - $this->strategy = new MessagePushServicePackageService(); + $this->strategy = new MessagePushServicePackageService($order_no); }else{ $this->strategy = new MessagePushInquiryService(); } @@ -48,4 +48,11 @@ class MessagePushService extends BaseService { $this->strategy->patientDoctorAcceptedInquiry(); } + + // 医生-服务包待接诊 + // 仅限于患者购买服务包后,首次发起问诊后使用 + public function doctorWaitInquiry(): void + { + $this->strategy->doctorWaitInquiry(); + } } \ No newline at end of file diff --git a/app/Services/MessagePushServicePackageService.php b/app/Services/MessagePushServicePackageService.php index 79bdf9e..a8258b6 100644 --- a/app/Services/MessagePushServicePackageService.php +++ b/app/Services/MessagePushServicePackageService.php @@ -28,6 +28,26 @@ class MessagePushServicePackageService extends BaseService // 订单数据 public ?array $order = null; + // 服务包订单数据 + public ?array $order_service_package = null; + + // 问诊订单数据 + public ?array $order_inquiry = null; + + public function __construct(string $order_no){ + // 获取订单数据 + $params = array(); + $params['order_service_no'] = $order_no; + $order_service_package = OrderServicePackage::getOne($params); + if (empty($order_service_package)){ + throw new BusinessException("订单数据错误"); + } + + $this->order_service_package = $order_service_package->toArray(); + + $params = array(); + } + /** * 患者-通知患者医生已接诊 * @return void @@ -54,15 +74,6 @@ class MessagePushServicePackageService extends BaseService } // 站内 - // 获取服务包订单 - $params = array(); - $params['order_service_no'] = $this->order['order_no']; - $order_service_package = OrderServicePackage::getOne($params); - if (empty($order_service_package)){ - Log::getInstance("MessagePushServicePackageService-patientDoctorAcceptedInquiry")->error("服务包订单数据为空"); - return; - } - // 获取服务包订单详情 $params = array(); $params['order_service_no'] = $this->order['order_no']; @@ -73,13 +84,13 @@ class MessagePushServicePackageService extends BaseService } // 转换服务包订单类型为汉字 - $order_type = orderServiceTypeToString($order_service_package['order_service_type']); + $order_type = orderServiceTypeToString($this->order_service_package['order_service_type']); // 转换每月次数为汉字 $monthly_frequency = monthlyFrequencyToString($order_service_package_detail['monthly_frequency']); - $start_time = date('Y年m月d日 H时i分',strtotime($order_service_package['start_time'])); - $finish_time = date('Y年m月d日 H时i分',strtotime($order_service_package['finish_time'])); + $start_time = date('Y年m月d日 H时i分',strtotime($this->order_service_package['start_time'])); + $finish_time = date('Y年m月d日 H时i分',strtotime($this->order_service_package['finish_time'])); // 站内 $data = array(); @@ -136,4 +147,49 @@ class MessagePushServicePackageService extends BaseService Log::getInstance("MessagePushServicePackageService-patientDoctorAcceptedInquiry")->error($e->getMessage()); } } + + // 医生-服务包待接诊 + // 仅限于患者购买服务包后,首次发起问诊后使用 + public function doctorWaitInquiry() + { + try { + // 获取医生数据 + $params = array(); + $params['doctor_id'] = $this->order['doctor_id']; + $user_doctor = UserDoctor::getOne($params); + if (empty($user_doctor)) { + Log::getInstance("MessagePushServicePackageService-doctorWaitInquiry")->error("医生数据为空"); + return; + } + + + // 站内 + $data = array(); + $data['user_id'] = $this->user['user_id']; + $data['notice_type'] = 1; + $data['inquiry_type'] = 1; // 问诊类型(医生端服务通知存在 1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药) + $data['from_name'] = "肝胆小秘书"; + $data['notice_brief_title'] = "您有新的问诊咨询,请及时处理。"; + $data['notice_title'] = "您有新的问诊咨询,请及时处理。"; + $data['notice_content'] = "您有新的问诊咨询,请及时处理。"; + $data['link_type'] = 3; // 问诊消息列表页 + + $link_params = array(); + $link_params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id']; + $link_params['inquiry_type'] = $this->order_inquiry['inquiry_type']; + $link_params['doctor_user_id'] = $user_doctor['user_id']; + $link_params['patient_user_id'] = $this->order_inquiry['user_id']; + $data['link_params'] = json_encode($link_params, JSON_UNESCAPED_UNICODE);// 跳转参数 + + $message = new SendStationMessageProducer($data); + $producer = ApplicationContext::getContainer()->get(Producer::class); + $result = $producer->produce($message); + if (!$result) { + Log::getInstance("MessagePush")->error("错误:加入站内推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE)); + } + + }catch (\Throwable $e){ + Log::getInstance("MessagePushServicePackageService-doctorWaitInquiry")->error($e->getMessage()); + } + } } \ No newline at end of file diff --git a/app/Services/OrderServicePackageService.php b/app/Services/OrderServicePackageService.php index 5bc717f..a35d557 100644 --- a/app/Services/OrderServicePackageService.php +++ b/app/Services/OrderServicePackageService.php @@ -986,9 +986,9 @@ class OrderServicePackageService extends BaseService // 等待医生接诊 $imService->waitDoctorInquiry($order_inquiry, $user_doctor['user_id'], $order_inquiry['user_id']); - // 发送站内、订阅失败发送短信消息-医生有新问诊 - $MessagePush = new MessagePush($user_doctor['user_id'], $order_inquiry['order_inquiry_id']); - $MessagePush->doctorHaveNewInquiry(); + // 发送站内、订阅失败发送短信消息-医生有新服务包订单 + $MessagePush = new MessagePush($user_doctor['user_id'], $order_service_package['order_service_no']); + $MessagePush->doctorHaveNewServicePackage(); // 加入xx时间未接诊通知队列 $data = array(); @@ -1282,4 +1282,25 @@ class OrderServicePackageService extends BaseService return $remaining_quantity; } + + /** + * 检测问诊是否服务包首次问诊 + * @param string|int $order_no + * @return bool + */ + public function isFirstInquiryServicePackage(string|int $order_no): bool + { + $params = array(); + $params['order_service_no'] = $order_no; + $order_service_package_inquiry = OrderServicePackageInquiry::getList($params); + if (empty($order_service_package_inquiry)){ + return true; + } + + if (count($order_service_package_inquiry) == 1){ + return true; + } + + return false; + } } \ No newline at end of file