3709 lines
168 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Services;
use App\Amqp\Producer\SendSmsMessageProducer;
use App\Amqp\Producer\SendStationMessageProducer;
use App\Amqp\Producer\SendSubMessageProducer;
use App\Constants\HttpEnumCode;
use App\Exception\BusinessException;
use App\Model\BasicDetectionOrgan;
use App\Model\DetectionProject;
use App\Model\DoctorWithdrawal;
use App\Model\Order;
use App\Model\OrderDetection;
use App\Model\OrderInquiry;
use App\Model\OrderInquiryCase;
use App\Model\OrderInquiryCoupon;
use App\Model\OrderPrescription;
use App\Model\OrderProduct;
use App\Model\OrderProductItem;
use App\Model\OrderServicePackage;
use App\Model\OrderServicePackageCase;
use App\Model\OrderServicePackageDetail;
use App\Model\OrderServicePackageInquiry;
use App\Model\OrderServicePackageProduct;
use App\Model\Product;
use App\Model\SystemInquiryConfig;
use App\Model\User;
use App\Model\UserDoctor;
use App\Utils\Log;
use Hyperf\Amqp\Producer;
//use Hyperf\Utils\ApplicationContext;
use Hyperf\Context\ApplicationContext;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/**
* 消息推送业务类
*/
class MessagePush extends BaseService
{
// 被推送者用户数据(存在被推送者时存在,否则为空)
public ?array $user = null;
// 订单数据
public ?array $order = null;
// 服务包订单数据
public ?array $order_service_package = null;
// 问诊订单数据
public ?array $order_inquiry = null;
// 药品订单数据
public ?array $order_product = null;
// 检测订单数据
public ?array $order_detection = null;
/**
* @param string $to_user_id 用户id存在被推送者时存在,否则为空)
* @param string $order_no 问诊订单编号
*/
public function __construct(string $to_user_id = "", string $order_no = "")
{
if (!empty($to_user_id)){
$params = array();
$params['user_id'] = $to_user_id;
$user = User::getOne($params);
if (!empty($user)) {
$this->user = $user->toArray();
}
}
// 获取订单数据
if (!empty($order_no)){
$params = array();
$params['order_no'] = $order_no;
$order = Order::getOne($params);
if (!empty($order)){
$this->order = $order->toArray();
// 判断订单类型
switch ($order['order_type']) {
case 1: // 问诊订单
$params = array();
$params['inquiry_no'] = $order['order_no'];
$order_inquiry = OrderInquiry::getOne($params);
if (!empty($order_inquiry)) {
$this->order_inquiry = $order_inquiry->toArray();
}
break;
case 2: // 药品订单
$params = array();
$params['order_product_no'] = $order['order_no'];
$order_product = OrderProduct::getOne($params);
if (!empty($order_product)) {
$this->order_product = $order_product->toArray();
}
break;
case 3: // 检测订单
$params = array();
$params['detection_no'] = $order['order_no'];
$order_detection = OrderDetection::getOne($params);
if (!empty($order_detection)) {
$this->order_detection = $order_detection->toArray();
}
break;
case 4: // 健康包订单
case 5: // 随访包订单
$params = array();
$params['inquiry_no'] = $order_no;
$order_inquiry = OrderInquiry::getOne($params);
if (!empty($order_inquiry)) {
$this->order_inquiry = $order_inquiry->toArray();
$params = array();
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
$order_service_package_inquiry = OrderServicePackageInquiry::getOne($params);
if (!empty($order_service_package_inquiry)){
$params = array();
$params['order_service_no'] = $order_service_package_inquiry['order_service_no'];
$order_service_package = OrderServicePackage::getOne($params);
if (!empty($order_service_package)){
$this->order_service_package = $order_service_package->toArray();
}
}
}
break;
default:
throw new BusinessException("订单类型错误");
}
}
}
}
/**
* 患者-医生未接诊
* 快速/购药的服务5分钟未接诊
* 公益/专家24小时未接诊
* 站内、订阅
* @return void
*/
public function patientNoInquiry(): void
{
try {
// 站内
// 服务消息
$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) {
// 专家-公益
$data['notice_brief_title'] = "您咨询的医生因工作繁忙没有时间接诊,点击查看详情。";
$data['notice_title'] = "您咨询的医生因工作繁忙没有时间接诊,点击查看详情。";
$data['notice_content'] = "您咨询的医生因工作繁忙暂无空闲时间接诊。给您带来不便敬请谅解平台会在24小时内进行退款您可以点击订单详情查看退款详情。";
} elseif ($this->order_inquiry['inquiry_type'] == 2 || $this->order_inquiry['inquiry_type'] == 4) {
// 快速-购药
$data['notice_brief_title'] = "您的咨询暂无医生接诊,点击查看详情。";
$data['notice_title'] = "您的咨询暂无医生接诊,点击查看详情。";
$data['notice_content'] = "当前咨询排队人员较多暂无空闲医生接诊。给您带来不便敬请谅解平台会在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);// 跳转参数
$data['button_type'] = 4; // 订单详情
$message = new SendStationMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error(json_encode($data, JSON_UNESCAPED_UNICODE));
}
// 订阅
// 获取医生数据
$params = array();
$params['doctor_id'] = $this->order_inquiry['doctor_id'];
$user_doctor = UserDoctor::getOne($params);
if (empty($user_doctor)) {
Log::getInstance("MessagePush")->error("错误:医生数据为空");
return;
}
$sub_data = array();
$sub_data['push_user_id'] = $this->user['user_id'];
$sub_data['wx_template_id'] = "UOMww1S30Oq7rErJrqO8wN6lNEVKRo2fgcXnb0tBwHI";//问诊异常通知
$sub_data['params']['page'] = "patient/pages/orderDetail/orderDetail?order_inquiry_id={$this->order_inquiry['order_inquiry_id']}";
$sub_data['params']['data'] = [
"character_string1" => (string)$this->order_inquiry['inquiry_no'],// 订单ID
"name2" => (string)$user_doctor['user_name'],// 问诊医生
"date3" => $this->order_inquiry['created_at'],// 问诊时间
"thing4" => inquiryCancelReasonToPushString($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) {
Log::getInstance("MessagePush")->error("错误:" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error("错误:" . $e->getMessage());
}
}
/**
* 患者-分配医生失败
* 订阅
* @return void
*/
public function assignDoctorFail(): void
{
try {
// 订阅
// 获取医生数据
if (!empty($this->order_inquiry['doctor_id'])) {
$params = array();
$params['doctor_id'] = $this->order_inquiry['doctor_id'];
$user_doctor = UserDoctor::getOne($params);
}
$sub_data = array();
$sub_data['push_user_id'] = $this->user['user_id'];
$sub_data['wx_template_id'] = "UOMww1S30Oq7rErJrqO8wN6lNEVKRo2fgcXnb0tBwHI";//问诊异常通知
$sub_data['params']['page'] = "patient/pages/orderDetail/orderDetail?order_inquiry_id={$this->order_inquiry['order_inquiry_id']}";
$sub_data['params']['data'] = [
"character_string1" => (string)$this->order_inquiry['inquiry_no'],// 订单ID
"name2" => $user_doctor['user_name'] ?? "接诊医生",// 问诊医生
"date3" => $this->order_inquiry['created_at'],// 问诊时间
"thing4" => inquiryCancelReasonToPushString($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) {
Log::getInstance("MessagePush")->error("错误:" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error("错误:" . $e->getMessage());
}
}
/**
* 医生-通知患者回复
* 订阅
* @param string $content 回复内容
* @return bool
*/
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['wx_template_id'] = "jhYUf91ULCTX_f69hazqAYwImdFf8ELasRAwB6X-MTM"; // 患者回复通知
$sub_data['params']['page'] = "Pages/yishi/wenzhen_v2/wenzhen";
$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 (\Throwable $e) {
throw new BusinessException("加入推送队列失败" . $e->getMessage());
}
return true;
}
/**
* 患者-通知患者医生已接诊
* 站内、订阅、短信
* @return void
*/
public function patientAcceptedInquiry(): void
{
try {
// 获取医生数据
$params = array();
$params['doctor_id'] = $this->order_inquiry['doctor_id'];
$user_doctor = UserDoctor::getOne($params);
if (empty($user_doctor)) {
Log::getInstance("MessagePush")->error("错误:医生数据为空");
return;
}
// 获取问诊订单关联病例
$params = array();
$params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$order_inquiry_case = OrderInquiryCase::getOne($params);
if (empty($order_inquiry_case)) {
Log::getInstance("MessagePush")->error("错误:病例数据为空");
return;
}
// 获取系统接诊配置
$params = array();
$params['inquiry_type'] = $this->order_inquiry['inquiry_type'];
$params['inquiry_mode'] = $this->order_inquiry['inquiry_mode'];
$system_inquiry_config = SystemInquiryConfig::getOne($params);
if (empty($system_inquiry_config)) {
Log::getInstance("MessagePush")->error("错误:获取系统接诊配置失败");
return;
}
// 站内
$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'] = "{$user_doctor['user_name']}医生已接诊,请尽快和医生进行沟通交流病情,点击查看详情。";
$data['notice_title'] = "{$user_doctor['user_name']}医生已接诊,请尽快和医生进行沟通交流病情,点击查看详情。";
$data['notice_content'] = "{$user_doctor['user_name']}医生已接诊,请您尽快和医生进行沟通交流病情,您可以点击问诊详情进行交流。";
$data['link_type'] = 1;// 聊天详情页
$link_params = array();
$link_params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$link_params['inquiry_type'] = $this->order_inquiry['inquiry_type'];
$link_params['doctor_user_id'] = $user_doctor['user_id'];
$link_params['patient_user_id'] = $this->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("MessagePush")->error("错误:加入推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
// 问诊内容-病情主诉
$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={$this->order_inquiry['order_inquiry_id']}";
$sub_data['params']['data'] = [
"thing1" => (string)$disease_desc,// 问诊内容-病情主诉
"thing2" => "医生已接诊,请您尽快和医生沟通交流病情",// 提醒内容
"name3" => (string)$user_doctor['user_name'],// 问诊医生
"thing4" => "点击查看问诊订单详情",// 提示说明
];
$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) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
// 短信
$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($this->order_inquiry['inquiry_type']);
$template_param['name'] = $user_doctor['user_name'];
$template_param['duration'] = $duration; // 服务时长
$data['template_param'] = $template_param;
$message = new SendSmsMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . $e->getMessage());
}
}
/**
* 患者的问诊服务结束
* 站内、订阅
* @return void
*/
public function patientInquiryFinish(): void
{
try {
// 获取医生数据
$params = array();
$params['doctor_id'] = $this->order_inquiry['doctor_id'];
$user_doctor = UserDoctor::getOne($params);
if (empty($user_doctor)) {
Log::getInstance("MessagePush")->error("错误:医生数据为空");
return;
}
// 获取问诊订单关联病例
$params = array();
$params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$order_inquiry_case = OrderInquiryCase::getOne($params);
if (empty($order_inquiry_case)) {
Log::getInstance("MessagePush")->error("错误:病例数据为空");
return;
}
$producer = ApplicationContext::getContainer()->get(Producer::class);
// 站内
// 服务消息
$inquiry_type_string = inquiryTypeToString($this->order_inquiry['inquiry_type']);
$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'] = "您的【{$inquiry_type_string}】服务已结束,点击查看详情。";
$data['notice_title'] = "您的【{$inquiry_type_string}】服务已结束,点击查看详情。";
$data['notice_content'] = "您咨询{$user_doctor['user_name']}医生的服务已结束,请对本次问诊服务做出评价。您的评价对医生和其他患者也有很重要的参考价值。您也可以点击医生头像,进入医生主页关注医生。";
$data['link_type'] = 10;// 问诊订单详情
$link_params = array();
$link_params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$link_params['inquiry_type'] = $this->order_inquiry['inquiry_type'];
$link_params['doctor_user_id'] = $user_doctor['user_id'];
$link_params['patient_user_id'] = $this->order_inquiry['user_id'];
$data['link_params'] = json_encode($link_params, JSON_UNESCAPED_UNICODE);// 跳转参数
$data['button_type'] = 4; // 订单详情
$message = new SendStationMessageProducer($data);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
// 问诊内容
if (empty($order_inquiry_case['disease_desc'])){
$disease_desc = $inquiry_type_string;
}else{
$disease_desc = $order_inquiry_case['disease_desc'];
if (mb_strlen($disease_desc) > 15) {
$disease_desc = mb_substr($disease_desc, 0, 15, 'UTF-8') . '...';
}
}
// 订阅
$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={$this->order_inquiry['order_inquiry_id']}";
$sub_data['params']['data'] = [
"thing1" => (string)$disease_desc,// 问诊内容
"thing2" => "您的问诊服务已结束,请对本次服务做出评价",// 提醒内容
"name3" => (string)$user_doctor['user_name'],// 问诊医生
"thing4" => "点击查看问诊订单详情",// 提示说明
];
$data = array();
$data['sub_data'] = $sub_data;
$data['sms_data'] = array();
$message = new SendSubMessageProducer($data);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . $e->getMessage());
}
}
/**
* 患者-处方被药师审核通过
* 站内、短信
* @return void
*/
public function patientPrescriptionVerifyPass(): void
{
try {
// 获取医生数据
$params = array();
$params['doctor_id'] = $this->order_inquiry['doctor_id'];
$user_doctor = UserDoctor::getOne($params);
if (empty($user_doctor)) {
Log::getInstance("MessagePush")->error("错误:医生数据为空");
return;
}
// 站内
// 服务消息
// 获取问诊订单处方数据
$params = array();
$params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$params['doctor_id'] = $this->order_inquiry['doctor_id'];
$params['pharmacist_audit_status'] = 1;
$order_prescription = OrderPrescription::getOne($params);
if (empty($order_prescription)) {
Log::getInstance("MessagePush")->error("错误:处方数据为空");
return;
}
$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'] = "{$user_doctor['user_name']}医生为您开具的电子处方已审核通过,点击查看详情。";
$data['notice_title'] = "{$user_doctor['user_name']}医生为您开具的电子处方已审核通过,点击查看详情。";
$data['notice_content'] = "{$user_doctor['user_name']}医生为您开具的电子处方已审核通过,您可以点击查看处方进行购买药品。";
$data['link_type'] = 13;
$link_params = array();
$link_params['order_prescription_id'] = $order_prescription['order_prescription_id'];
$data['link_params'] = json_encode($link_params, JSON_UNESCAPED_UNICODE);// 跳转参数
$data['button_type'] = 5; // 查看处方
$message = new SendStationMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
// 短信
$data = array();
$data['template_code'] = "SMS_271540920";
$data['scene_desc'] = "处方审核通过";
$data['phone'] = $this->user['mobile'];
$data['user_id'] = $this->user['user_id'];
$template_param = array();
$template_param['name'] = $user_doctor['user_name'];
$data['template_param'] = $template_param;
$message = new SendSmsMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . $e->getMessage());
}
}
/**
* 患者-处方审核未通过
* 站内
* @return void
*/
public function patientPrescriptionVerifyFail(): void
{
try {
// 获取医生数据
$params = array();
$params['doctor_id'] = $this->order_inquiry['doctor_id'];
$user_doctor = UserDoctor::getOne($params);
if (empty($user_doctor)) {
Log::getInstance("MessagePush")->error("错误:医生数据为空");
return;
}
// 站内
// 服务消息
$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'] = "{$user_doctor['user_name']}医生为您开具的电子处方未通过审核,点击查看详情。";
$data['notice_title'] = "{$user_doctor['user_name']}医生为您开具的电子处方未通过审核,点击查看详情。";
$data['notice_content'] = "{$user_doctor['user_name']}医生为您开具的电子处方未通过审核,您可以稍后重新发起问诊申请开具处方。";
$message = new SendStationMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . $e->getMessage());
}
}
/**
* 患者-优惠劵发放
* 站内
* @param string $coupon_name
* @return void
*/
public function patientDistributeCoupon(string $coupon_name): void
{
try {
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 3;
$data['notice_system_type'] = 2; // 系统消息类型(患者端系统消息存在 1:服务消息 2:福利消息 3:退款消息 4:物流消息)
$data['from_name'] = "肝胆小秘书";
$data['notice_brief_title'] = "有新的优惠券已下发至您的账户,点击查看详情。";
$data['notice_title'] = "{$coupon_name}】已到账";
$data['notice_content'] = "有新的优惠劵已下发至您的账户中,点击查看详情!";
$data['link_type'] = 7;
$message = new SendStationMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . $e->getMessage());
}
}
/**
* 患者-优惠劵退还
* 站内
* @param string $coupon_name
* @return void
*/
public function patientRefundCoupon(string $coupon_name): void
{
try {
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 3;
$data['notice_system_type'] = 2; // 系统消息类型(患者端系统消息存在 1:服务消息 2:福利消息 3:退款消息 4:物流消息)
$data['from_name'] = "肝胆小秘书";
$data['notice_brief_title'] = "优惠劵已退还至您的账户,点击查看详情。";
$data['notice_title'] = "{$coupon_name}】已退还";
$data['notice_content'] = "您有优惠劵已退还至您的账户,请点击查看详情!";
$data['link_type'] = 7;
$message = new SendStationMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . $e->getMessage());
}
}
/**
* 患者-优惠劵即将过期
* 站内
* @param string $coupon_name
* @return void
*/
public function patientExpireCoupon(string $coupon_name): void
{
try {
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 3;
$data['notice_system_type'] = 2; // 系统消息类型(患者端系统消息存在 1:服务消息 2:福利消息 3:退款消息 4:物流消息)
$data['from_name'] = "肝胆小秘书";
$data['notice_brief_title'] = "您有一张优惠劵即将过期,点击查看详情。";
$data['notice_title'] = "{$coupon_name}】即将过期";
$data['notice_content'] = "您有一张优惠劵即将过期,点击查看详情!";
$data['link_type'] = 7;
$message = new SendStationMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . $e->getMessage());
}
}
/**
* 患者-问诊服务退款成功
* 站内、订阅、短信
* @param int $cancel_reason 取消订单原因1:医生未接诊 2:主动取消 3:无可分配医生 4:客服取消 5:支付超时)
* @return void
*/
public function refundInquirySuccess(int $cancel_reason): void
{
try {
if (!empty($this->order_inquiry['doctor_id'])) {
// 获取医生数据
$params = array();
$params['doctor_id'] = $this->order_inquiry['doctor_id'];
$user_doctor = UserDoctor::getOne($params);
if (empty($user_doctor)) {
Log::getInstance("MessagePush")->error("错误:医生数据为空");
return;
}
}
// 站内
$inquiry_type_string = inquiryTypeToString($this->order_inquiry['inquiry_type']);
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 3;
$data['notice_system_type'] = 3;
$data['from_name'] = "肝胆小秘书";
$data['notice_brief_title'] = "您的【{$inquiry_type_string}】服务,平台已退款成功,点击查看详情";
if ($cancel_reason == 1) {
// 已支付未接诊
if ($this->order_inquiry['inquiry_type'] == 1 || $this->order_inquiry['inquiry_type'] == 3) {
$data['notice_title'] = "您的【{$inquiry_type_string}】服务,平台已退款成功";
$data['notice_content'] = "因医生繁忙未及时接诊平台会在24小时内退款至原账户给您带来的不便敬请谅解。";
} else {
$data['notice_title'] = "您咨询的【{$inquiry_type_string}】服务,平台已退款成功";
$data['notice_content'] = "因当前候诊人较多您的咨询暂无医生接诊。平台会在24小时内退款至原账户给您带来的不便敬请谅解。";
}
} elseif ($cancel_reason == 2) {
// 已支付未成功分配医生
$data['notice_title'] = "您咨询的【{$inquiry_type_string}】服务,平台已退款成功";
$data['notice_content'] = "因当前候诊人较多您的咨询暂无医生接诊。平台会在24小时内退款至原账户给您带来的不便敬请谅解。";
} elseif ($cancel_reason == 3) {
// 已支付未接诊患者取消订单
$data['notice_title'] = "您的【{$inquiry_type_string}】服务已取消";
$data['notice_content'] = "您已成功取消当前服务平台会在24小时内退款至原账户感谢您的支持。";
} elseif ($cancel_reason == 4) {
// 已支付已接诊客服取消问诊订单
$data['notice_title'] = "您的【{$inquiry_type_string}】服务已取消";
$data['notice_content'] = "平台已为您安排退款会在24小时内退款至原账户请您注意查收感谢您的支持。";
} else {
Log::getInstance("MessagePush")->error("错误:类型错误");
return;
}
$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) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
// 短信
// 获取系统接诊配置
$data = array();
$data['template_code'] = "SMS_272180110";
$data['scene_desc'] = "患者问诊退款";
$data['phone'] = $this->user['mobile'];
$data['user_id'] = $this->user['user_id'];
$template_param = array();
$template_param['type'] = inquiryTypeToString($this->order_inquiry['inquiry_type']);
$data['template_param'] = $template_param;
$message = new SendSmsMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . $e->getMessage());
}
}
/**
* 患者-药品订单退款成功
* 站内、订阅、短信
* @param string $order_product_id
* @return void
*/
public function refundProductSuccess(string $order_product_id): void
{
try {
// 获取药品订单数据
$params = array();
$params['order_product_id'] = $order_product_id;
$order_product = OrderProduct::getOne($params);
if (empty($order_product)) {
Log::getInstance("MessagePush")->error("错误:药品订单数据为空");
return;
}
$order_product = $order_product->toArray();
// 获取药品订单商品数据
$params = array();
$params['order_product_id'] = $order_product_id;
$order_product_item = OrderProductItem::getList($params);
if (empty($order_product_item)) {
Log::getInstance("MessagePush")->error("错误:商品订单列表数据为空");
return;
}
// 获取商品数据
$product_name_array = array();
foreach ($order_product_item as $item) {
$params = array();
$params['product_id'] = $item['product_id'];
$product = Product::getOne($params);
if (empty($product)) {
Log::getInstance("MessagePush")->error("错误:商品数据为空");
return;
}
$product_name_array[] = $product['common_name'];
}
$product_name = "";
if (!empty($product_name_array)) {
if (count($product_name_array) > 1) {
$product_name = implode('、', $product_name_array);
} else {
$product_name = $product_name_array[0];
}
}
// 站内
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 3;
$data['notice_system_type'] = 3;
$data['from_name'] = "肝胆小秘书";
$data['notice_brief_title'] = "您购买的【{$product_name}】药品,平台已退款成功,点击查看详情";
$data['notice_title'] = "您购买的【{$product_name}】药品,平台已退款成功";
$data['notice_content'] = "受特别因素影响,您的药品无法正常配送。平台已退款至原账户,给您带来的不便敬请谅解。";
$data['link_type'] = 8;// 药品订单详情页
$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);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
// 订阅
$sub_data = array();
$sub_data['push_user_id'] = $this->user['user_id'];
$sub_data['wx_template_id'] = "gQO5vhPQfdnvXtK0XnGns1XqNhQpOrXTjdl-5HWWMUw";//药品订单取消通知
$sub_data['params']['page'] = "patient/pages/medinceOrderDetail/medinceOrderDetail?order_product_id={$order_product_id}";
$sub_data['params']['data'] = [
"character_string3" => (string)$order_product['order_product_no'],// 订单号
"time5" => $order_product['cancel_time'],// 取消时间
"amount4" => $order_product['payment_amount_total'],// 退款金额
"thing1" => "受特别因素影响,您的药品无法正常配送",// 取消原因
"thing6" => "点击详情查看",// 温馨提示
];
$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) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
// 短信
// 获取系统接诊配置
$data = array();
$data['template_code'] = "SMS_271955204";
$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']);
$data['template_param'] = $template_param;
$message = new SendSmsMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . $e->getMessage());
}
}
/**
* 患者-物流信息
* 已揽收、已发货、自动收货
* 站内
* @param string $status 已揽收、已发货、已签收
* @param string $order_product_id
* @return void
*/
public function logistics(string $status, string $order_product_id): void
{
try {
// 站内
// 服务消息
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 3;
$data['notice_system_type'] = 4;// 系统消息类型(患者端系统消息存在 1:服务消息 2:福利消息 3:退款消息 4:物流消息)
$data['from_name'] = "肝胆小秘书";
$data['notice_brief_title'] = "您购买的药品【{$status}】,点击查看物流详情。";
$data['notice_title'] = "您购买的药品【{$status}】,点击查看物流详情。";
$data['notice_content'] = "您购买的药品【{$status}】,点击查看物流详情。";
$data['link_type'] = 9;// 物流详情
$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);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . $e->getMessage());
}
}
/**
* 患者-药品已发货
* 订阅失败发送短信
* @param string $order_product_id
* @return void
*/
public function productDelivery(string $order_product_id): void
{
try {
// 获取药品订单数据
$params = array();
$params['order_product_id'] = $order_product_id;
$order_product = OrderProduct::getOne($params);
if (empty($order_product)) {
Log::getInstance("MessagePush")->error("错误:药品订单数据为空");
return;
}
$order_product = $order_product->toArray();
// 获取药品订单商品数据
$params = array();
$params['order_product_id'] = $order_product_id;
$order_product_item = OrderProductItem::getList($params);
if (empty($order_product_item)) {
Log::getInstance("MessagePush")->error("错误:商品订单列表数据为空");
return;
}
// 获取商品数据
$product_name_array = array();
foreach ($order_product_item as $item) {
$params = array();
$params['product_id'] = $item['product_id'];
$product = Product::getOne($params);
if (empty($product)) {
Log::getInstance("MessagePush")->error("错误:商品数据为空");
return;
}
$product_name_array[] = $product['common_name'];
}
$product_name = "";
if (!empty($product_name_array)) {
if (count($product_name_array) > 1) {
$product_name = implode('、', $product_name_array);
} else {
$product_name = $product_name_array[0];
}
}
// 订阅
$sub_data = array();
$sub_data['push_user_id'] = $this->user['user_id'];
$sub_data['wx_template_id'] = "YFdVxDclV1ZjhS7E4Cs0zFdshTRizERpwYdZizj_UWo"; // 药品发货通知
$sub_data['params']['page'] = "patient/pages/medinceOrderDetail/medinceOrderDetail?order_product_id={$order_product_id}";
$sub_data['params']['data'] = [
"character_string9" => (string)$order_product['order_product_no'],// 快递单号
"time7" => $order_product['delivery_time'],// 发货时间
"thing3" => $order_product['province'] . $order_product['city'] . $order_product['county'],// 收货地址
"thing6" => (string)$order_product['consignee_name'],// 收货人
"thing5" => "您的药品已发货,点击可以查看订单详情",// 备注
];
// 短信
$sms_data = array();
$sms_data['template_code'] = "SMS_271980127";
$sms_data['scene_desc'] = "药品发货通知";
$sms_data['phone'] = $this->user['mobile'];
$sms_data['user_id'] = $this->user['user_id'];
$template_param = array();
$template_param['name'] = $product_name;
$template_param['code'] = $order_product['logistics_no'] ?: "";
$sms_data['template_param'] = $template_param;
$data = array();
$data['sub_data'] = $sub_data;
$data['sms_data'] = $sms_data;
$message = new SendSubMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . $e->getMessage());
}
}
/**
* 药品收货-用药提醒-无法开发,
* 订阅失败发送短信
* @param string $order_product_id
* @return bool
*/
public function medicationReminder(string $order_product_id): bool
{
try {
} catch (\Throwable $e) {
throw new BusinessException("加入推送队列失败" . $e->getMessage());
}
return true;
}
/**
* 医生-医生有新问诊
* 站内、订阅失败发送短信
* @return void
*/
public function doctorHaveNewInquiry(): void
{
try {
// 获取医生数据
$params = array();
$params['doctor_id'] = $this->order_inquiry['doctor_id'];
$user_doctor = UserDoctor::getOne($params);
if (empty($user_doctor)) {
Log::getInstance("MessagePush")->error("错误:医生数据为空");
return;
}
// 获取问诊订单关联病例
$params = array();
$params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$order_inquiry_case = OrderInquiryCase::getOne($params);
if (empty($order_inquiry_case)) {
Log::getInstance("MessagePush")->error("错误:病例数据为空");
return;
}
// 站内
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 1;
$data['inquiry_type'] = $this->order_inquiry['inquiry_type']; // 问诊类型(医生端服务通知存在 1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药)
$data['from_name'] = "肝胆小秘书";
$data['notice_brief_title'] = "您有新的问诊咨询,请及时处理。";
$data['notice_title'] = "您有新的问诊咨询,请及时处理。";
$data['notice_content'] = "您有新的问诊咨询,请及时处理。";
$data['link_type'] = 3; // 问诊消息列表页
$link_params = array();
$link_params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$link_params['inquiry_type'] = $this->order_inquiry['inquiry_type'];
$link_params['doctor_user_id'] = $user_doctor['user_id'];
$link_params['patient_user_id'] = $this->order_inquiry['user_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) {
Log::getInstance("MessagePush")->error(json_encode($data, JSON_UNESCAPED_UNICODE));
}
// 订阅
// 问诊内容-病情主诉
$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 . "...";
}
}
}
if ($this->order_inquiry['inquiry_type'] == 1 || $this->order_inquiry['inquiry_type'] == 3) {
// 专家、公益
$thing6 = "24小时内未接诊平台将自动取消问诊";
} else {
// 快速、购药
$thing6 = "5分钟内未接诊平台将自动取消问诊";
}
$sub_data = array();
$sub_data['push_user_id'] = $this->user['user_id'];
$sub_data['wx_template_id'] = "G1RIs0RYqsTQ2CuPQWalIMyb6_deuEEbJfajfhGvNzc";//咨询提醒
$sub_data['params']['page'] = "Pages/yishi/wenzhen_v2/wenzhen";
$sub_data['params']['data'] = [
"thing1" => "您有一个新的问诊服务等待接诊",// 提醒内容
"name2" => (string)$this->order_inquiry['patient_name'],// 患者姓名
"thing4" => (string)$disease_desc,// 病情描述
"thing6" => $thing6,// 提示说明
"thing5" => "",// 咨询内容
];
// 短信
$sms_data = array();
$sms_data['template_code'] = "SMS_272015117";
$sms_data['scene_desc'] = "医生接到新问诊";
$sms_data['phone'] = $this->user['mobile'];
$sms_data['user_id'] = $this->user['user_id'];
$template_param = array();
$template_param['type'] = inquiryTypeToString($this->order_inquiry['inquiry_type']);
$sms_data['template_param'] = $template_param;
$data = array();
$data['sub_data'] = $sub_data;
$data['sms_data'] = $sms_data;
$message = new SendSubMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error("错误:加入订阅推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . $e->getMessage());
}
}
/**
* 医生xx时间后还未接诊
* 站内、订阅失败发送短信
* @return bool
*/
public function doctorNotYetInquiry(): bool
{
try {
// 获取问诊订单关联病例
$params = array();
$params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$order_inquiry_case = OrderInquiryCase::getOne($params);
if (empty($order_inquiry_case)) {
throw new BusinessException("加入推送队列失败:问诊病例为空");
}
// 站内
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 1;
$data['inquiry_type'] = $this->order_inquiry['inquiry_type']; // 问诊类型(医生端服务通知存在 1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药)
$data['from_name'] = "肝胆小秘书";
$data['notice_brief_title'] = "{$this->order_inquiry['patient_name']}患者的问诊您还未接诊,请及时处理。";
$data['notice_title'] = "{$this->order_inquiry['patient_name']}患者的问诊您还未接诊,请及时处理。";
$data['notice_content'] = "{$this->order_inquiry['patient_name']}患者的问诊您还未接诊,请及时处理。";
$data['link_type'] = 3; // 问诊消息列表页.
$link_params = array();
$link_params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$link_params['inquiry_type'] = $this->order_inquiry['inquiry_type'];
$link_params['doctor_user_id'] = $this->user['user_id'];
$link_params['patient_user_id'] = $this->order_inquiry['user_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) {
Log::getInstance("MessagePush")->error(json_encode($data, JSON_UNESCAPED_UNICODE));
}
$inquiry_type = inquiryTypeToString($this->order_inquiry['inquiry_type']);
// 订阅
$sub_data = array();
$sub_data['push_user_id'] = $this->user['user_id'];
$sub_data['wx_template_id'] = "G1RIs0RYqsTQ2CuPQWalIMyb6_deuEEbJfajfhGvNzc"; // 咨询提醒
$sub_data['params']['page'] = "Pages/yishi/wenzhen_v2/wenzhen";
$sub_data['params']['data'] = [
"thing1" => "您好医生,有新的问诊服务您还未接诊",// 提醒内容
"name2" => $this->order_inquiry['patient_name'],// 患者姓名
"thing4" => mb_substr($order_inquiry_case['disease_desc'], 0, 18),// 病情描述
"thing6" => "您还未接诊,请及时上线处理",// 提示说明
"thing5" => "",// 咨询内容
];
$sms_data = array();
$sms_data['template_code'] = "SMS_271905266";
$sms_data['scene_desc'] = "医生xx时间后还未接诊";
$sms_data['phone'] = $this->user['mobile'];
$sms_data['user_id'] = $this->user['user_id'];
$template_param = array();
$template_param['type'] = inquiryTypeToString($this->order_inquiry['inquiry_type']);
$template_param['name'] = $this->order_inquiry['patient_name'];
$sms_data['template_param'] = $template_param;
$data = array();
$data['sub_data'] = $sub_data;
$data['sms_data'] = $sms_data;
$message = new SendSubMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error(json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error($e->getMessage());
}
return true;
}
/**
* 医生-问诊结束
* 站内
* 发送给医生
* @return void
*/
public function finishInquiryToDoctor(): void
{
try {
// 获取问诊订单关联病例
$params = array();
$params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$order_inquiry_case = OrderInquiryCase::getOne($params);
if (empty($order_inquiry_case)) {
Log::getInstance("MessagePush")->error("错误:问诊病例为空");
return;
}
// 站内
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 1;
$data['inquiry_type'] = $this->order_inquiry['inquiry_type']; // 问诊类型(医生端服务通知存在 1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药)
$data['from_name'] = "肝胆小秘书";
$data['notice_brief_title'] = "{$this->order_inquiry['patient_name']}患者的问诊已结束,请注意查看。";
$data['notice_title'] = "{$this->order_inquiry['patient_name']}患者的问诊已结束,请注意查看。";
$data['notice_content'] = "{$this->order_inquiry['patient_name']}患者的问诊已结束,请注意查看。";
$data['link_type'] = 3; // 问诊消息列表页
$link_params = array();
$link_params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$link_params['inquiry_type'] = $this->order_inquiry['inquiry_type'];
$link_params['patient_user_id'] = $this->order_inquiry['user_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) {
Log::getInstance("MessagePush")->error("错误:加入站内推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . $e->getMessage());
}
}
/**
* 医生-开具的处方审核通过
* 站内、订阅失败发送短信
* @return void
*/
public function prescriptionVerifySuccess(): void
{
try {
// 获取问诊订单处方数据
$params = array();
$params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$params['doctor_id'] = $this->order_inquiry['doctor_id'];
$params['pharmacist_audit_status'] = 1;
$order_prescription = OrderPrescription::getOne($params);
if (empty($order_prescription)) {
Log::getInstance("MessagePush")->error("错误:处方数据为空");
return;
}
// 站内
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 1;
$data['inquiry_type'] = $this->order_inquiry['inquiry_type']; // 问诊类型(医生端服务通知存在 1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药)
$data['from_name'] = "肝胆小秘书";
$data['notice_brief_title'] = "{$this->order_inquiry['patient_name']}患者的电子处方已审核通过,请注意查看。";
$data['notice_title'] = "{$this->order_inquiry['patient_name']}患者的电子处方已审核通过,请注意查看。";
$data['notice_content'] = "{$this->order_inquiry['patient_name']}患者的电子处方已审核通过,请注意查看。";
$data['link_type'] = 3; // 问诊消息列表页
$link_params = array();
$link_params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$link_params['inquiry_type'] = $this->order_inquiry['inquiry_type'];
$link_params['doctor_user_id'] = $this->user['user_id'];
$link_params['patient_user_id'] = $this->order_inquiry['user_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) {
Log::getInstance("MessagePush")->error("错误:加入站内推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
// 订阅
$sub_data = array();
$sub_data['push_user_id'] = $this->user['user_id'];
$sub_data['wx_template_id'] = "kUy70xHlr7ADo4aIHiictM4Te7MSec3E5kHsYvFQu40"; // 处方审核结果通知
$sub_data['params']['page'] = "user/pages/yishi/chufangsetup/index?status=1";
$sub_data['params']['data'] = [
"phrase1" => "审方通过",// 审核结果
"thing2" => "审核通过",// 原因
"date3" => $order_prescription['pharmacist_verify_time'],// 审核时间
"thing4" => "建议您向患者补充说明如何用药",// 提示说明
];
// 短信
$sms_data = array();
$sms_data['template_code'] = "SMS_272120097";
$sms_data['scene_desc'] = "您为{$this->order_inquiry['patient_name']}患者开具的电子处方药师已审核通过,尽快和患者完成交流并提醒患者购药。请前往微信小程序“问诊消息”进行操作。";
$sms_data['phone'] = $this->user['mobile'];
$sms_data['user_id'] = $this->user['user_id'];
$template_param = array();
$template_param['name'] = $this->order_inquiry['patient_name'];
$sms_data['template_param'] = $template_param;
$data = array();
$data['sub_data'] = $sub_data;
$data['sms_data'] = $sms_data;
$message = new SendSubMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error("错误:加入站内推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error("错误:加入站内推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
}
/**
* 医生-开具的处方审核未通过
* 订阅失败发送短信
* @param string $order_prescription_id
* @return void
*/
public function prescriptionVerifyFail(string $order_prescription_id = ""): void
{
try {
// 获取问诊订单处方数据
$params = array();
$params['order_prescription_id'] = $order_prescription_id;
$order_prescription = OrderPrescription::getOne($params);
if (empty($order_prescription)) {
Log::getInstance("MessagePush")->error("错误:处方数据为空");
return;
}
// 订阅
$sub_data = array();
$sub_data['push_user_id'] = $this->user['user_id'];
$sub_data['wx_template_id'] = "kUy70xHlr7ADo4aIHiictM4Te7MSec3E5kHsYvFQu40"; // 处方审核结果通知
$sub_data['params']['page'] = "user/pages/yishi/chufangsetup/index?status=2";
$sub_data['params']['data'] = [
"phrase1" => "审方不通过",// 审核结果
"thing2" => (string)$order_prescription['pharmacist_fail_reason'],// 原因
"date3" => date('Y-m-d', time()),// 审核时间
"thing4" => "建议您提醒患者,稍后重新发起问诊申请开方",// 提示说明
];
// 短信
$sms_data = array();
$sms_data['template_code'] = "SMS_271905264";
$sms_data['scene_desc'] = "您为{$this->order_inquiry['patient_name']}患者开具的电子处方药师审核不通过,请尽快前往微信小程序“处方管理”中查看原因,并重开处方。";
$sms_data['phone'] = $this->user['mobile'];
$sms_data['user_id'] = $this->user['user_id'];
$template_param = array();
$template_param['name'] = $this->order_inquiry['patient_name'];
$sms_data['template_param'] = $template_param;
$data = array();
$data['sub_data'] = $sub_data;
$data['sms_data'] = $sms_data;
$message = new SendSubMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error("错误:加入站内推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error("错误:加入站内推送队列失败" . $e->getMessage());
}
}
/**
* 医师身份通过
* 短信
* @return bool
*/
public function DoctorIdenAuthSuccess(): bool
{
try {
if ($this->push_type == 3) {
// 短信
// 获取系统接诊配置
$data = array();
$data['template_code'] = "SMS_271925089";
$data['scene_desc'] = "医师身份通过";
$data['phone'] = $this->user['mobile'];
$data['user_id'] = $this->user['user_id'];
$template_param = array();
$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 (\Throwable $e) {
throw new BusinessException("加入推送队列失败" . $e->getMessage());
}
return true;
}
/**
* 医师身份未通过
* 短信
* @return bool
*/
public function DoctorIdenAuthFail(): bool
{
try {
if ($this->push_type == 3) {
// 短信
// 获取系统接诊配置
$data = array();
$data['template_code'] = "SMS_271905155";
$data['scene_desc'] = "医师身份未通过";
$data['phone'] = $this->user['mobile'];
$data['user_id'] = $this->user['user_id'];
$template_param = array();
$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 (\Throwable $e) {
throw new BusinessException("加入推送队列失败" . $e->getMessage());
}
return true;
}
/**
* 多点执业认证审核通过
* 站内、订阅发送失败发送短信
* @return bool
*/
public function doctorMultiPointSuccess(): bool
{
try {
if ($this->push_type == 1) {
// 站内
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 1;
$data['from_name'] = "肝胆小秘书";
$data['notice_title'] = "多点执业认证审核结果";
$data['notice_brief_title'] = "您提交的多点执业认证审核通过,查看详情;";
$data['notice_content'] = "{$this->user['user_name']}医生,您提交的多点执业认证审核通过,现在可以为患者开具电子处方了;";
$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['wx_template_id'] = "XWfEQYtb8_ubz8pCs3GoCG6TFxpDz9jn52895yvDm3s";// 审核结果通知
$sub_data['params']['page'] = "Pages/index/index";
$sub_data['params']['data'] = [
"thing1" => "多点执业认证审核通过",// 审核结果
"thing2" => "多点执业认证",// 审核内容
"time3" => $user_doctor['multi_point_time'],// 审核时间
"thing4" => "您提交的多点执业认证审核通过,点击查看详情。",// 备注
];
// 短信
$sms_data = array();
$sms_data['template_code'] = "SMS_271575911";
$sms_data['scene_desc'] = "多点执业认证审核通过";
$sms_data['phone'] = $this->user['mobile'];
$sms_data['user_id'] = $this->user['user_id'];
$template_param = array();
$sms_data['template_param'] = $template_param;
$data = array();
$data['sub_data'] = $sub_data;
$data['sms_data'] = $sms_data;
$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 (\Throwable $e) {
throw new BusinessException("加入推送队列失败" . $e->getMessage());
}
return true;
}
/**
* 多点执业认证审核未通过
* 站内、订阅发送失败发送短信
* @return bool
*/
public function doctorMultiPointFail(): bool
{
try {
if ($this->push_type == 1) {
// 站内
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 1;
$data['from_name'] = "肝胆小秘书";
$data['notice_title'] = "多点执业认证审核结果";
$data['notice_brief_title'] = "您提交的多点执业认证审核拒绝,查看详情;";
$data['notice_content'] = "{$this->user['user_name']}医生,您提交的多点执业认证审核未通过,请查看原因重新提交;";
$data['link_type'] = 4;// 我的名片
$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['wx_template_id'] = "bGGoKtDZC23GZtrrxuy6i5V7OhHgRgwXWx4yoDO1tlA";//资格审核未通过通知
$sub_data['params']['page'] = "Pages/index/index";
$sub_data['params']['data'] = [
"thing1" => "{$this->user['user_name']}医生您好,多点执业认证审核没有通过,请重新提交",// 温馨提示
"thing2" => $user_doctor['multi_point_fail_reason'],// 驳回理由
"time3" => $user_doctor['multi_point_time'],// 审核时间
];
// 短信
$sms_data = array();
$sms_data['template_code'] = "SMS_272030021";
$sms_data['scene_desc'] = "多点执业认证审核未通过";
$sms_data['phone'] = $this->user['mobile'];
$sms_data['user_id'] = $this->user['user_id'];
$template_param = array();
$sms_data['template_param'] = $template_param;
$data = array();
$data['sub_data'] = $sub_data;
$data['sms_data'] = $sms_data;
$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 (\Throwable $e) {
throw new BusinessException("加入推送队列失败" . $e->getMessage());
}
return true;
}
/**
* 医生简介审核通过-因缺少简介表,审核时间使用的是当前时间
* 站内、订阅发送失败发送短信
* @return bool
*/
public function doctorBriefSuccess(): bool
{
try {
// 获取医生数据
$params = array();
$params['doctor_id'] = $this->order_inquiry['doctor_id'];
$user_doctor = UserDoctor::getOne($params);
if (empty($user_doctor)) {
throw new BusinessException("加入推送队列失败:医生数据为空");
}
if ($this->push_type == 1) {
// 站内
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 1;
$data['from_name'] = "肝胆小秘书";
$data['notice_title'] = "简介信息审核结果";
$data['notice_brief_title'] = "{$this->user['user_name']}医生,您修改的简介信息审核通过,快去通知患者吧;";
$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) {
// 订阅
$sub_data = array();
$sub_data['push_user_id'] = $this->user['user_id'];
$sub_data['wx_template_id'] = "XWfEQYtb8_ubz8pCs3GoCG6TFxpDz9jn52895yvDm3s"; // 审核结果通知
$sub_data['params']['page'] = "Pages/index/index";
$sub_data['params']['data'] = [
"thing1" => "医师简介审核通过;",// 审核结果
"thing2" => "医师简介",// 审核内容
"time3" => date('Y-m-d H:i:s', time()),// 审核时间
"thing4" => "{$user_doctor['user_name']}医生,您修改的简介信息审核通过,快去通知患者吧。",// 备注
];
// 短信
$sms_data = array();
$sms_data['template_code'] = "SMS_271990126";
$sms_data['scene_desc'] = "医生简介审核通过";
$sms_data['phone'] = $this->user['mobile'];
$sms_data['user_id'] = $this->user['user_id'];
$template_param = array();
$sms_data['template_param'] = $template_param;
$data = array();
$data['sub_data'] = $sub_data;
$data['sms_data'] = $sms_data;
$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 (\Throwable $e) {
throw new BusinessException("加入推送队列失败" . $e->getMessage());
}
return true;
}
/**
* 医生简介审核未通过-因缺少简介表,审核时间使用的是当前时间,驳回理由未填写
* 站内、订阅发送失败发送短信
* @return bool
*/
public function doctorBriefFail(): bool
{
try {
if ($this->push_type == 1) {
// 站内
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 1;
$data['from_name'] = "肝胆小秘书";
$data['notice_title'] = "简介信息审核结果";
$data['notice_brief_title'] = "{$this->user['user_name']}医生,您修改的简介信息审核未通过,请查看原因重新提交;";
$data['link_type'] = 5;// 我的简介
$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['wx_template_id'] = "bGGoKtDZC23GZtrrxuy6i5V7OhHgRgwXWx4yoDO1tlA"; // 资格审核未通过通知
$sub_data['params']['page'] = "Pages/index/index";
$sub_data['params']['data'] = [
"thing1" => "{$this->user['user_name']}医生您好,简介信息审核没有通过,请重新提交",// 温馨提示
"thing2" => "未知",// 驳回理由
"time3" => date('Y-m-d H:i:s', time()),// 审核时间
];
// 短信
$sms_data = array();
$sms_data['template_code'] = "SMS_272165092";
$sms_data['scene_desc'] = "简介信息认证审核未通过";
$sms_data['phone'] = $this->user['mobile'];
$sms_data['user_id'] = $this->user['user_id'];
$template_param = array();
$sms_data['template_param'] = $template_param;
$data = array();
$data['sub_data'] = $sub_data;
$data['sms_data'] = $sms_data;
$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 (\Throwable $e) {
throw new BusinessException("加入推送队列失败" . $e->getMessage());
}
return true;
}
/**
* 医师服务费结算成功
* 站内、短信
* @param string $withdrawal_id
* @return bool
*/
public function doctorSettlementSuccess(string $withdrawal_id)
{
try {
// 获取医生提现表数据
$params = array();
$params['withdrawal_id'] = $withdrawal_id;
$doctor_withdrawal = DoctorWithdrawal::getOne($params);
if (empty($doctor_withdrawal)) {
Log::getInstance("MessagePush")->error("错误:提现数据为空");
return;
}
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'] = 6;// 我的账户
$data['button_type'] = 1;// 我的账户
$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) {
Log::getInstance("MessagePush")->error("错误:加入站内推送队列失败" . 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) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . $e->getMessage());
}
return true;
}
/**
* 医师服务费结算失败
* 站内、短信
* @param string $withdrawal_id
* @return bool
*/
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 (\Throwable $e) {
throw new BusinessException("加入推送队列失败" . $e->getMessage());
}
return true;
}
/**
* 小程序升级通知
* 站内
* @param string $date 日期
* @param string $function 功能
* @return bool
*/
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 (\Throwable $e) {
throw new BusinessException("加入推送队列失败" . $e->getMessage());
}
return true;
}
/**
* 小程序升级通知
* 站内
* @param string $title 协议名称
* @return bool
*/
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 (\Throwable $e) {
throw new BusinessException("加入推送队列失败" . $e->getMessage());
}
return true;
}
/**
* 医生-患者取消问诊
* 站内-订阅
* @return void
*/
public function patientCancelInquiryToDoctor(): void
{
try {
// 获取医生数据
$params = array();
$params['doctor_id'] = $this->order_inquiry['doctor_id'];
$user_doctor = UserDoctor::getOne($params);
if (empty($user_doctor)) {
Log::getInstance("MessagePush")->error("错误:医生数据为空");
return;
}
// 获取问诊订单关联病例
$params = array();
$params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$order_inquiry_case = OrderInquiryCase::getOne($params);
if (empty($order_inquiry_case)) {
Log::getInstance("MessagePush")->error("错误:病例数据为空");
return;
}
// 站内
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 1;
$data['inquiry_type'] = $this->order_inquiry['inquiry_type']; // 问诊类型(医生端服务通知存在 1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药)
$data['from_name'] = "肝胆小秘书";
$data['notice_brief_title'] = "患者已取消问诊咨询,您可选择其他患者的问诊咨询进行接诊。";
$data['notice_title'] = "患者已取消问诊咨询,您可选择其他患者的问诊咨询进行接诊。";
$data['notice_content'] = "患者已取消问诊咨询,您可选择其他患者的问诊咨询进行接诊。";
$data['link_type'] = 3; // 问诊消息列表页
$link_params = array();
$link_params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$link_params['inquiry_type'] = $this->order_inquiry['inquiry_type'];
$link_params['doctor_user_id'] = $user_doctor['user_id'];
$link_params['patient_user_id'] = $this->order_inquiry['user_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) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
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'] = "G1RIs0RYqsTQ2CuPQWalIMyb6_deuEEbJfajfhGvNzc";//咨询提醒
$sub_data['params']['page'] = "Pages/yishi/wenzhen_v2/wenzhen";
$sub_data['params']['data'] = [
"thing1" => "问诊咨询已取消",// 提醒内容
"name2" => (string)$this->order_inquiry['patient_name'],// 患者姓名
"thing4" => (string)$disease_desc,// 病情描述
"thing6" => "您可以选择其他患者的问诊咨询进行接诊",// 提示说明
"thing5" => "",// 咨询内容
];
$data = array();
$data['sub_data'] = $sub_data;
$data['sms_data'] = [];
$message = new SendSubMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . $e->getMessage());
}
}
/**
* 医生-超时未接诊
* 站内、订阅
* @return void
*/
public function doctorNoInquiry(): void
{
try {
// 获取问诊订单关联病例
$params = array();
$params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$order_inquiry_case = OrderInquiryCase::getOne($params);
if (empty($order_inquiry_case)) {
Log::getInstance("MessagePush")->error("错误:病例数据为空");
return;
}
// 站内
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 1;
$data['inquiry_type'] = $this->order_inquiry['inquiry_type']; // 问诊类型(医生端服务通知存在 1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药)
$data['from_name'] = "肝胆小秘书";
$data['notice_brief_title'] = "因您超时未接诊,订单已失效,已退款给患者。";
$data['notice_title'] = "因您超时未接诊,订单已失效,已退款给患者。";
$data['notice_content'] = "因您超时未接诊,订单已失效,已退款给患者。";
$message = new SendStationMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
// 问诊内容-病情主诉
$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'] = "G1RIs0RYqsTQ2CuPQWalIMyb6_deuEEbJfajfhGvNzc";//咨询提醒
$sub_data['params']['page'] = "";
$sub_data['params']['data'] = [
"thing1" => "超时未接诊",// 提醒内容
"name2" => (string)$this->order_inquiry['patient_name'],// 患者姓名
"thing4" => (string)$disease_desc,// 病情描述
"thing6" => "因您超时未接诊订单已失效,已退款给患者",// 提示说明
"thing5" => "",// 咨询内容
];
$data = array();
$data['sub_data'] = $sub_data;
$data['sms_data'] = [];
$message = new SendSubMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . $e->getMessage());
}
}
/**
* 患者-检测订单取消成功通知
* 订阅
* @param string $order_detection_id
* @return void
*/
public function patientCancelDetectionOrderSuccess(string $order_detection_id): void
{
try {
// 获取检测订单
$params = array();
$params['order_detection_id'] = $order_detection_id;
$order_detection = OrderDetection::getOne($params);
if (empty($order_detection)) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败,无检测订单数据");
return;
}
// 获取检测项目
$params = array();
$params['detection_project_id'] = $order_detection['detection_project_id'];
$detection_project = DetectionProject::getOne($params);
if (empty($detection_project)) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败,检测项目错误");
return;
}
$sub_data = array();
$sub_data['push_user_id'] = $this->user['user_id'];
$sub_data['wx_template_id'] = "5aJSrO8SU5rxqdB99zzl4rMVgcOTjt5mQh56cpZI1Hg";//咨询提醒
$sub_data['params']['page'] = "patient/pages/checkOrderDetail/checkOrderDetail?order_detection_id=" . $order_detection['detection_no'];
$sub_data['params']['data'] = [
"thing1" => $order_detection['patient_name'],// 就诊人
"thing7" => (string)$detection_project['detection_project_name'],// 服务项目
"time6" => date('Y年m月d日 H:i'),// 取消时间
"amount8" => $order_detection['payment_amount_total'],// 退款金额
"thing5" => "订单取消成功,支付金额将立即原路退回。",// 温馨提示
];
$data = array();
$data['sub_data'] = $sub_data;
$data['sms_data'] = [];
$message = new SendSubMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . $e->getMessage());
}
}
/**
* 患者-新报告生成通知
* 订阅发送失败发送短信
* @param string $order_detection_id
* @return void
*/
public function patientDetectionResultNotice(string $order_detection_id): void
{
try {
// 获取检测订单
$params = array();
$params['order_detection_id'] = $order_detection_id;
$order_detection = OrderDetection::getOne($params);
if (empty($order_detection)) {
Log::getInstance("MessagePush-patientDetectionResultNotice")->error("无检测订单数据");
return;
}
// 获取检测项目
$params = array();
$params['detection_project_id'] = $order_detection['detection_project_id'];
$detection_project = DetectionProject::getOne($params);
if (empty($detection_project)) {
Log::getInstance("MessagePush-patientDetectionResultNotice")->error("检测项目错误");
return;
}
// 获取检测机构名称
$params = array();
$params['detection_organ_id'] = $order_detection['detection_organ_id'];
$basic_detection_organ = BasicDetectionOrgan::getOne($params);
if (empty($basic_detection_organ)){
Log::getInstance("MessagePush-patientDetectionResultNotice")->error("检测机构错误");
return;
}
// 订阅
$sub_data = array();
$sub_data['push_user_id'] = $this->user['user_id'];
$sub_data['wx_template_id'] = "dNj3azLupP_w3j649v6lqz7je_ScqwgwFsnug6pKvyI"; // 处方审核结果通知
$sub_data['params']['page'] = "patient/pages/checkOrderDetail/checkOrderDetail?order_detection_id=" . $order_detection['detection_no'];
$sub_data['params']['data'] = [
"thing1" => "" . $detection_project['detection_project_name'] . "】报告已出",// 报告名称
"time3" => date('Y年m月d日 H:i'),// 生成时间
"thing9" => $order_detection['patient_name'],// 就诊人
"thing4" => $basic_detection_organ['detection_organ_name'],// 单位名称-检测所名称
"thing8" => "请联系医生做报告解读您有5个沟通回合。",// 测评结果
];
// 短信
$sms_data = array();
$sms_data['template_code'] = "SMS_462035956";
$sms_data['scene_desc'] = "新报告生成通知";
$sms_data['phone'] = $this->user['mobile'];
$sms_data['user_id'] = $this->user['user_id'];
$template_param = array();
$template_param['report'] = $detection_project['detection_project_name'];
$sms_data['template_param'] = $template_param;
$data = array();
$data['sub_data'] = $sub_data;
$data['sms_data'] = $sms_data;
$message = new SendSubMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush-patientDetectionResultNotice")->error(json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush-patientDetectionResultNotice")->error($e->getMessage());
}
}
/**
* 医生-通知医生患者检测报告已生成
* 短信
* @param string $order_detection_id
* @return void
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function doctorDetectionResultNotice(string $order_detection_id): void
{
// 获取检测订单
$params = array();
$params['order_detection_id'] = $order_detection_id;
$order_detection = OrderDetection::getOne($params);
if (empty($order_detection)) {
Log::getInstance("MessagePush-patientDetectionResultNotice")->error("无检测订单数据");
return;
}
// 获取检测项目
$params = array();
$params['detection_project_id'] = $order_detection['detection_project_id'];
$detection_project = DetectionProject::getOne($params);
if (empty($detection_project)) {
Log::getInstance("MessagePush-patientDetectionResultNotice")->error("检测项目错误");
return;
}
// 获取系统接诊配置
$data = array();
$data['template_code'] = "SMS_461980700";
$data['scene_desc'] = "通知医生患者检测报告已生成";
$data['phone'] = $this->user['mobile'];
$data['user_id'] = $this->user['user_id'];
$template_param = array();
$template_param['name'] = $order_detection['patient_name'];
$template_param['report'] = $detection_project['detection_project_name'];
$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));
}
}
/**
* 客服-通知客服
* 短信
* @param string $order_no
* @param string $mobile
* @return void
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function noticeReport(string $order_no,string $mobile): void
{
// 获取系统接诊配置
$data = array();
$data['template_code'] = "SMS_463525093";
$data['scene_desc'] = "通知客服";
$data['phone'] = $mobile;
$template_param = array();
$template_param['code'] = $order_no;
$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));
}
}
/**
* 患者-im消息通知
* 订阅
* @param string $msg
* @return void
*/
public function patientImMessageNotice(string $msg): void
{
try {
// 获取医生数据
$params = array();
$params['doctor_id'] = $this->order_inquiry['doctor_id'];
$user_doctor = UserDoctor::getOne($params);
if (empty($user_doctor)) {
Log::getInstance("MessagePush")->error("错误:医生数据为空");
return;
}
// im内容
if (strlen($msg) > 15) {
$msg = mb_substr($msg, 0, 15);
if ($msg) {
$msg = $msg . "...";
}
}
// 订阅
$sub_data = array();
$sub_data['push_user_id'] = $this->user['user_id'];
$sub_data['wx_template_id'] = "9v6dZhjg09CttLd3W9nEUV_-eshNc4BYYNy59jglvZE";// 问诊提醒
$sub_data['params']['page'] = "pages/message/message";
$sub_data['params']['data'] = [
"thing1" => (string)"医生回复了您的消息,点击查看详情",// 问诊内容
"thing2" => (string)$msg,// 提醒内容
"name3" => (string)$user_doctor['user_name'],// 问诊医生
"thing4" => "如有困扰,前往个人中心的设置中关闭",// 提示说明
];
$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) {
Log::getInstance("MessagePush-patientImMessageNotice")->error(json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush-patientImMessageNotice")->error($e->getMessage());
}
}
/**
* 医生-im消息通知
* 订阅
* @param string $msg
* @return void
*/
public function doctorImMessageNotice(string $msg): void
{
try {
// 获取问诊订单关联病例
$params = array();
$params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$order_inquiry_case = OrderInquiryCase::getOne($params);
if (empty($order_inquiry_case)) {
Log::getInstance("MessagePush")->error("错误:病例数据为空");
return;
}
// im内容
if (strlen($msg) > 15) {
$msg = mb_substr($msg, 0, 15);
if ($msg) {
$msg = $msg . "...";
}
}
// 问诊内容-病情主诉
$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'] = "G1RIs0RYqsTQ2CuPQWalIMyb6_deuEEbJfajfhGvNzc";// 问诊提醒
$sub_data['params']['page'] = "Pages/yishi/wenzhen_v2/wenzhen";
$sub_data['params']['data'] = [
"thing1" => $msg,// 提醒内容
"name2" => (string)$this->order_inquiry['patient_name'],// 患者姓名
"thing4" => (string)$disease_desc,// 病情描述
"thing6" => "患者发来了最新消息,点击查看详情",// 提示说明
];
$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) {
Log::getInstance("MessagePush-patientImMessageNotice")->error(json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush-patientImMessageNotice")->error($e->getMessage());
}
}
/**
* 患者-赠送回合数
* 站内、订阅失败发送短信
* @param string $times_number
* @param string $give_expiration_time 赠送到期时间
* @return void
*/
public function doctorGiveFreeRounds(string $times_number,string $give_expiration_time): void
{
try {
// 获取医生数据
$params = array();
$params['doctor_id'] = $this->order_inquiry['doctor_id'];
$user_doctor = UserDoctor::getOne($params);
if (empty($user_doctor)) {
Log::getInstance("MessagePush")->error("错误:医生数据为空");
return;
}
// 获取问诊订单关联病例
$params = array();
$params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$order_inquiry_case = OrderInquiryCase::getOne($params);
if (empty($order_inquiry_case)) {
Log::getInstance("MessagePush")->error("错误:病例数据为空");
return;
}
$producer = ApplicationContext::getContainer()->get(Producer::class);
$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'] = "您好,{$user_doctor['user_name']}医生已赠送您{$times_number}次回复机会,请在有效期内和医生进行问诊,请查看详情。";
$data['notice_title'] = "您好,{$user_doctor['user_name']}医生已赠送您{$times_number}次回复机会,请在有效期内和医生进行问诊,请查看详情。";
$data['notice_content'] = "您好,{$user_doctor['user_name']}医生已赠送您{$times_number}次回复机会(过期时间:{$give_expiration_time}),请在有效期内和医生进行问诊,请查看详情。";
$data['link_type'] = 10;// 问诊订单详情
$link_params = array();
$link_params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$link_params['inquiry_type'] = $this->order_inquiry['inquiry_type'];
$link_params['doctor_user_id'] = $user_doctor['user_id'];
$link_params['patient_user_id'] = $this->order_inquiry['user_id'];
$data['link_params'] = json_encode($link_params, JSON_UNESCAPED_UNICODE);// 跳转参数
$data['button_type'] = 4; // 订单详情
$message = new SendStationMessageProducer($data);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
// 订阅
// 问诊内容-病情主诉
$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 . "...";
}
}
}
// 赠送到期时间
$give_expiration_time = date('Y-m-d H:i',strtotime($give_expiration_time));
$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={$this->order_inquiry['order_inquiry_id']}";
$sub_data['params']['data'] = [
"thing1" => (string)$disease_desc,// 问诊内容-病情主诉
"thing2" => "医生赠送您{$times_number}次沟通机会",// 提醒内容
"name3" => (string)$user_doctor['user_name'],// 问诊医生
"thing4" => "有效期至{$give_expiration_time}",// 提示说明
];
// 短信
$sms_data = array();
$sms_data['template_code'] = "SMS_464725006";
$sms_data['scene_desc'] = "医生赠送免费回合数";
$sms_data['phone'] = $this->user['mobile'];
$sms_data['user_id'] = $this->user['user_id'];
$template_param = array();
$template_param['name'] = $user_doctor['user_name'];
$template_param['number'] = $times_number;
$template_param['time'] = $give_expiration_time;
$sms_data['template_param'] = $template_param;
$data = array();
$data['sub_data'] = $sub_data;
$data['sms_data'] = $sms_data;
$message = new SendSubMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error("错误:加入订阅推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . $e->getMessage());
}
}
/**
* 医生-医生有新的服务包订单
* 站内、订阅失败发送短信
* @return void
*/
public function doctorHaveNewServicePackage(): void
{
try {
// 获取医生数据
$params = array();
$params['doctor_id'] = $this->order_inquiry['doctor_id'];
$user_doctor = UserDoctor::getOne($params);
if (empty($user_doctor)) {
Log::getInstance("MessagePush")->error("医生数据为空");
return;
}
// 获取问诊订单关联病例
$params = array();
$params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$order_inquiry_case = OrderInquiryCase::getOne($params);
if (empty($order_inquiry_case)) {
Log::getInstance("MessagePush")->error("病例数据为空");
return;
}
// 转换问诊订单订单接诊方式-字符串
$inquiry_mode = orderServiceTypeToString($this->order_inquiry['inquiry_mode']);
// 站内
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 1;
$data['inquiry_type'] = $this->order_inquiry['inquiry_type']; // 问诊类型(医生端服务通知存在 1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药)
$data['from_name'] = "肝胆小秘书";
$data['notice_brief_title'] = "您有新的{$inquiry_mode}服务等待接诊,请及时处理。";
$data['notice_title'] = "您有新的{$inquiry_mode}服务等待接诊,请及时处理。";
$data['notice_content'] = "您有新的{$inquiry_mode}服务等待接诊,请及时处理。";
$data['link_type'] = 3; // 问诊消息列表页
$link_params = array();
$link_params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$link_params['inquiry_type'] = $this->order_inquiry['inquiry_type'];
$link_params['doctor_user_id'] = $user_doctor['user_id'];
$link_params['patient_user_id'] = $this->order_inquiry['user_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) {
Log::getInstance("MessagePush")->error(json_encode($data, JSON_UNESCAPED_UNICODE));
}
// 订阅
// 问诊内容-病情主诉
$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'] = "G1RIs0RYqsTQ2CuPQWalIMyb6_deuEEbJfajfhGvNzc";//咨询提醒
$sub_data['params']['page'] = "Pages/yishi/wenzhen_v2/wenzhen";
$sub_data['params']['data'] = [
"thing1" => "您有一个{$inquiry_mode}服务等待接诊",// 提醒内容
"name2" => (string)$this->order_inquiry['patient_name'],// 患者姓名
"thing4" => (string)$disease_desc,// 病情描述
"thing6" => "72小时内未接诊平台将自动取消服务",// 提示说明
"thing5" => "",// 咨询内容
];
// 短信
$sms_data = array();
$sms_data['template_code'] = "SMS_272015117";
$sms_data['scene_desc'] = "医生接到新服务包服务";
$sms_data['phone'] = $this->user['mobile'];
$sms_data['user_id'] = $this->user['user_id'];
$template_param = array();
$template_param['type'] = $inquiry_mode;
$sms_data['template_param'] = $template_param;
$data = array();
$data['sub_data'] = $sub_data;
$data['sms_data'] = $sms_data;
$message = new SendSubMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error(json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error( $e->getMessage());
}
}
/**
* 医生-医生有新的服务包问诊订单
* 站内、订阅失败发送短信
* @return void
*/
public function doctorHaveNewServicePackageInquiry(): void
{
try {
// 获取医生数据
$params = array();
$params['doctor_id'] = $this->order_inquiry['doctor_id'];
$user_doctor = UserDoctor::getOne($params);
if (empty($user_doctor)) {
Log::getInstance("MessagePush")->error("错误:医生数据为空");
return;
}
// 获取问诊订单关联病例
$params = array();
$params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$order_inquiry_case = OrderInquiryCase::getOne($params);
if (empty($order_inquiry_case)) {
Log::getInstance("MessagePush")->error("病例数据为空");
return;
}
// 转换问诊订单订单接诊方式-字符串
$inquiry_mode = orderServiceTypeToString($this->order_inquiry['inquiry_mode']);
// 站内
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 1;
$data['inquiry_type'] = $this->order_inquiry['inquiry_type']; // 问诊类型(医生端服务通知存在 1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药)
$data['from_name'] = "肝胆小秘书";
$data['notice_brief_title'] = "{$this->order_inquiry['patient_name']}患者发起{$inquiry_mode}服务中的一次问诊,请及时处理。";
$data['notice_title'] = "{$this->order_inquiry['patient_name']}患者发起{$inquiry_mode}服务中的一次问诊,请及时处理。";
$data['notice_content'] = "{$this->order_inquiry['patient_name']}患者发起{$inquiry_mode}服务中的一次问诊,请及时处理。";
$data['link_type'] = 3; // 问诊消息列表页
$link_params = array();
$link_params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$link_params['inquiry_type'] = $this->order_inquiry['inquiry_type'];
$link_params['doctor_user_id'] = $user_doctor['user_id'];
$link_params['patient_user_id'] = $this->order_inquiry['user_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) {
Log::getInstance("MessagePush")->error(json_encode($data, JSON_UNESCAPED_UNICODE));
}
// 订阅
// 问诊内容-病情主诉
$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'] = "G1RIs0RYqsTQ2CuPQWalIMyb6_deuEEbJfajfhGvNzc";//咨询提醒
$sub_data['params']['page'] = "Pages/yishi/wenzhen_v2/wenzhen";
$sub_data['params']['data'] = [
"thing1" => "发起{$inquiry_mode}服务中一次问诊",// 提醒内容
"name2" => (string)$this->order_inquiry['patient_name'],// 患者姓名
"thing4" => (string)$disease_desc,// 病情描述
"thing6" => "24小时内未接诊平台将自动取消问诊",// 提示说明
"thing5" => "",// 咨询内容
];
$data = array();
$data['sub_data'] = $sub_data;
$data['sms_data'] = [];
$message = new SendSubMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error(json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error( $e->getMessage());
}
}
/**
* 医生-患者取消服务包订单
* 站内-订阅
* @return void
*/
public function doctorPatientCancelServicePackage(): void
{
try {
// 获取医生数据
$params = array();
$params['doctor_id'] = $this->order_inquiry['doctor_id'];
$user_doctor = UserDoctor::getOne($params);
if (empty($user_doctor)) {
Log::getInstance("MessagePush")->error("医生数据为空");
return;
}
// 获取问诊订单关联病例
$params = array();
$params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$order_inquiry_case = OrderInquiryCase::getOne($params);
if (empty($order_inquiry_case)) {
Log::getInstance("MessagePush")->error("病例数据为空");
return;
}
// 转换问诊订单订单接诊方式-字符串
$inquiry_mode = orderServiceTypeToString($this->order_inquiry['inquiry_mode']);
// 站内
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 1;
$data['inquiry_type'] = $this->order_inquiry['inquiry_type']; // 问诊类型(医生端服务通知存在 1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药)
$data['from_name'] = "肝胆小秘书";
$data['notice_brief_title'] = "{$this->order_inquiry['patient_name']}患者已取消{$inquiry_mode}服务,您可选择其他患者的问诊咨询进行接诊。";
$data['notice_title'] = "{$this->order_inquiry['patient_name']}患者已取消{$inquiry_mode}服务,您可选择其他患者的问诊咨询进行接诊。";
$data['notice_content'] = "{$this->order_inquiry['patient_name']}患者已取消{$inquiry_mode}服务,您可选择其他患者的问诊咨询进行接诊。";
$data['link_type'] = 3; // 问诊消息列表页
$link_params = array();
$link_params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$link_params['inquiry_type'] = $this->order_inquiry['inquiry_type'];
$link_params['doctor_user_id'] = $user_doctor['user_id'];
$link_params['patient_user_id'] = $this->order_inquiry['user_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) {
Log::getInstance("MessagePush")->error(json_encode($data, JSON_UNESCAPED_UNICODE));
}
// 问诊内容-病情主诉
$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'] = "G1RIs0RYqsTQ2CuPQWalIMyb6_deuEEbJfajfhGvNzc";//咨询提醒
$sub_data['params']['page'] = "Pages/yishi/wenzhen_v2/wenzhen";
$sub_data['params']['data'] = [
"thing1" => "{$inquiry_mode}服务已取消",// 提醒内容
"name2" => (string)$this->order_inquiry['patient_name'],// 患者姓名
"thing4" => (string)$disease_desc,// 病情描述
"thing6" => "您可以选择其他患者的问诊咨询进行接诊",// 提示说明
"thing5" => "",// 咨询内容
];
$data = array();
$data['sub_data'] = $sub_data;
$data['sms_data'] = [];
$message = new SendSubMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error(json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error($e->getMessage());
}
}
/**
* 医生-医生xx时间后还未接受服务包订单
* 站内、订阅失败发送短信
* @return void
*/
public function doctorNotYetOrderServicePackage(): void
{
try {
// 获取问诊订单关联病例
$params = array();
$params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$order_inquiry_case = OrderInquiryCase::getOne($params);
if (empty($order_inquiry_case)) {
Log::getInstance("MessagePush")->error("医生数据为空");
return;
}
// 转换问诊订单订单接诊方式-字符串
$inquiry_mode = orderServiceTypeToString($this->order_inquiry['inquiry_mode']);
// 站内
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 1;
$data['inquiry_type'] = $this->order_inquiry['inquiry_type']; // 问诊类型(医生端服务通知存在 1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药)
$data['from_name'] = "肝胆小秘书";
$data['notice_brief_title'] = "{$this->order_inquiry['patient_name']}患者的{$inquiry_mode}服务您还未接诊,请及时处理。";
$data['notice_title'] = "{$this->order_inquiry['patient_name']}患者的{$inquiry_mode}服务您还未接诊,请及时处理。";
$data['notice_content'] = "{$this->order_inquiry['patient_name']}患者的{$inquiry_mode}服务您还未接诊,请及时处理。";
$data['link_type'] = 3; // 问诊消息列表页.
$link_params = array();
$link_params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$link_params['inquiry_type'] = $this->order_inquiry['inquiry_type'];
$link_params['doctor_user_id'] = $this->user['user_id'];
$link_params['patient_user_id'] = $this->order_inquiry['user_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) {
Log::getInstance("MessagePush")->error(json_encode($data, JSON_UNESCAPED_UNICODE));
}
// 问诊内容-病情主诉
$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'] = "G1RIs0RYqsTQ2CuPQWalIMyb6_deuEEbJfajfhGvNzc"; // 咨询提醒
$sub_data['params']['page'] = "Pages/yishi/wenzhen_v2/wenzhen";
$sub_data['params']['data'] = [
"thing1" => "您好医生,有新的{$inquiry_mode}服务您还未接诊",// 提醒内容
"name2" => $this->order_inquiry['patient_name'],// 患者姓名
"thing4" => mb_substr($order_inquiry_case['disease_desc'], 0, 18),// 病情描述
"thing6" => "您还未接诊,请及时上线处理",// 提示说明
"thing5" => "",// 咨询内容
];
$sms_data = array();
$sms_data['template_code'] = "SMS_271905266";
$sms_data['scene_desc'] = "医生xx时间后还未接诊";
$sms_data['phone'] = $this->user['mobile'];
$sms_data['user_id'] = $this->user['user_id'];
$template_param = array();
$template_param['type'] = $inquiry_mode;
$template_param['name'] = $this->order_inquiry['patient_name'];
$sms_data['template_param'] = $template_param;
$data = array();
$data['sub_data'] = $sub_data;
$data['sms_data'] = $sms_data;
$message = new SendSubMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error(json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error($e->getMessage());
}
}
/**
* 医生-通知医生患者的服务包服务结束
* 站内订阅
* 发送给医生
* @return void
*/
public function doctorServicePackageFinish(): void
{
try {
$params = array();
$params['order_service_no'] = $this->order['order_no'];
$order_service_package = OrderServicePackage::getOne($params);
if (empty($order_service_package)) {
Log::getInstance("MessagePush")->error("服务包订单为空");
return;
}
// 获取问诊订单关联病例
$params = array();
$params['order_service_id'] = $order_service_package['order_service_id'];
$order_service_package_case= OrderServicePackageCase::getOne($params);
if (empty($order_service_package_case)) {
Log::getInstance("MessagePush")->error("服务包病例为空");
return;
}
// 获取医生数据
$params = array();
$params['doctor_id'] = $order_service_package['doctor_id'];
$user_doctor = UserDoctor::getOne($params);
if (empty($user_doctor)) {
Log::getInstance("MessagePush")->error("医生数据为空");
return;
}
// 转换问诊订单订单接诊方式-字符串
$order_service_type = orderServiceTypeToString($order_service_package['order_service_type']);
if ($order_service_package['order_service_type'] == 1){
$inquiry_mode = 8;
}else{
$inquiry_mode = 9;
}
// 站内
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 1;
$data['inquiry_type'] = 1; // 问诊类型(医生端服务通知存在 1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药)
$data['inquiry_mode'] = $inquiry_mode; // 接诊方式1:图文 2:视频 3:语音 4:电话 5:会员 6:疑难会诊 7:附赠 8:健康包 9:随访包)
$data['from_name'] = "肝胆小秘书";
$data['notice_brief_title'] = "{$order_service_package['patient_name']}患者的{$order_service_type}服务已完成,您可以提醒患者进行续费。";
$data['notice_title'] = "{$order_service_package['patient_name']}患者的{$order_service_type}服务已完成,您可以提醒患者进行续费。";
$data['notice_content'] = "{$order_service_package['patient_name']}患者的{$order_service_type}服务已完成,您可以提醒患者进行续费。";
$message = new SendStationMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error(json_encode($data, JSON_UNESCAPED_UNICODE));
}
// 订阅
// 问诊内容-病情主诉
$disease_desc = $order_service_package_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'] = "G1RIs0RYqsTQ2CuPQWalIMyb6_deuEEbJfajfhGvNzc"; // 咨询提醒
$sub_data['params']['page'] = "Pages/yishi/wenzhen_v2/wenzhen";
$sub_data['params']['data'] = [
"thing1" => "{$order_service_type}服务已完成",// 提醒内容
"name2" => $this->order_inquiry['patient_name'],// 患者姓名
"thing4" => $disease_desc,// 病情描述
"thing6" => "您可以提醒患者进行续费",// 提示说明
"thing5" => "",// 咨询内容
];
$data = array();
$data['sub_data'] = $sub_data;
$data['sms_data'] = [];
$message = new SendSubMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error(json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . $e->getMessage());
}
}
/**
* 患者-通知患者医生已接受服务包服务
* 站内、订阅
* @return void
*/
public function patientAcceptedServicePackage(): void
{
try {
// 获取医生数据
$params = array();
$params['doctor_id'] = $this->order_inquiry['doctor_id'];
$user_doctor = UserDoctor::getOne($params);
if (empty($user_doctor)) {
Log::getInstance("MessagePush")->error("医生数据为空");
return;
}
// 获取问诊订单关联病例
$params = array();
$params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$order_inquiry_case = OrderInquiryCase::getOne($params);
if (empty($order_inquiry_case)) {
Log::getInstance("MessagePush")->error("病例数据为空");
return;
}
// 获取服务包订单详情
$params = array();
$params['order_service_no'] = $this->order_service_package['order_no'];
$order_service_package_detail = OrderServicePackageDetail::getOne($params);
if (empty($order_service_package_detail)){
Log::getInstance("MessagePush")->error("服务包订单数据为空");
return;
}
// 转换服务包订单类型为汉字
$order_type = orderServiceTypeToString($this->order_service_package['order_service_type']);
// 转换每月次数为汉字
$monthly_frequency = monthlyFrequencyToString($order_service_package_detail['monthly_frequency']);
$start_time = date('Y年m月d日 H时i分',strtotime($this->order_service_package['start_time']));
$finish_time = date('Y年m月d日 H时i分',strtotime($this->order_service_package['finish_time']));
// 站内
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 3;
$data['notice_system_type'] = 1;
$data['inquiry_mode'] = $this->order_inquiry['inquiry_mode']; // 接诊方式1:图文 2:视频 3:语音 4:电话 5:会员 6:疑难会诊 7:附赠 8:健康包 9:随访包)
$data['from_name'] = "肝胆小秘书";
$data['notice_brief_title'] = "您购买的{$order_type}服务,医生已接受,点击查看详情。";
$data['notice_title'] = "您购买的{$order_type}服务,医生已接受,点击查看详情。";
$data['notice_content'] = "您购买的{$order_type}服务,{$user_doctor['user_name']}医生已接受,服务包含:({$monthly_frequency}次问诊/月30盒肝爽颗粒服务有效期{$start_time}~{$finish_time},每次问诊不限制沟通回合数,您可以点击【问诊详情】进行交流。";
$data['link_type'] = 15;// 聊天详情页
$link_params = array();
$link_params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$link_params['order_no'] = $this->order['order_no'];
$link_params['inquiry_type'] = $this->order_inquiry['inquiry_type'];
$link_params['doctor_user_id'] = $user_doctor['user_id'];
$link_params['patient_user_id'] = $this->order_inquiry['user_id'];
$data['link_params'] = json_encode($link_params, JSON_UNESCAPED_UNICODE);// 跳转参数
$data['button_type'] = 4;
$message = new SendStationMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->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'] = "healthyService/pages/healthyOrderDetail/healthyOrderDetail?order_service_id={$this->order_service_package['order_service_no']}";
$sub_data['params']['data'] = [
"thing1" => "{$order_type}服务",// 问诊内容
"thing2" => "医生已接受",// 提醒内容
"name3" => (string)$user_doctor['user_name'],// 问诊医生
"thing4" => "点击查看详情",// 提示说明
];
$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) {
Log::getInstance("MessagePush")->error(json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error($e->getMessage());
}
}
/**
* 患者-通知患者医生已接诊服务包相关问诊订单
* 站内、订阅
* @return void
*/
public function patientAcceptedServicePackageInquiry(): void
{
try {
// 获取医生数据
$params = array();
$params['doctor_id'] = $this->order_inquiry['doctor_id'];
$user_doctor = UserDoctor::getOne($params);
if (empty($user_doctor)) {
Log::getInstance("MessagePush")->error("医生数据为空");
return;
}
// 获取问诊订单关联病例
$params = array();
$params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$order_inquiry_case = OrderInquiryCase::getOne($params);
if (empty($order_inquiry_case)) {
Log::getInstance("MessagePush")->error("病例数据为空");
return;
}
// 获取服务包订单详情
$params = array();
$params['order_service_no'] = $this->order_service_package['order_no'];
$order_service_package_detail = OrderServicePackageDetail::getOne($params);
if (empty($order_service_package_detail)){
Log::getInstance("MessagePush")->error("服务包订单数据为空");
return;
}
// 转换服务包订单类型为汉字
$order_type = orderServiceTypeToString($this->order_service_package['order_service_type']);
$OrderServicePackageService = new OrderServicePackageService();
if ($order_service_package_detail['monthly_frequency'] != 0) {
// 获取服务包当月已问诊次数
$month_inquiry_count = $OrderServicePackageService->getCurrentMonthInquiryCount($this->order_service_package['pay_time'],$this->order_service_package['order_service_type'],$this->order_service_package['user_id'], $this->order_service_package['doctor_id']);
// 获取服务包当月剩余问诊次数
$remaining_inquiry_count = $order_service_package_detail['monthly_frequencys'] - $month_inquiry_count;
if ($remaining_inquiry_count < 0){
$remaining_inquiry_count = 0;
}
}else{
$remaining_inquiry_count = "不限";
}
// 获取剩余药品数量
$remaining_quantity = 0;
if ($this->order_service_package['order_service_type'] == 1){
// 获取服务包内所有药品
$health_package_products = $OrderServicePackageService->getOrderServiceProduct($order_service_package_detail['package_id']);
foreach ($health_package_products as $health_package_product) {
// 获取服务包内某一药品的剩余数量
$remaining_quantity = $OrderServicePackageService->getOrderServiceProductCanUseQuantity($this->order_service_package['order_service_id'],$health_package_product['product_id'],$health_package_product['quantity']);
}
}
// 站内
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 3;
$data['notice_system_type'] = 1;
$data['inquiry_mode'] = $this->order_inquiry['inquiry_mode']; // 接诊方式1:图文 2:视频 3:语音 4:电话 5:会员 6:疑难会诊 7:附赠 8:健康包 9:随访包)
$data['from_name'] = "肝胆小秘书";
$data['notice_brief_title'] = "您使用{$order_type}服务中问诊,医生已接诊,点击查看详情。";
$data['notice_title'] = "您使用{$order_type}服务中问诊,医生已接诊,点击查看详情。";
$data['notice_content'] = "您使用{$order_type}服务中问诊,{$user_doctor['user_name']}医生已接诊,服务剩余:({$remaining_inquiry_count}次问诊/月;{$remaining_quantity}盒肝爽颗粒),您可以点击【问诊详情】进行交流。
";
$data['link_type'] = 1;
$link_params = array();
$link_params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$link_params['order_no'] = $this->order['order_no'];
$link_params['inquiry_type'] = $this->order_inquiry['inquiry_type'];
$link_params['doctor_user_id'] = $user_doctor['user_id'];
$link_params['patient_user_id'] = $this->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("MessagePush")->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={$this->order_inquiry['order_inquiry_id']}";
$sub_data['params']['data'] = [
"thing1" => "使用{$order_type}服务中问诊",// 问诊内容
"thing2" => "医生已接诊",// 提醒内容
"name3" => (string)$user_doctor['user_name'],// 问诊医生
"thing4" => "点击查看详情",// 提示说明
];
$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) {
Log::getInstance("MessagePush")->error(json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error($e->getMessage());
}
}
/**
* 患者-通知患者服务包服务已结束
* 站内、订阅
* @return void
*/
public function patientServicePackageFinish(): void
{
try {
// 获取问诊订单关联病例
$params = array();
$params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$order_inquiry_case = OrderInquiryCase::getOne($params);
if (empty($order_inquiry_case)) {
Log::getInstance("MessagePush")->error("问诊病例为空");
return;
}
// 获取医生数据
$params = array();
$params['doctor_id'] = $this->order_inquiry['doctor_id'];
$user_doctor = UserDoctor::getOne($params);
if (empty($user_doctor)) {
Log::getInstance("MessagePush")->error("医生数据为空");
return;
}
// 转换服务包订单类型为汉字
$order_type = orderServiceTypeToString($this->order_service_package['order_service_type']);
// 站内
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 1;
$data['inquiry_type'] = $this->order_inquiry['inquiry_type']; // 问诊类型(医生端服务通知存在 1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药)
$data['from_name'] = "肝胆小秘书";
$data['notice_brief_title'] = "您购买的{$order_type}服务已结束,点击查看详情。";
$data['notice_title'] = "您购买的{$order_type}服务已结束,点击查看详情。";
$data['notice_content'] = "您购买的{$order_type}服务已结束,您可以继续购买医生的{$order_type}进行问诊。";
$data['link_type'] = 15;
$link_params = array();
$link_params['order_no'] = $this->order['order_no'];
$link_params['doctor_user_id'] = $user_doctor['user_id'];
$link_params['patient_user_id'] = $this->order_service_package['user_id'];
$data['link_params'] = json_encode($link_params, JSON_UNESCAPED_UNICODE);// 跳转参数
$data['button_type'] = 4;
$message = new SendStationMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error(json_encode($data, JSON_UNESCAPED_UNICODE));
}
// 订阅
// 问诊内容-病情主诉
$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'] = "healthyService/pages/healthyOrderDetail/healthyOrderDetail?order_service_id={$this->order['order_no']}";
$sub_data['params']['data'] = [
"thing1" => "{$order_type}服务",// 问诊内容
"thing2" => "已结束",// 提醒内容
"name3" => (string)$user_doctor['user_name'],// 问诊医生
"thing4" => "如您还需服务,请点击此处续费",// 提示说明
];
$data = array();
$data['sub_data'] = $sub_data;
$data['sms_data'] = [];
$message = new SendSubMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error(json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error($e->getMessage());
}
}
/**
* 患者-通知患者服务包药品未使用完
* 站内
* @param string|int $remaining_quantity
* @return void
*/
public function patientServicePackageHaveProduct(string|int $remaining_quantity = 0): void
{
try {
// 获取医生数据
$params = array();
$params['doctor_id'] = $this->order_inquiry['doctor_id'];
$user_doctor = UserDoctor::getOne($params);
if (empty($user_doctor)) {
Log::getInstance("MessagePush")->error("医生数据为空");
return;
}
if ($remaining_quantity == 0){
$OrderServicePackageService = new OrderServicePackageService();
// 获取服务包订单编号-通过问诊订单id
$order_service_no = $OrderServicePackageService->getOrderServiceNoByOrderInquiryId($this->order_inquiry['inquiry_no']);
// 获取服务包订单
$params = array();
$params['order_service_no'] = $order_service_no;
$order_service_package = OrderServicePackage::getOne($params);
if (empty($order_service_package)){
Log::getInstance("MessagePush")->error("服务包订单错误");
return;
}
// 获取服务包订单详情
$params = array();
$params['order_service_id'] = $order_service_package['order_service_id'];
$order_service_package_detail = OrderServicePackageDetail::getOne($params);
if (empty($order_service_package_detail)){
Log::getInstance("MessagePush")->error("服务包订单详情错误");
return;
}
// 获取服务包内所有药品
$health_package_products = $OrderServicePackageService->getOrderServiceProduct($order_service_package_detail['package_id']);
foreach ($health_package_products as $health_package_product) {
// 获取服务包内某一药品的剩余数量
$remaining_quantity = $OrderServicePackageService->getOrderServiceProductCanUseQuantity($order_service_package['order_service_id'],$health_package_product['product_id'],$health_package_product['quantity']);
}
}
// 站内
$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'] = "您购买的健康包服务中,有福利还未使用,点击查看详情。";
$data['notice_title'] = "您购买的健康包服务中,有福利还未使用,点击查看详情。";
$data['notice_content'] = "您购买的健康包服务中包含30盒“肝爽颗粒步长目前剩余{$remaining_quantity}盒,您可以进入【订单详情】查看具体情况,在问诊中与医生沟通开具处方。";
$data['link_type'] = 15;
$link_params = array();
$link_params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$link_params['order_no'] = $this->order_service_package['order_no'];
$link_params['inquiry_type'] = $this->order_inquiry['inquiry_type'];
$link_params['doctor_user_id'] = $user_doctor['user_id'];
$link_params['patient_user_id'] = $this->order_inquiry['user_id'];
$data['link_params'] = json_encode($link_params, JSON_UNESCAPED_UNICODE);// 跳转参数
$data['button_type'] = 4;
$message = new SendStationMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error(json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error($e->getMessage());
}
}
/**
* 患者-医生未接受服务包订单
* 站内、订阅、短信
* @return void
*/
public function patientDoctorNoAcceptServicePackage(): void
{
try {
// 获取医生数据
$params = array();
$params['doctor_id'] = $this->order_inquiry['doctor_id'];
$user_doctor = UserDoctor::getOne($params);
if (empty($user_doctor)) {
Log::getInstance("MessagePush")->error("医生数据为空");
return;
}
// 转换问诊订单订单接诊方式-字符串
$inquiry_mode = orderServiceTypeToString($this->order_inquiry['inquiry_mode']);
// 站内
$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'] = "您购买的{$inquiry_mode}服务,医生未及时确认,点击查看详情。";
$data['notice_title'] = "您购买的{$inquiry_mode}服务,医生未及时确认,点击查看详情。";
$data['notice_content'] = "您购买的{$inquiry_mode}服务,{$user_doctor['user_name']}医生未及时确认,平台已自动发起退款,请注意查看账户信息。";
$data['link_type'] = 15;
$link_params = array();
$link_params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
$link_params['order_no'] = $this->order_service_package['order_no'];
$link_params['inquiry_type'] = $this->order_inquiry['inquiry_type'];
$link_params['doctor_user_id'] = $user_doctor['user_id'];
$link_params['patient_user_id'] = $this->order_inquiry['user_id'];
$data['link_params'] = json_encode($link_params, JSON_UNESCAPED_UNICODE);// 跳转参数
$data['button_type'] = 4;
$message = new SendStationMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->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'] = "healthyService/pages/healthyOrderDetail/healthyOrderDetail?order_service_id={$this->order_service_package['order_service_no']}";
$sub_data['params']['data'] = [
"thing1" => "{$inquiry_mode}服务",// 问诊内容
"thing2" => "未及时确认",// 提醒内容
"name3" => (string)$user_doctor['user_name'],// 问诊医生
"thing4" => "平台已自动发起退款,请注意查看账户信息",// 提示说明
];
$data = array();
$data['sub_data'] = $sub_data;
$data['sms_data'] = [];
$message = new SendSubMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error(json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error("错误:" . $e->getMessage());
}
}
/**
* 患者-服务包服务退款成功
* 站内、订阅
* @return void
*/
public function refundServicePackageSuccess(): void
{
try {
// 获取医生数据
$params = array();
$params['doctor_id'] = $this->order['doctor_id'];
$user_doctor = UserDoctor::getOne($params);
if (empty($user_doctor)) {
Log::getInstance("MessagePush")->error("医生数据为空");
return;
}
// 转换问诊订单订单接诊方式-字符串
$order_type = orderTypeToString($this->order['order_type']);
// 站内
$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}服务,订单取消成功,点击查看详情。";
$data['notice_content'] = "您购买的{$order_type}服务,订单取消成功,平台已自动发起退款,请注意查看账户信息。";
$data['link_type'] = 15;
$link_params = array();
$link_params['order_no'] = $this->order['order_no'];
$link_params['inquiry_type'] = 1;
$link_params['doctor_user_id'] = $user_doctor['user_id'];
$link_params['patient_user_id'] = $this->order['user_id'];
$data['link_params'] = json_encode($link_params, JSON_UNESCAPED_UNICODE);// 跳转参数
$data['button_type'] = 4;
$message = new SendStationMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->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'] = "healthyService/pages/healthyOrderDetail/healthyOrderDetail?order_service_id={$this->order['order_no']}";
$sub_data['params']['data'] = [
"thing1" => "{$order_type}服务",// 问诊内容
"thing2" => "取消订单成功",// 提醒内容
"name3" => (string)$user_doctor['user_name'],// 问诊医生
"thing4" => "平台已自动发起退款,请注意查看账户信息",// 提示说明
];
// 短信
$sms_data = array();
$sms_data['template_code'] = "SMS_465655405";
$sms_data['scene_desc'] = "服务包服务退款成功";
$sms_data['phone'] = $this->user['mobile'];
$sms_data['user_id'] = $this->user['user_id'];
$template_param = array();
$template_param['type'] = $order_type;
$template_param['name'] = (string)$user_doctor['user_name'];
$sms_data['template_param'] = $template_param;
$data = array();
$data['sub_data'] = $sub_data;
$data['sms_data'] = $sms_data;
$message = new SendSubMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Log::getInstance("MessagePush")->error(json_encode($data, JSON_UNESCAPED_UNICODE));
}
} catch (\Throwable $e) {
Log::getInstance("MessagePush")->error("错误:" . $e->getMessage());
}
}
}