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