新增消息推送,修改订阅消息推送队列

This commit is contained in:
wucongxing 2023-03-29 20:33:01 +08:00
parent 57e0489fb4
commit 4ca988f3a2
4 changed files with 219 additions and 61 deletions

View File

@ -98,18 +98,6 @@ class SendSubMessageConsumer extends ConsumerMessage
return Result::ACK;
}
// 获取消息模版
$sub_template = $this->getSubTemplate($user['user_type'],$data['sub_data']['template_title']);
if (empty($sub_template)){
Log::getInstance()->error("订阅消息推送执行失败:未获取到需要发送的消息模版数据");
$this->saveErrorPushLog($user['user_type'],$data['sub_data'],"未获取到需要发送的消息模版数据");
// 执行发送短信步骤
$this->addSendSmsMessageQueue($data['sms_data']);
return Result::ACK;
}
// 处理发送环境
// $miniprogram_state = "developer";
$miniprogram_state = "trial";
@ -118,16 +106,14 @@ class SendSubMessageConsumer extends ConsumerMessage
}
$options = [
"template_id" => $sub_template['wx_template_id'],
"page" => $sub_template['page'] ?: $data['sub_data']['params']['page'] ?: "",
"template_id" => $data['sub_data']['wx_template_id'],
"page" => $data['sub_data']['params']['page'] ?: "",
"touser" => $open_id,
"data" => $send_data,
"miniprogram_state" => $miniprogram_state,
"lang" => "zh_CN",
];
dump($options);
// 发起推送
$Wechat = new Wechat($user['user_type']);
$result = $Wechat->sendSubscribeMessage($options);

View File

