新增了消息推送策略模式发送
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user