新增问诊消息推送
This commit is contained in:
@@ -276,43 +276,4 @@ class ImService extends BaseService
|
||||
|
||||
$message->sendMessage($arg);
|
||||
}
|
||||
|
||||
// 发送自定义消息
|
||||
public function sendCustomMessage(string $from_user_id,string $to_user_id,string $content,string $order_inquiry_id,int $inquiry_type, array $cloud_custom_data): void
|
||||
{
|
||||
if (!empty($from_user_id)){
|
||||
// 检测并创建发送者资料
|
||||
$this->setUserProfile($from_user_id);
|
||||
}
|
||||
|
||||
// 检测并创建接收者资料
|
||||
$this->setUserProfile($to_user_id);
|
||||
|
||||
$message = new Message();
|
||||
|
||||
$arg = array();
|
||||
if (!empty($from_user_id)){
|
||||
$arg['From_Account'] = $from_user_id; // 发送方user_id 如系统发送,无需填写
|
||||
}
|
||||
$arg['To_Account'] = $to_user_id; // 接收方user_id
|
||||
$arg['ForbidCallbackControl'] = ['ForbidBeforeSendMsgCallback','ForbidAfterSendMsgCallback'];
|
||||
$arg['SendMsgControl'] = ['NoUnread'];
|
||||
|
||||
$arg['MsgBody'] = [
|
||||
[
|
||||
"MsgType" => "TIMCustomElem",
|
||||
"MsgContent" => [
|
||||
"Data" => $content,
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
// 自定义消息
|
||||
$arg['CloudCustomData'] = "";
|
||||
if (!empty($cloud_custom_data)){
|
||||
$arg['CloudCustomData'] = json_encode($cloud_custom_data,JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
$message->sendMessage($arg);
|
||||
}
|
||||
}
|
||||
@@ -278,7 +278,7 @@ class InquiryService extends BaseService
|
||||
$data = array();
|
||||
$data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
$message = new CancelUnInquiryOrdersDelayDirectProducer($data);
|
||||
$message->setDelayMs(1000 * 60 * 5);
|
||||
$message->setDelayMs(1000 * 60 * 60 * 24);
|
||||
$producer = $this->container->get(Producer::class);
|
||||
$res = $producer->produce($message);
|
||||
if (!$res) {
|
||||
@@ -604,11 +604,19 @@ class InquiryService extends BaseService
|
||||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)) {
|
||||
return fail();
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"订单错误");
|
||||
}
|
||||
|
||||
if ($order_inquiry['doctor_id'] != $user_info['client_user_id'] && $order_inquiry['patient_id'] != $user_info['client_user_id']){
|
||||
return fail();
|
||||
if ($user_info['user_type'] == 1){
|
||||
if ($order_inquiry['patient_id'] != $user_info['client_user_id']){
|
||||
return fail(HttpEnumCode::SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
if ($user_info['user_type'] == 2){
|
||||
if ($order_inquiry['doctor_id'] != $user_info['client_user_id']){
|
||||
return fail(HttpEnumCode::SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
$params = array();
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Amqp\Producer\SendStationMessageProducer;
|
||||
use App\Amqp\Producer\SendSubMessageProducer;
|
||||
use App\Constants\HttpEnumCode;
|
||||
use App\Exception\BusinessException;
|
||||
use App\Model\OrderInquiry;
|
||||
use App\Model\User;
|
||||
use App\Model\UserDoctor;
|
||||
use Hyperf\Amqp\Producer;
|
||||
use Hyperf\Utils\ApplicationContext;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
/**
|
||||
* 消息推送业务类
|
||||
*/
|
||||
class MessagePush extends BaseService
|
||||
{
|
||||
// 推送类型 1:站内 2:订阅 3:短信
|
||||
public int $push_type;
|
||||
|
||||
// 用户数据(存在被推送者时存在,否则为空)
|
||||
public array $user = [];
|
||||
|
||||
// 问诊订单数据(可为空)
|
||||
public array $order_inquiry = [];
|
||||
|
||||
/**
|
||||
* @param int $push_type 推送类型 1:站内 2:订阅 3:短信
|
||||
* @param string $user_id 用户id(存在被推送者时存在,否则为空)
|
||||
* @param string $order_inquiry_id 问诊订单id
|
||||
*/
|
||||
public function __construct(int $push_type, string $user_id = "", string $order_inquiry_id = "")
|
||||
{
|
||||
if (!in_array($push_type, [1, 2, 3])) {
|
||||
throw new BusinessException("推送类型错误:" . $push_type);
|
||||
}
|
||||
$this->push_type = $push_type;
|
||||
|
||||
if (!empty($user_id)) {
|
||||
$params = array();
|
||||
$params['user_id'] = $user_id;
|
||||
$user = User::getOne($params);
|
||||
if (!empty($user)) {
|
||||
$this->user = $user->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($order_inquiry_id)) {
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (!empty($order_inquiry)) {
|
||||
$this->order_inquiry = $order_inquiry->toArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 快速/购药的服务5分钟未接诊
|
||||
* 公益/专家24小时未接诊
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function noInquiry(): bool
|
||||
{
|
||||
try {
|
||||
if ($this->push_type == 1) {
|
||||
// 站内
|
||||
// 服务消息
|
||||
$data = array();
|
||||
$data['user_id'] = $this->user['user_id'];
|
||||
$data['notice_type'] = 3;
|
||||
$data['notice_system_type'] = 1;
|
||||
$data['from_name'] = "肝胆小秘书";
|
||||
if ($this->order_inquiry['inquiry_type'] == 1 || $this->order_inquiry['inquiry_type'] == 3) {
|
||||
// 专家-公益
|
||||
$inquiry_type_string = inquiryTypeToString($this->order_inquiry['inquiry_type']);
|
||||
$data['notice_title'] = "【{$inquiry_type_string}】医生未接诊:您咨询的医生因工作繁忙没有时间接诊,点击查看详情。";
|
||||
$data['notice_content'] = "【{$inquiry_type_string}】未接诊:您咨询的服务当前排队人较多,暂无空闲医生接诊。给您带来不便敬请谅解,平台会在24小时内进行退款,您可以点击订单详情查看退款详情。";
|
||||
|
||||
} elseif ($this->order_inquiry['inquiry_type'] == 1 || $this->order_inquiry['inquiry_type'] == 4) {
|
||||
// 快速-购药
|
||||
$inquiry_type_string = inquiryTypeToString($this->order_inquiry['inquiry_type']);
|
||||
$data['notice_title'] = "【{$inquiry_type_string}】未接诊:您咨询的服务暂无医生接诊,点击查看详情。";
|
||||
$data['notice_content'] = "【{$inquiry_type_string}】医生未接诊:您咨询的医生因工作繁忙,暂无空闲时间接诊。给您带来不便敬请谅解,平台会在24小时内进行退款,您可以点击订单详情查看退款详情。";
|
||||
}
|
||||
|
||||
$data['link_type'] = 10;// 问诊订单详情
|
||||
|
||||
$link_params = array();
|
||||
$link_params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
|
||||
$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 == 2) {
|
||||
// 订阅
|
||||
// 获取医生数据
|
||||
$params = array();
|
||||
$params['doctor_id'] = $this->order_inquiry['doctor_id'];
|
||||
$user_doctor = UserDoctor::getOne($params);
|
||||
if (empty($user_doctor)){
|
||||
throw new BusinessException("加入推送队列失败:医生数据为空");
|
||||
}
|
||||
|
||||
$sub_data = array();
|
||||
$sub_data['push_user_id'] = $this->user['user_id'];
|
||||
$sub_data['template_title'] = "问诊异常通知";
|
||||
$sub_data['params']['page'] = "pages/orderDetail/orderDetail";
|
||||
$sub_data['params']['data'] = [
|
||||
"character_string1" => $this->order_inquiry['inquiry_no'],// 订单ID
|
||||
"name2" => (string)$user_doctor['user_name'],// 问诊医生
|
||||
"date3" => $this->order_inquiry['created_at'],// 问诊时间
|
||||
"thing4" => cancelReasonToString($this->order_inquiry['cancel_reason']),// 取消原因
|
||||
"thing5" => "点击详情更换医生问诊",// 提示说明
|
||||
];
|
||||
|
||||
|
||||
$data = array();
|
||||
$data['sub_data'] = $sub_data;
|
||||
$data['sms_data'] = array();
|
||||
|
||||
$message = new SendSubMessageProducer($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) {
|
||||
// 短信 无需接入
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw new BusinessException("加入推送队列失败" . $e->getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 患者回复通知
|
||||
* @param string $content 回复内容
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function patientReplyNotice(string $content): bool
|
||||
{
|
||||
try {
|
||||
// 只有订阅消息
|
||||
if ($this->push_type == 2){
|
||||
$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->user['user_id']}&order_inquiry_id={$this->order_inquiry['order_inquiry_id']}&inquiry_type={$this->order_inquiry['inquiry_type']}";
|
||||
$sub_data['params']['data'] = [
|
||||
"thing1" => $this->user['user_name'],// 患者姓名
|
||||
"thing2" => $content,// 回复内容
|
||||
];
|
||||
|
||||
$data = array();
|
||||
$data['sub_data'] = $sub_data;
|
||||
$data['sms_data'] = array();
|
||||
$message = new SendSubMessageProducer($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;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace App\Services;
|
||||
|
||||
use App\Amqp\Producer\AssignDoctorProducer;
|
||||
use App\Amqp\Producer\CancelUnPayInquiryOrderDelayProducer;
|
||||
use App\Amqp\Producer\CancelUnpayOrdersDelayDirectProducer;
|
||||
use App\Constants\DoctorTitleCode;
|
||||
use App\Constants\HttpEnumCode;
|
||||
@@ -810,6 +809,9 @@ class PatientOrderService extends BaseService
|
||||
$cloud_custom_data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
$cloud_custom_data['is_system'] = 1;
|
||||
$cloud_custom_data['inquiry_type'] = $order_inquiry['inquiry_type'];
|
||||
$cloud_custom_data['patient_family_data']['patient_name'] = $order_inquiry['patient_name'];
|
||||
$cloud_custom_data['patient_family_data']['patient_sex'] = $order_inquiry['patient_sex'];
|
||||
$cloud_custom_data['patient_family_data']['patient_age'] = $order_inquiry['patient_age'];
|
||||
|
||||
// 消息内容
|
||||
$message_content_data = array();
|
||||
|
||||
Reference in New Issue
Block a user