diff --git a/app/Common/Common.php b/app/Common/Common.php index 8e29ab4..442ba8b 100644 --- a/app/Common/Common.php +++ b/app/Common/Common.php @@ -317,5 +317,37 @@ function couponScopeToString(int|string $application_scope): string } else { $result = ""; } + return $result; +} + +/** + * 转换服务包订单类型为汉字 + * @param int|string $order_service_type 服务包类型(1:健康包 2:随访包) + * @return string + */ +function orderServiceTypeToString(int|string $order_service_type): string +{ + if ($order_service_type == 1) { + $result = "健康包"; + } elseif ($order_service_type == 2) { + $result = "随访包"; + } else { + $result = "服务包"; + } + return $result; +} + +/** + * 转换每月次数为汉字 + * @param int|string $monthly_frequency 服务包类型(1:健康包 2:随访包) + * @return string + */ +function monthlyFrequencyToString(int|string $monthly_frequency): string +{ + $result = $monthly_frequency; + if ($monthly_frequency == 0) { + $result = "不限"; + } + return $result; } \ No newline at end of file diff --git a/app/Services/MessagePush.php b/app/Services/MessagePush.php index f3f54eb..8a4bd02 100644 --- a/app/Services/MessagePush.php +++ b/app/Services/MessagePush.php @@ -226,7 +226,7 @@ class MessagePush extends BaseService } /** - * 患者-通知患者医生已接诊 + * 患者-通知患者医生已接诊----- * 站内、订阅、短信 * @return void */ diff --git a/app/Services/MessagePushInquiryService.php b/app/Services/MessagePushInquiryService.php new file mode 100644 index 0000000..a7861d4 --- /dev/null +++ b/app/Services/MessagePushInquiryService.php @@ -0,0 +1,164 @@ +order['order_no']; + $order_inquiry = OrderInquiry::getOne($params); + if (empty($order_inquiry)){ + Log::getInstance("MessagePushInquiryService-patientDoctorAcceptedInquiry")->error("问诊订单数据为空"); + return; + } + + // 获取医生数据 + $params = array(); + $params['doctor_id'] = $this->order['doctor_id']; + $user_doctor = UserDoctor::getOne($params); + if (empty($user_doctor)) { + Log::getInstance("MessagePushInquiryService-patientDoctorAcceptedInquiry")->error("医生数据为空"); + return; + } + + // 站内 + $station_data = array(); + $station_data['user_id'] = $this->user['user_id']; + $station_data['notice_type'] = 3; + $station_data['notice_system_type'] = 1; + $station_data['from_name'] = "肝胆小秘书"; + $station_data['notice_brief_title'] = "{$user_doctor['user_name']}医生已接诊,请尽快和医生进行沟通交流病情,点击查看详情。"; + $station_data['notice_title'] = "{$user_doctor['user_name']}医生已接诊,请尽快和医生进行沟通交流病情,点击查看详情。"; + $station_data['notice_content'] = "{$user_doctor['user_name']}医生已接诊,请您尽快和医生进行沟通交流病情,您可以点击问诊详情进行交流。"; + $station_data['link_type'] = 1;// 聊天详情页 + + $link_params = array(); + $link_params['order_inquiry_id'] = $order_inquiry['order_inquiry_id']; + $link_params['inquiry_type'] = $order_inquiry['inquiry_type']; + $link_params['doctor_user_id'] = $user_doctor['user_id']; + $link_params['patient_user_id'] = $order_inquiry['user_id']; + $station_data['link_params'] = json_encode($link_params, JSON_UNESCAPED_UNICODE);// 跳转参数 + $station_data['button_type'] = 6; // 问诊详情 + + $message = new SendStationMessageProducer($station_data); + $producer = ApplicationContext::getContainer()->get(Producer::class); + $result = $producer->produce($message); + if (!$result) { + Log::getInstance("MessagePushInquiryService-patientDoctorAcceptedInquiry")->error(json_encode($station_data, JSON_UNESCAPED_UNICODE)); + } + + // 订阅 + // 获取问诊订单关联病例 + $params = array(); + $params['order_inquiry_id'] = $order_inquiry['order_inquiry_id']; + $order_inquiry_case = OrderInquiryCase::getOne($params); + if (empty($order_inquiry_case)) { + Log::getInstance("MessagePushInquiryService-patientDoctorAcceptedInquiry")->error("病例数据为空"); + return; + } + + // 问诊内容-病情主诉 + $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 . "..."; + } + } + } + + $sub_data = array(); + $sub_data['push_user_id'] = $this->user['user_id']; + $sub_data['wx_template_id'] = "9v6dZhjg09CttLd3W9nEUV_-eshNc4BYYNy59jglvZE";// 问诊提醒 + $sub_data['params']['page'] = "patient/pages/orderDetail/orderDetail?order_inquiry_id={$order_inquiry['order_inquiry_id']}"; + $sub_data['params']['data'] = [ + "thing1" => (string)$disease_desc,// 问诊内容-病情主诉 + "thing2" => "医生已接诊,请您尽快和医生沟通交流病情",// 提醒内容 + "name3" => (string)$user_doctor['user_name'],// 问诊医生 + "thing4" => "点击查看问诊订单详情",// 提示说明 + ]; + + $subscription_data = array(); + $subscription_data['sub_data'] = $sub_data; + $subscription_data['sms_data'] = array(); + + $message = new SendSubMessageProducer($subscription_data); + $producer = ApplicationContext::getContainer()->get(Producer::class); + $result = $producer->produce($message); + if (!$result) { + Log::getInstance("MessagePushInquiryService-patientDoctorAcceptedInquiry")->error(json_encode($subscription_data, JSON_UNESCAPED_UNICODE)); + } + + // 短信 + // 获取系统接诊配置 + $params = array(); + $params['inquiry_type'] = $order_inquiry['inquiry_type']; + $params['inquiry_mode'] = $order_inquiry['inquiry_mode']; + $system_inquiry_config = SystemInquiryConfig::getOne($params); + if (empty($system_inquiry_config)) { + Log::getInstance("MessagePushInquiryService-patientDoctorAcceptedInquiry")->error("获取系统接诊配置失败"); + return; + } + + // 问诊时长 + $duration = $system_inquiry_config['duration']; + if ($duration <= 0) { + $duration = "不限制"; + } else { + $duration = $duration . "分钟"; + } + + $data = array(); + $data['template_code'] = "SMS_271955088"; + $data['scene_desc'] = "通知患者医生已接诊"; + $data['phone'] = $this->user['mobile']; + $data['user_id'] = $this->user['user_id']; + + $template_param = array(); + $template_param['type'] = inquiryTypeToString($order_inquiry['inquiry_type']); + $template_param['name'] = $user_doctor['user_name']; + $template_param['duration'] = $duration; // 服务时长 + $data['template_param'] = $template_param; + + $message = new SendStationMessageProducer($data); + $producer = ApplicationContext::getContainer()->get(Producer::class); + $result = $producer->produce($message); + if (!$result) { + Log::getInstance("MessagePushInquiryService-patientDoctorAcceptedInquiry")->error(json_encode($data, JSON_UNESCAPED_UNICODE)); + } + }catch (\Throwable $e){ + Log::getInstance("MessagePushInquiryService-patientDoctorAcceptedInquiry")->error($e->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/Services/MessagePushService.php b/app/Services/MessagePushService.php new file mode 100644 index 0000000..dd0321c --- /dev/null +++ b/app/Services/MessagePushService.php @@ -0,0 +1,51 @@ +strategy = new MessagePushServicePackageService(); + }else{ + $this->strategy = new MessagePushInquiryService(); + } + + $this->strategy->order = $order->toArray(); + $this->strategy->user = $user->toArray(); + } + + /** + * 患者-通知患者医生已接诊 + * @return void + */ + public function patientDoctorAcceptedInquiry(): void + { + $this->strategy->patientDoctorAcceptedInquiry(); + } +} \ No newline at end of file diff --git a/app/Services/MessagePushServicePackageService.php b/app/Services/MessagePushServicePackageService.php new file mode 100644 index 0000000..79bdf9e --- /dev/null +++ b/app/Services/MessagePushServicePackageService.php @@ -0,0 +1,139 @@ +order['order_no']; + $order_inquiry = OrderInquiry::getOne($params); + if (empty($order_inquiry)){ + Log::getInstance("MessagePushServicePackageService-patientDoctorAcceptedInquiry")->error("问诊订单数据为空"); + return; + } + + // 获取医生数据 + $params = array(); + $params['doctor_id'] = $this->order['doctor_id']; + $user_doctor = UserDoctor::getOne($params); + if (empty($user_doctor)) { + Log::getInstance("MessagePushServicePackageService-patientDoctorAcceptedInquiry")->error("医生数据为空"); + return; + } + + // 站内 + // 获取服务包订单 + $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']; + $order_service_package_detail = OrderServicePackageDetail::getOne($params); + if (empty($order_service_package_detail)){ + Log::getInstance("MessagePushServicePackageService-patientDoctorAcceptedInquiry")->error("服务包订单数据为空"); + return; + } + + // 转换服务包订单类型为汉字 + $order_type = orderServiceTypeToString($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'])); + + // 站内 + $data = array(); + $data['user_id'] = $this->user['user_id']; + $data['notice_type'] = 3; + $data['notice_system_type'] = 1; + $data['from_name'] = "肝胆小秘书"; + $data['notice_brief_title'] = "您购买的{$order_type},医生已接诊,点击查看详情。"; + $data['notice_title'] = "您购买的{$order_type},{$user_doctor['user_name']}医生已接诊,每次问诊不限制沟通回合数,您可以点击【问诊详情】进行交流。"; + $data['notice_content'] = "您购买的{$order_type},{$user_doctor['user_name']}医生已接诊,每次问诊不限制沟通回合数,您可以点击【问诊详情】进行交流。"; + $data['link_type'] = 1;// 聊天详情页 + + $link_params = array(); + $link_params['order_inquiry_id'] = $order_inquiry['order_inquiry_id']; + $link_params['inquiry_type'] = $order_inquiry['inquiry_type']; + $link_params['doctor_user_id'] = $user_doctor['user_id']; + $link_params['patient_user_id'] = $order_inquiry['user_id']; + $data['link_params'] = json_encode($link_params, JSON_UNESCAPED_UNICODE);// 跳转参数 + $data['button_type'] = 6; // 问诊详情 + + $message = new SendStationMessageProducer($data); + $producer = ApplicationContext::getContainer()->get(Producer::class); + $result = $producer->produce($message); + if (!$result) { + Log::getInstance("MessagePushServicePackageService-patientDoctorAcceptedInquiry")->error(json_encode($data, JSON_UNESCAPED_UNICODE)); + } + + // 订阅 + $sub_data = array(); + $sub_data['push_user_id'] = $this->user['user_id']; + $sub_data['wx_template_id'] = "9v6dZhjg09CttLd3W9nEUV_-eshNc4BYYNy59jglvZE";// 问诊提醒 + $sub_data['params']['page'] = "patient/pages/orderDetail/orderDetail?order_inquiry_id={$order_inquiry['order_inquiry_id']}"; + $sub_data['params']['data'] = [ + "thing1" => $order_type . "服务", + "thing2" => "医生已接诊",// 提醒内容 + "name3" => (string)$user_doctor['user_name'],// 问诊医生 + "thing4" => "点击查看详情",// 提示说明 + ]; + + $subscription_data = array(); + $subscription_data['sub_data'] = $sub_data; + $subscription_data['sms_data'] = array(); + + $message = new SendSubMessageProducer($subscription_data); + $producer = ApplicationContext::getContainer()->get(Producer::class); + $result = $producer->produce($message); + if (!$result) { + Log::getInstance("MessagePushServicePackageService-patientDoctorAcceptedInquiry")->error(json_encode($subscription_data, JSON_UNESCAPED_UNICODE)); + } + + // 短信 + + }catch (\Throwable $e){ + Log::getInstance("MessagePushServicePackageService-patientDoctorAcceptedInquiry")->error($e->getMessage()); + } + } +} \ No newline at end of file