@ -19,7 +19,7 @@ class SendSubMessageProducer extends ProducerMessage
* [
* "sub_data" => [
* "push_user_id" // 用户id被推送者
* "template_title" // 推送的模版名称
* "wx_template_id" // 推送的模版id
* "params" => [ // 推送所需的参数
* "page" // 跳转页面
* "data" => [

View File

@ -104,4 +104,5 @@ class DoctorWithdrawal extends Model
return $data;
}
}

View File

@ -7,6 +7,7 @@ use App\Amqp\Producer\SendStationMessageProducer;
use App\Amqp\Producer\SendSubMessageProducer;
use App\Constants\HttpEnumCode;
use App\Exception\BusinessException;
use App\Model\DoctorWithdrawal;
use App\Model\OrderInquiry;
use App\Model\OrderInquiryCase;
use App\Model\OrderPrescription;
@ -67,6 +68,7 @@ class MessagePush extends BaseService
}
/**
* 医生未接诊
* 快速/购药的服务5分钟未接诊
* 公益/专家24小时未接诊
* 站内、订阅
@ -74,7 +76,7 @@ class MessagePush extends BaseService
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function noInquiry(): bool
public function patientNoInquiry(): bool
{
try {
if ($this->push_type == 1) {
@ -124,7 +126,7 @@ class MessagePush extends BaseService
$sub_data = array();
$sub_data['push_user_id'] = $this->user['user_id'];
$sub_data['template_title'] = "问诊异常通知";
$sub_data['wx_template_id'] = "UOMww1S30Oq7rErJrqO8wN6lNEVKRo2fgcXnb0tBwHI";//问诊异常通知
$sub_data['params']['page'] = "pages/orderDetail/orderDetail?order_inquiry_id={$this->order_inquiry['order_inquiry_id']}";
$sub_data['params']['data'] = [
"character_string1" => $this->order_inquiry['inquiry_no'],// 订单ID
@ -154,7 +156,7 @@ class MessagePush extends BaseService
}
/**
* 患者回复通知
* 通知医生患者回复
* 订阅
* @param string $content 回复内容
* @return bool
@ -168,7 +170,7 @@ class MessagePush extends BaseService
if ($this->push_type == 2){
$sub_data = array();
$sub_data['push_user_id'] = $this->user['user_id'];
$sub_data['template_title'] = "患者回复通知";
$sub_data['wx_template_id'] = "jhYUf91ULCTX_f69hazqAYwImdFf8ELasRAwB6X-MTM"; // 患者回复通知
$sub_data['params']['page'] = "Pages/yishi/wenzhen_v2/wenzhen";
$sub_data['params']['data'] = [
"thing1" => $this->user['user_name'],// 患者姓名
@ -193,13 +195,13 @@ class MessagePush extends BaseService
}
/**
* 医生已接诊
* 通知患者医生已接诊
* 站内、订阅、短信
* @return bool
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function doctorAcceptedInquiry(): bool
public function patientAcceptedInquiry(): bool
{
try {
// 获取医生数据
@ -241,7 +243,7 @@ class MessagePush extends BaseService
// 订阅
$sub_data = array();
$sub_data['push_user_id'] = $this->user['user_id'];
$sub_data['template_title'] = "问诊提醒";
$sub_data['wx_template_id'] = "9v6dZhjg09CttLd3W9nEUV_-eshNc4BYYNy59jglvZE";// 问诊提醒
$sub_data['params']['page'] = "pages/orderDetail/orderDetail?order_inquiry_id={$this->order_inquiry['order_inquiry_id']}";
$sub_data['params']['data'] = [
"thing1" => "问诊内容",// 问诊内容
@ -281,7 +283,7 @@ class MessagePush extends BaseService
$data = array();
$data['template_code'] = "SMS_271955088";
$data['scene_desc'] = "医生已接诊";
$data['scene_desc'] = "通知患者医生已接诊";
$data['phone'] = $this->user['mobile'];
$data['user_id'] = $this->user['user_id'];
@ -307,13 +309,13 @@ class MessagePush extends BaseService
}
/**
* 服务结束
* 患者的问诊服务结束
* 站内、订阅
* @return bool
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function inquiryFinish(): bool
public function patientInquiryFinish(): bool
{
try {
// 获取医生数据
@ -358,7 +360,7 @@ class MessagePush extends BaseService
// 订阅
$sub_data = array();
$sub_data['push_user_id'] = $this->user['user_id'];
$sub_data['template_title'] = "问诊提醒";
$sub_data['wx_template_id'] = "9v6dZhjg09CttLd3W9nEUV_-eshNc4BYYNy59jglvZE"; // 问诊提醒
$sub_data['params']['page'] = "pages/orderDetail/orderDetail?order_inquiry_id={$this->order_inquiry['order_inquiry_id']}";
$sub_data['params']['data'] = [
"thing1" => "问诊内容",// 问诊内容
@ -386,13 +388,13 @@ class MessagePush extends BaseService
}
/**
* 处方审核通过
* 患者的处方被药师审核通过
* 站内、短信
* @return bool
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function prescriptionVerifyPass(): bool
public function patientPrescriptionVerifyPass(): bool
{
try {
// 获取医生数据
@ -470,7 +472,7 @@ class MessagePush extends BaseService
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function distributeCoupon(): bool
public function patientDistributeCoupon(): bool
{
try {
// 获取医生数据
@ -522,7 +524,7 @@ class MessagePush extends BaseService
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function refundCoupon(): bool
public function patientRefundCoupon(): bool
{
try {
// 获取医生数据
@ -574,7 +576,7 @@ class MessagePush extends BaseService
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function expireCoupon(): bool
public function patientExpireCoupon(): bool
{
try {
// 获取医生数据
@ -682,7 +684,7 @@ class MessagePush extends BaseService
// 订阅
$sub_data = array();
$sub_data['push_user_id'] = $this->user['user_id'];
$sub_data['template_title'] = "问诊异常通知";
$sub_data['wx_template_id'] = "UOMww1S30Oq7rErJrqO8wN6lNEVKRo2fgcXnb0tBwHI"; //问诊异常通知
$sub_data['params']['page'] = "pages/orderDetail/orderDetail?order_inquiry_id={$this->order_inquiry['order_inquiry_id']}";
$sub_data['params']['data'] = [
"character_string1" => $this->order_inquiry['inquiry_no'],// 订单ID
@ -799,7 +801,7 @@ class MessagePush extends BaseService
// 订阅
$sub_data = array();
$sub_data['push_user_id'] = $this->user['user_id'];
$sub_data['template_title'] = "药品订单取消通知";
$sub_data['wx_template_id'] = "gQO5vhPQfdnvXtK0XnGns1XqNhQpOrXTjdl-5HWWMUw";//药品订单取消通知
$sub_data['params']['page'] = "pages/orderDetail/orderDetail?order_inquiry_id={$this->order_inquiry['order_inquiry_id']}";
$sub_data['params']['data'] = [
"character_string3" => $order_product['order_product_no'],// 订单号
@ -917,7 +919,7 @@ class MessagePush extends BaseService
// 订阅
$sub_data = array();
$sub_data['push_user_id'] = $this->user['user_id'];
$sub_data['template_title'] = "药品发货通知";
$sub_data['wx_template_id'] = "YFdVxDclV1ZjhS7E4Cs0zFdshTRizERpwYdZizj_UWo"; // 药品发货通知
$sub_data['params']['page'] = "pages/orderDetail/orderDetail?order_inquiry_id={$this->order_inquiry['order_inquiry_id']}";
$sub_data['params']['data'] = [
"character_string9" => $order_product['order_product_no'],// 快递单号
@ -983,13 +985,13 @@ class MessagePush extends BaseService
}
/**
* 新问诊
* 医生有新问诊
* 站内、订阅失败发送短信
* @return bool
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function newInquiry(): bool
public function doctorHaveNewInquiry(): bool
{
try {
// 获取医生数据
@ -1031,8 +1033,7 @@ class MessagePush extends BaseService
$sub_data = array();
$sub_data['push_user_id'] = $this->user['user_id'];
$sub_data['template_title'] = "咨询提醒";
// $sub_data['params']['page'] = "Pages/yishi/chat/index?from_account={$this->order_inquiry['user_id']}&order_inquiry_id={$this->order_inquiry['order_inquiry_id']}&inquiry_type={$this->order_inquiry['inquiry_type']}";
$sub_data['wx_template_id'] = "G1RIs0RYqsTQ2CuPQWalIMyb6_deuEEbJfajfhGvNzc";//咨询提醒
$sub_data['params']['page'] = "Pages/yishi/wenzhen_v2/wenzhen";
$sub_data['params']['data'] = [
"thing1" => "您有新的患者向您发起了({$inquiry_type})服务,请您尽快上线接诊;",// 提醒内容
@ -1125,8 +1126,7 @@ class MessagePush extends BaseService
$sub_data = array();
$sub_data['push_user_id'] = $this->user['user_id'];
$sub_data['template_title'] = "咨询提醒";
// $sub_data['params']['page'] = "Pages/yishi/chat/index?from_account={$this->order_inquiry['user_id']}&order_inquiry_id={$this->order_inquiry['order_inquiry_id']}&inquiry_type={$this->order_inquiry['inquiry_type']}";
$sub_data['wx_template_id'] = "G1RIs0RYqsTQ2CuPQWalIMyb6_deuEEbJfajfhGvNzc"; // 咨询提醒
$sub_data['params']['page'] = "Pages/yishi/wenzhen_v2/wenzhen";
$sub_data['params']['data'] = [
"thing1" => "您好医生,{$this->order_inquiry['patient_name']}患者的({$inquiry_type})服务您还未接诊;",// 提醒内容
@ -1268,7 +1268,7 @@ class MessagePush extends BaseService
// 订阅
$sub_data = array();
$sub_data['push_user_id'] = $this->user['user_id'];
$sub_data['template_title'] = "处方审核结果通知";
$sub_data['wx_template_id'] = "kUy70xHlr7ADo4aIHiictM4Te7MSec3E5kHsYvFQu40"; // 处方审核结果通知
$sub_data['params']['page'] = "Pages/yishi/chufangsetup/index";
$sub_data['params']['data'] = [
"phrase1" => "药师审方通过",// 审核结果
@ -1329,7 +1329,7 @@ class MessagePush extends BaseService
// 订阅
$sub_data = array();
$sub_data['push_user_id'] = $this->user['user_id'];
$sub_data['template_title'] = "处方审核结果通知";
$sub_data['wx_template_id'] = "kUy70xHlr7ADo4aIHiictM4Te7MSec3E5kHsYvFQu40"; // 处方审核结果通知
$sub_data['params']['page'] = "Pages/yishi/chufangsetup/index";
$sub_data['params']['data'] = [
"phrase1" => "药师审方不通过",// 审核结果
@ -1477,7 +1477,7 @@ class MessagePush extends BaseService
$sub_data = array();
$sub_data['push_user_id'] = $this->user['user_id'];
$sub_data['template_title'] = "审核结果通知";
$sub_data['wx_template_id'] = "XWfEQYtb8_ubz8pCs3GoCG6TFxpDz9jn52895yvDm3s";// 审核结果通知
$sub_data['params']['page'] = "Pages/index/index";
$sub_data['params']['data'] = [
"thing1" => "多点执业认证审核通过",// 审核结果
@ -1558,7 +1558,7 @@ class MessagePush extends BaseService
$sub_data = array();
$sub_data['push_user_id'] = $this->user['user_id'];
$sub_data['template_title'] = "资格审核未通过通知";
$sub_data['wx_template_id'] = "bGGoKtDZC23GZtrrxuy6i5V7OhHgRgwXWx4yoDO1tlA";//资格审核未通过通知
$sub_data['params']['page'] = "Pages/index/index";
$sub_data['params']['data'] = [
"thing1" => "{$this->user['user_name']}医生您好,多点执业认证审核没有通过,请重新提交",// 温馨提示
@ -1631,7 +1631,7 @@ class MessagePush extends BaseService
// 订阅
$sub_data = array();
$sub_data['push_user_id'] = $this->user['user_id'];
$sub_data['template_title'] = "审核结果通知";
$sub_data['wx_template_id'] = "XWfEQYtb8_ubz8pCs3GoCG6TFxpDz9jn52895yvDm3s"; // 审核结果通知
$sub_data['params']['page'] = "Pages/index/index";
$sub_data['params']['data'] = [
"thing1" => "医师简介审核通过;",// 审核结果
@ -1711,7 +1711,7 @@ class MessagePush extends BaseService
$sub_data = array();
$sub_data['push_user_id'] = $this->user['user_id'];
$sub_data['template_title'] = "资格审核未通过通知";
$sub_data['wx_template_id'] = "bGGoKtDZC23GZtrrxuy6i5V7OhHgRgwXWx4yoDO1tlA"; // 资格审核未通过通知
$sub_data['params']['page'] = "Pages/index/index";
$sub_data['params']['data'] = [
"thing1" => "{$this->user['user_name']}医生您好,简介信息审核没有通过,请重新提交",// 温馨提示
@ -1748,32 +1748,48 @@ class MessagePush extends BaseService
}
/**
* 医师服务费结算结果
* 医师服务费结算成功
* 站内、短信
* @param string $order_product_id
* @param string $withdrawal_id
* @return bool
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function doctorSettlementResult(string $order_product_id): bool
public function doctorSettlementSuccess(string $withdrawal_id): bool
{
try {
// 获取医生提现表数据
$params = array();
$params['withdrawal_id'] = $withdrawal_id;
$doctor_withdrawal = DoctorWithdrawal::getOne($params);
if (empty($doctor_withdrawal)){
throw new BusinessException("加入推送队列失败:提现数据为空");
}
if ($this->push_type == 1) {
// 站内
// 计算时间
$created_at = date('Y',strtotime($doctor_withdrawal['created_at']));
$now_year = date('Y',time());
if ($created_at != $now_year){
$created_at = date('Y',strtotime($doctor_withdrawal['created_at'])) . '年' . date('m',strtotime($doctor_withdrawal['created_at'])) . "";
}else{
$created_at = date('m',strtotime($doctor_withdrawal['created_at'])) . '月' . date('m',strtotime($doctor_withdrawal['created_at'])) . "";
}
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 2;
$data['from_name'] = "肝胆小秘书";
$data['notice_brief_title'] = "XX月XX日提取的服务费已结算本年显示XX月XX日去年显示XX年XX月;";
$data['notice_title'] = "XX月XX日提取的服务费已结算本年显示XX月XX日去年显示XX年XX月";
$data['notice_content'] = "XX医生您好您XX月XX日提取的服务费已结算至您的银行卡请注意查收。本年显示XX月XX日去年显示XX年XX月";
$data['notice_brief_title'] = "{$created_at}提取的服务费已结算;";
$data['notice_title'] = "{$created_at}提取的服务费已结算";
$data['notice_content'] = "{$this->user['user_name']}医生您好,您{$created_at}提取的服务费已结算至您的银行卡,请注意查收。";
$data['link_type'] = 8;// 药品订单详情页
$data['link_type'] = 6;// 我的账户
$data['button_type'] = 1;// 我的账户
$link_params = array();
$link_params['order_product_id'] = $order_product_id;
$data['link_params'] = json_encode($link_params,JSON_UNESCAPED_UNICODE);// 跳转参数
$message = new SendStationMessageProducer($data);
@ -1786,17 +1802,16 @@ class MessagePush extends BaseService
// 短信
// 获取系统接诊配置
$data = array();
$data['template_code'] = "SMS_271955204";
$data['scene_desc'] = "患者药品费用退款";
$data['template_code'] = "SMS_271915200";
$data['scene_desc'] = "医师服务费结算成功";
$data['phone'] = $this->user['mobile'];
$data['user_id'] = $this->user['user_id'];
$template_param = array();
$template_param['name'] = $product_name;
$template_param['status'] = productCancelReasonToString($order_product['cancel_reason']);
$template_param['name'] = $this->user['user_name'];
$template_param['time'] = date('Y-m-d H:i',strtotime($doctor_withdrawal['created_at']));
$data['template_param'] = $template_param;
$message = new SendSmsMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
@ -1810,4 +1825,160 @@ class MessagePush extends BaseService
return true;
}
/**
* 医师服务费结算失败
* 站内、短信
* @param string $withdrawal_id
* @return bool
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function doctorSettlementFail(string $withdrawal_id): bool
{
try {
// 获取医生提现表数据
$params = array();
$params['withdrawal_id'] = $withdrawal_id;
$doctor_withdrawal = DoctorWithdrawal::getOne($params);
if (empty($doctor_withdrawal)){
throw new BusinessException("加入推送队列失败:提现数据为空");
}
if ($this->push_type == 1) {
// 站内
// 计算时间
$created_at = date('Y',strtotime($doctor_withdrawal['created_at']));
$now_year = date('Y',time());
if ($created_at != $now_year){
$created_at = date('Y',strtotime($doctor_withdrawal['created_at'])) . '年' . date('m',strtotime($doctor_withdrawal['created_at'])) . "";
}else{
$created_at = date('m',strtotime($doctor_withdrawal['created_at'])) . '月' . date('m',strtotime($doctor_withdrawal['created_at'])) . "";
}
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 2;
$data['from_name'] = "肝胆小秘书";
$data['notice_brief_title'] = "{$created_at}提取的服务费结算失败";
$data['notice_title'] = "{$created_at}服务费结算失败";
$data['notice_content'] = "{$this->user['user_name']}医生您好,您{$created_at}提取的服务费结算失败,肝胆小秘书会尽快和您取得联系,您也可以选择联系客服主动联系。";
$data['link_type'] = 11;// 联系客服
$data['button_type'] = 2;// 联系客服
$link_params = array();
$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) {
throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
}
} elseif ($this->push_type == 3) {
// 短信
// 获取系统接诊配置
$data = array();
$data['template_code'] = "SMS_271915200";
$data['scene_desc'] = "医师服务费结算失败";
$data['phone'] = $this->user['mobile'];
$data['user_id'] = $this->user['user_id'];
$template_param = array();
$template_param['name'] = $this->user['user_name'];
$template_param['time'] = date('Y-m-d H:i',strtotime($doctor_withdrawal['created_at']));
$data['template_param'] = $template_param;
$message = new SendSmsMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
}
}
} catch (\Exception $e) {
throw new BusinessException("加入推送队列失败" . $e->getMessage());
}
return true;
}
/**
* 小程序升级通知
* 站内
* @param string $date 日期
* @param string $function 功能
* @return bool
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function DoctorSystemUpgrade(string $date,string $function): bool
{
try {
if ($this->push_type == 1) {
// 站内
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 2;
$data['from_name'] = "肝胆小秘书";
$data['notice_brief_title'] = $date . "会更新新的功能,敬请期待";
$data['notice_title'] = "系统升级";
$data['notice_content'] = "{$this->user['user_name']}医生,{$date}会更新{$function}功能,敬请期待;";
$link_params = array();
$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) {
throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
}
}
} catch (\Exception $e) {
throw new BusinessException("加入推送队列失败" . $e->getMessage());
}
return true;
}
/**
* 小程序升级通知
* 站内
* @param string $title 协议名称
* @return bool
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function DoctorAgreementUpdate(string $title): bool
{
try {
if ($this->push_type == 1) {
// 站内
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 2;
$data['from_name'] = "肝胆小秘书";
$data['notice_brief_title'] = "平台对【{$title}】协议进行了更新,请注意查收";
$data['notice_title'] = "协议更新";
$data['notice_content'] = "{$this->user['user_name']}医生,平台对【{$title}】协议进行了更新,请注意查收";
$link_params = array();
$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) {
throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
}
}
} catch (\Exception $e) {
throw new BusinessException("加入推送队列失败" . $e->getMessage());
}
return true;
}
}