新增了消息推送策略模式发送
This commit is contained in:
parent
581111bdbe
commit
73e167d42a
@ -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;
|
||||
}
|
||||
@ -226,7 +226,7 @@ class MessagePush extends BaseService
|
||||
}
|
||||
|
||||
/**
|
||||
* 患者-通知患者医生已接诊
|
||||
* 患者-通知患者医生已接诊-----
|
||||
* 站内、订阅、短信
|
||||
* @return void
|
||||
*/
|
||||
|
||||
164
app/Services/MessagePushInquiryService.php
Normal file
164
app/Services/MessagePushInquiryService.php
Normal file
@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Amqp\Producer\SendStationMessageProducer;
|
||||
use App\Amqp\Producer\SendSubMessageProducer;
|
||||
use App\Exception\BusinessException;
|
||||
use App\Model\Order;
|
||||
use App\Model\OrderInquiry;
|
||||
use App\Model\OrderInquiryCase;
|
||||
use App\Model\SystemInquiryConfig;
|
||||
use App\Model\User;
|
||||
use App\Model\UserDoctor;
|
||||
use App\Utils\Log;
|
||||
use Hyperf\Amqp\Producer;
|
||||
use Hyperf\Context\ApplicationContext;
|
||||
|
||||
/**
|
||||
* 消息推送业务类-问诊
|
||||
*/
|
||||
class MessagePushInquiryService extends BaseService
|
||||
{
|
||||
// 被推送者用户数据
|
||||
public ?array $user = null;
|
||||
|
||||
// 订单数据
|
||||
public ?array $order = null;
|
||||
|
||||
/**
|
||||
* 患者-通知患者医生已接诊
|
||||
* @return void
|
||||
*/
|
||||
public function patientDoctorAcceptedInquiry(): void
|
||||
{
|
||||
try {
|
||||
// 获取问诊订单数据
|
||||
$params = array();
|
||||
$params['inquiry_no'] = $this->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());
|
||||
}
|
||||
}
|
||||
}
|
||||
51
app/Services/MessagePushService.php
Normal file
51
app/Services/MessagePushService.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Exception\BusinessException;
|
||||
use App\Model\Order;
|
||||
use App\Model\User;
|
||||
|
||||
class MessagePushService extends BaseService
|
||||
{
|
||||
private MessagePushServicePackageService|MessagePushInquiryService $strategy;
|
||||
|
||||
/**
|
||||
* @param string $to_user_id 用户id(存在被推送者时存在,否则为空)
|
||||
* @param string $order_no 问诊订单系统订单编号
|
||||
*/
|
||||
public function __construct(string $to_user_id, string $order_no){
|
||||
$params = array();
|
||||
$params['user_id'] = $to_user_id;
|
||||
$user = User::getOne($params);
|
||||
if (empty($user)){
|
||||
throw new BusinessException("用户数据错误");
|
||||
}
|
||||
|
||||
// 获取订单数据
|
||||
$params = array();
|
||||
$params['order_no'] = $order_no;
|
||||
$order = Order::getOne($params);
|
||||
if (empty($order)){
|
||||
throw new BusinessException("订单数据错误");
|
||||
}
|
||||
|
||||
if ($order['order_type'] == 4 || $order['order_type'] == 5){
|
||||
$this->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();
|
||||
}
|
||||
}
|
||||
139
app/Services/MessagePushServicePackageService.php
Normal file
139
app/Services/MessagePushServicePackageService.php
Normal file
@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Amqp\Producer\SendStationMessageProducer;
|
||||
use App\Amqp\Producer\SendSubMessageProducer;
|
||||
use App\Exception\BusinessException;
|
||||
use App\Model\Order;
|
||||
use App\Model\OrderInquiry;
|
||||
use App\Model\OrderInquiryCase;
|
||||
use App\Model\OrderServicePackage;
|
||||
use App\Model\OrderServicePackageDetail;
|
||||
use App\Model\SystemInquiryConfig;
|
||||
use App\Model\User;
|
||||
use App\Model\UserDoctor;
|
||||
use App\Utils\Log;
|
||||
use Hyperf\Amqp\Producer;
|
||||
use Hyperf\Context\ApplicationContext;
|
||||
|
||||
/**
|
||||
* 消息推送业务类-服务包问诊订单
|
||||
*/
|
||||
class MessagePushServicePackageService extends BaseService
|
||||
{
|
||||
// 被推送者用户数据
|
||||
public ?array $user = null;
|
||||
|
||||
// 订单数据
|
||||
public ?array $order = null;
|
||||
|
||||
/**
|
||||
* 患者-通知患者医生已接诊
|
||||
* @return void
|
||||
*/
|
||||
public function patientDoctorAcceptedInquiry(): void
|
||||
{
|
||||
try {
|
||||
// 获取问诊订单数据
|
||||
$params = array();
|
||||
$params['inquiry_no'] = $this->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());
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user