<?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\DoctorWithdrawal;
use App\Model\OrderInquiry;
use App\Model\OrderInquiryCase;
use App\Model\OrderPrescription;
use App\Model\OrderProduct;
use App\Model\OrderProductItem;
use App\Model\Product;
use App\Model\SystemInquiryConfig;
use App\Model\User;
use App\Model\UserDoctor;
use Hyperf\Amqp\Producer;
use Hyperf\Utils\ApplicationContext;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

/**
 * 消息推送业务类
 */
class MessagePush extends BaseService
{
    // 推送类型 1：站内 2：订阅 3：短信
    public int $push_type;

    // 用户数据(存在被推送者时存在,否则为空)
    public array $user = [];

    // 问诊订单数据(可为空)
    public array $order_inquiry = [];

    /**
     * @param int $push_type 推送类型 1：站内 2：订阅 3：短信
     * @param string $to_user_id 用户id（存在被推送者时存在,否则为空）
     * @param string $order_inquiry_id 问诊订单id
     */
    public function __construct(int $push_type, string $to_user_id = "", string $order_inquiry_id = "")
    {
        if (!in_array($push_type, [1, 2, 3])) {
            throw new BusinessException("推送类型错误:" . $push_type);
        }
        $this->push_type = $push_type;

        if (!empty($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_inquiry_id)) {
            $params = array();
            $params['order_inquiry_id'] = $order_inquiry_id;
            $order_inquiry = OrderInquiry::getOne($params);
            if (!empty($order_inquiry)) {
                $this->order_inquiry = $order_inquiry->toArray();
            }
        }
    }

    /**
     * 医生未接诊
     *  快速/购药的服务5分钟未接诊
     *  公益/专家24小时未接诊
     * 站内、订阅
     * @return bool
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function patientNoInquiry(): bool
    {
        try {
            if ($this->push_type == 1) {
                // 站内
                // 服务消息
                $data = array();
                $data['user_id'] = $this->user['user_id'];
                $data['notice_type'] = 3;
                $data['notice_system_type'] = 1;
                $data['from_name'] = "肝胆小秘书";
                if ($this->order_inquiry['inquiry_type'] == 1 || $this->order_inquiry['inquiry_type'] == 3) {
                    // 专家-公益
                    $data['notice_brief_title'] = "您咨询的服务暂无医生接诊，点击查看详情。";
                    $data['notice_title'] = "您咨询的服务暂无医生接诊，点击查看详情。";
                    $data['notice_content'] = "您咨询的服务当前排队人较多，暂无空闲医生接诊。给您带来不便敬请谅解，平台会在24小时内进行退款，您可以点击订单详情查看退款详情。";

                } elseif ($this->order_inquiry['inquiry_type'] == 1 || $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) {
                    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'] = "UOMww1S30Oq7rErJrqO8wN6lNEVKRo2fgcXnb0tBwHI";//问诊异常通知
                $sub_data['params']['page'] = "pages/orderDetail/orderDetail?order_inquiry_id={$this->order_inquiry['order_inquiry_id']}";
                $sub_data['params']['data'] = [
                    "character_string1" => $this->order_inquiry['inquiry_no'],// 订单ID
                    "name2" => (string)$user_doctor['user_name'],// 问诊医生
                    "date3" => $this->order_inquiry['created_at'],// 问诊时间
                    "thing4" => inquiryCancelReasonToString($this->order_inquiry['cancel_reason']),// 取消原因
                    "thing5" => "点击详情更换医生问诊",// 提示说明
                ];

                $data = array();
                $data['sub_data'] = $sub_data;
                $data['sms_data'] = array();

                $message = new SendSubMessageProducer($data);
                $producer = ApplicationContext::getContainer()->get(Producer::class);
                $result = $producer->produce($message);
                if (!$result) {
                    throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
                }

            }
        } catch (\Exception $e) {
            throw new BusinessException("加入推送队列失败" . $e->getMessage());
        }

        return true;
    }

    /**
     * 通知医生患者回复
     * 订阅
     * @param string $content 回复内容
     * @return bool
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function patientReplyNotice(string $content): bool
    {
        try {
            // 只有订阅消息
            if ($this->push_type == 2){
                $sub_data = array();
                $sub_data['push_user_id'] = $this->user['user_id'];
                $sub_data['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 (\Exception $e) {
            throw new BusinessException("加入推送队列失败" . $e->getMessage());
        }

        return true;
    }

    /**
     * 通知患者医生已接诊
     * 站内、订阅、短信
     * @return bool
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function patientAcceptedInquiry(): 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'] = 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) {
                    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'] = "9v6dZhjg09CttLd3W9nEUV_-eshNc4BYYNy59jglvZE";// 问诊提醒
                $sub_data['params']['page'] = "pages/orderDetail/orderDetail?order_inquiry_id={$this->order_inquiry['order_inquiry_id']}";
                $sub_data['params']['data'] = [
                    "thing1" => "问诊内容",// 问诊内容
                    "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) {
                    throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
                }

            } elseif ($this->push_type == 3) {
                // 短信
                // 获取系统接诊配置
                $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)) {
                    throw new BusinessException("加入推送队列失败:获取系统接诊配置失败");
                }

                $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) {
                    throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
                }
            }
        } catch (\Exception $e) {
            throw new BusinessException("加入推送队列失败" . $e->getMessage());
        }

        return true;
    }

    /**
     * 患者的问诊服务结束
     * 站内、订阅
     * @return bool
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function patientInquiryFinish(): 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) {
                // 站内
                // 服务消息
                $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);
                $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'] = "9v6dZhjg09CttLd3W9nEUV_-eshNc4BYYNy59jglvZE"; // 问诊提醒
                $sub_data['params']['page'] = "pages/orderDetail/orderDetail?order_inquiry_id={$this->order_inquiry['order_inquiry_id']}";
                $sub_data['params']['data'] = [
                    "thing1" => "问诊内容",// 问诊内容
                    "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) {
                    throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
                }
            }
        } catch (\Exception $e) {
            throw new BusinessException("加入推送队列失败" . $e->getMessage());
        }

        return true;
    }

    /**
     * 患者的处方被药师审核通过
     * 站内、短信
     * @return bool
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function patientPrescriptionVerifyPass(): 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) {
                // 站内
                // 服务消息
                // 获取问诊订单处方数据
                $params = array();
                $params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
                $order_prescription = OrderPrescription::getOne($params);
                if (empty($order_prescription)) {
                    throw new BusinessException("加入推送队列失败:处方数据为空");
                }

                $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) {
                    throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
                }
            } elseif ($this->push_type == 3) {
                // 短信
                $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) {
                    throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
                }
            }
        } catch (\Exception $e) {
            throw new BusinessException("加入推送队列失败" . $e->getMessage());
        }

        return true;
    }

    /**
     * 优惠劵发放
     * 站内
     * @return bool
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function patientDistributeCoupon(): 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) {
                // 站内
                // 获取问诊订单处方数据
                $params = array();
                $params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
                $order_prescription = OrderPrescription::getOne($params);
                if (empty($order_prescription)) {
                    throw new BusinessException("加入推送队列失败:处方数据为空");
                }

                $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'] = "【优惠劵名称】已到账";
                $data['notice_content'] = "有新的优惠劵已下发至您的账户中，点击查看详情！";
                $data['link_type'] = 7;

                $message = new SendStationMessageProducer($data);
                $producer = ApplicationContext::getContainer()->get(Producer::class);
                $result = $producer->produce($message);
                if (!$result) {
                    throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
                }
            }
        } catch (\Exception $e) {
            throw new BusinessException("加入推送队列失败" . $e->getMessage());
        }

        return true;
    }

    /**
     * 优惠劵退还
     * 站内
     * @return bool
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function patientRefundCoupon(): 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) {
                // 站内
                // 获取问诊订单处方数据
                $params = array();
                $params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
                $order_prescription = OrderPrescription::getOne($params);
                if (empty($order_prescription)) {
                    throw new BusinessException("加入推送队列失败:处方数据为空");
                }

                $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'] = "【优惠劵名称】已退还";
                $data['notice_content'] = "您有优惠劵已退还至您的账户，请点击查看详情！";
                $data['link_type'] = 7;

                $message = new SendStationMessageProducer($data);
                $producer = ApplicationContext::getContainer()->get(Producer::class);
                $result = $producer->produce($message);
                if (!$result) {
                    throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
                }
            }
        } catch (\Exception $e) {
            throw new BusinessException("加入推送队列失败" . $e->getMessage());
        }

        return true;
    }

    /**
     * 优惠劵过期
     * 站内
     * @return bool
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function patientExpireCoupon(): 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) {
                // 站内
                // 获取问诊订单处方数据
                $params = array();
                $params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
                $order_prescription = OrderPrescription::getOne($params);
                if (empty($order_prescription)) {
                    throw new BusinessException("加入推送队列失败:处方数据为空");
                }

                $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'] = "【优惠劵名称】即将过期";
                $data['notice_content'] = "您有一张优惠劵即将过期，点击查看详情！";
                $data['link_type'] = 7;

                $message = new SendStationMessageProducer($data);
                $producer = ApplicationContext::getContainer()->get(Producer::class);
                $result = $producer->produce($message);
                if (!$result) {
                    throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
                }
            }
        } catch (\Exception $e) {
            throw new BusinessException("加入推送队列失败" . $e->getMessage());
        }

        return true;
    }

    /**
     * 问诊服务退款成功
     * 站内、订阅、短信
     * @param int $type 类型 1：已支付未接诊 2：已支付未成功分配医生 3：已支付未接诊患者取消订单
     * @return bool
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function refundInquirySuccess(int $type): 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) {
                // 站内
                $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'] = "肝胆小秘书";
                if ($type == 1){
                    // 已支付未接诊
                    $data['notice_brief_title'] = "您咨询的【{$inquiry_type_string}】服务，平台 已退款成功，点击查看详情。";
                    $data['notice_title'] = "您咨询的【{$inquiry_type_string}】服务，平台 已退款成功";
                    $data['notice_content'] = "因医生繁忙未及时接诊，平台会在24小时内给您退款至原账户中，带来的不便敬请谅解。";
                }elseif ($type == 2){
                    // 已支付未成功分配医生
                    $data['notice_brief_title'] = "您咨询的【{$inquiry_type_string}】服务，平台 已退款成功，点击查看详情。";
                    $data['notice_title'] = "您咨询的【{$inquiry_type_string}】服务，平台 已退款成功";
                    $data['notice_content'] = "当前服务排队人较多，暂无空闲医生为您接诊，平台会在24小时内给您退款至原账户中，带来的不便敬请谅解。";
                }elseif ($type == 2){
                    // 已支付未接诊患者取消订单
                    $data['notice_brief_title'] = "您咨询的【{$inquiry_type_string}】服务，平台 已退款成功，点击查看详情。";
                    $data['notice_title'] = "您咨询的【{$inquiry_type_string}】服务，平台 已退款成功";
                    $data['notice_content'] = "您已取消成功当前服务，平台会在24小时内给您退还至原账户中，带来的不便敬请谅解。";
                }else{
                    throw new BusinessException("加入推送队列失败:类型错误");
                }

                $data['link_type'] = 10;// 问诊订单详情

                $link_params = array();
                $link_params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
                $data['link_params'] = json_encode($link_params,JSON_UNESCAPED_UNICODE);// 跳转参数

                $message = new SendStationMessageProducer($data);
                $producer = ApplicationContext::getContainer()->get(Producer::class);
                $result = $producer->produce($message);
                if (!$result) {
                    throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
                }
            } elseif ($this->push_type == 2) {
                // 订阅
                $sub_data = array();
                $sub_data['push_user_id'] = $this->user['user_id'];
                $sub_data['wx_template_id'] = "UOMww1S30Oq7rErJrqO8wN6lNEVKRo2fgcXnb0tBwHI"; //问诊异常通知
                $sub_data['params']['page'] = "pages/orderDetail/orderDetail?order_inquiry_id={$this->order_inquiry['order_inquiry_id']}";
                $sub_data['params']['data'] = [
                    "character_string1" => $this->order_inquiry['inquiry_no'],// 订单ID
                    "name2" => (string)$user_doctor['user_name'],// 问诊医生
                    "date3" => $this->order_inquiry['created_at'],// 问诊时间
                    "thing4" => "医生未接诊退款",// 取消原因
                    "thing5" => "点击详情查看",// 提示说明
                ];

                $data = array();
                $data['sub_data'] = $sub_data;
                $data['sms_data'] = array();

                $message = new SendSubMessageProducer($data);
                $producer = ApplicationContext::getContainer()->get(Producer::class);
                $result = $producer->produce($message);
                if (!$result) {
                    throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
                }
            } elseif ($this->push_type == 3) {
                // 短信
                // 获取系统接诊配置
                $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) {
                    throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
                }
            }
        } catch (\Exception $e) {
            throw new BusinessException("加入推送队列失败" . $e->getMessage());
        }

        return true;
    }

    /**
     * 药品订单退款成功
     * 站内、订阅、短信
     * @param string $order_product_id
     * @return bool
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function refundProductSuccess(string $order_product_id): bool
    {
        try {
            // 获取药品订单数据
            $params = array();
            $params['order_product_id'] = $order_product_id;
            $order_product = OrderProduct::getOne($params);
            if (empty($order_product)){
                throw new BusinessException("加入推送队列失败:药品订单数据为空");
            }

            // 获取药品订单商品数据
            $params = array();
            $params['order_product_id'] = $order_product_id;
            $order_product_item = OrderProductItem::getList($params);
            if (empty($order_product_item)){
                throw new BusinessException("加入推送队列失败:商品订单列表数据为空");
            }

            // 获取商品数据
            $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)){
                    throw new BusinessException("加入推送队列失败:商品数据为空");
                }

                $product_name_array[] = $product['common_name'];
            }

            $product_name = implode('、',$product_name_array);

            if ($this->push_type == 1) {
                // 站内
                $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) {
                    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'] = "gQO5vhPQfdnvXtK0XnGns1XqNhQpOrXTjdl-5HWWMUw";//药品订单取消通知
                $sub_data['params']['page'] = "pages/orderDetail/orderDetail?order_inquiry_id={$this->order_inquiry['order_inquiry_id']}";
                $sub_data['params']['data'] = [
                    "character_string3" => $order_product['order_product_no'],// 订单号

                    "time5" => $order_product['cancel_time'],// 取消时间

                    "amount4" => $order_product['payment_amount_total'],// 退款金额

                    "thing1" => productCancelReasonToString($order_product['cancel_reason']),// 取消原因

                    "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) {
                    throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
                }
            } elseif ($this->push_type == 3) {
                // 短信
                // 获取系统接诊配置
                $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) {
                    throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
                }
            }
        } catch (\Exception $e) {
            throw new BusinessException("加入推送队列失败" . $e->getMessage());
        }

        return true;
    }

    /**
     * 物流信息-暂时无法开发，无物流信息表
     * 已揽收、已发货、自动收货
     * 站内
     * @param string $order_product_id
     * @return bool
     */
    public function logistics(string $order_product_id): bool
    {
        try {

        } catch (\Exception $e) {
            throw new BusinessException("加入推送队列失败" . $e->getMessage());
        }

        return true;
    }

    /**
     * 药品已发货
     * 订阅失败发送短信
     * @param string $order_product_id
     * @return bool
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function ProductDelivery(string $order_product_id): bool
    {
        try {
            // 获取药品订单数据
            $params = array();
            $params['order_product_id'] = $order_product_id;
            $order_product = OrderProduct::getOne($params);
            if (empty($order_product)){
                throw new BusinessException("加入推送队列失败:药品订单数据为空");
            }

            // 获取药品订单商品数据
            $params = array();
            $params['order_product_id'] = $order_product_id;
            $order_product_item = OrderProductItem::getList($params);
            if (empty($order_product_item)){
                throw new BusinessException("加入推送队列失败:商品订单列表数据为空");
            }

            // 获取商品数据
            $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)){
                    throw new BusinessException("加入推送队列失败:商品数据为空");
                }

                $product_name_array[] = $product['common_name'];
            }

            $product_name = implode('、',$product_name_array);

            if ($this->push_type == 2) {
                // 订阅
                $sub_data = array();
                $sub_data['push_user_id'] = $this->user['user_id'];
                $sub_data['wx_template_id'] = "YFdVxDclV1ZjhS7E4Cs0zFdshTRizERpwYdZizj_UWo"; // 药品发货通知
                $sub_data['params']['page'] = "pages/orderDetail/orderDetail?order_inquiry_id={$this->order_inquiry['order_inquiry_id']}";
                $sub_data['params']['data'] = [
                    "character_string9" => $order_product['order_product_no'],// 快递单号

                    "time7" => $order_product['delivery_time'],// 发货时间

                    "thing3" => $order_product['province'] . $order_product['city'] . $order_product['county'],// 收货地址

                    "thing6" => $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) {
                    throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
                }
            }
        } catch (\Exception $e) {
            throw new BusinessException("加入推送队列失败" . $e->getMessage());
        }

        return true;
    }

    /**
     * 药品收货-用药提醒-无法开发，
     * 订阅失败发送短信
     * @param string $order_product_id
     * @return bool
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function medicationReminder(string $order_product_id): bool
    {
        try {

        } catch (\Exception $e) {
            throw new BusinessException("加入推送队列失败" . $e->getMessage());
        }

        return true;
    }

    /**
     * 医生有新问诊
     * 站内、订阅失败发送短信
     * @return bool
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function doctorHaveNewInquiry(): 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['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'] = 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);// 跳转参数

                $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) {
                // 订阅
                $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" => "您有新的患者向您发起了（{$inquiry_type}）服务，请您尽快上线接诊；",// 提醒内容

                    "name2" => $this->order_inquiry['patient_name'],// 患者姓名

                    "thing4" => (string)$user_doctor['user_name'],// 病情描述

                    "thing6" => "24小时内未接诊，平台将自动取消问诊。",// 提示说明

                    "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) {
                    throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
                }

            }
        } catch (\Exception $e) {
            throw new BusinessException("加入推送队列失败" . $e->getMessage());
        }

        return true;
    }

    /**
     * 医生xx时间后还未接诊
     * 站内、订阅失败发送短信
     * @return bool
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    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("加入推送队列失败:问诊病例为空");
            }

            if ($this->push_type == 1) {
                // 站内
                $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'] = 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'] = $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) {
                    throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
                }
            } elseif ($this->push_type == 2) {
                // 订阅
                $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" => "您好医生，{$this->order_inquiry['patient_name']}患者的（{$inquiry_type}）服务您还未接诊；",// 提醒内容

                    "name2" => $this->order_inquiry['patient_name'],// 患者姓名

                    "thing4" => mb_substr($order_inquiry_case['disease_desc'],0,18),// 病情描述

                    "thing6" => "24小时内未接诊，平台将自动取消问诊。",// 提示说明

                    "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) {
                    throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
                }

            }
        } catch (\Exception $e) {
            throw new BusinessException("加入推送队列失败" . $e->getMessage());
        }

        return true;
    }

    /**
     * 问诊结束
     * 站内
     * 发送给医生
     * @return bool
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function finishInquiryToDoctor(): 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("加入推送队列失败:问诊病例为空");
            }

            if ($this->push_type == 1) {
                // 站内
                $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'];
                $data['link_params'] = json_encode($link_params,JSON_UNESCAPED_UNICODE);// 跳转参数

                $message = new SendStationMessageProducer($data);
                $producer = ApplicationContext::getContainer()->get(Producer::class);
                $result = $producer->produce($message);
                if (!$result) {
                    throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
                }
            }
        } catch (\Exception $e) {
            throw new BusinessException("加入推送队列失败" . $e->getMessage());
        }

        return true;
    }

    /**
     * 医生开具的处方审核通过
     * 站内、订阅失败发送短信
     * @return bool
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function prescriptionVerifySuccess(): bool
    {
        try {
            // 获取问诊订单处方数据
            $params = array();
            $params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
            $order_prescription = OrderPrescription::getOne($params);
            if (empty($order_prescription)) {
                throw new BusinessException("加入推送队列失败:处方数据为空");
            }

            if ($this->push_type == 1) {
                // 站内
                $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'] = "{$this->order_inquiry['patient_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'] = $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) {
                    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'] = "kUy70xHlr7ADo4aIHiictM4Te7MSec3E5kHsYvFQu40"; // 处方审核结果通知
                $sub_data['params']['page'] = "Pages/yishi/chufangsetup/index";
                $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'] = "医生开具的处方审核通过";
                $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) {
                    throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
                }

            }
        } catch (\Exception $e) {
            throw new BusinessException("加入推送队列失败" . $e->getMessage());
        }

        return true;
    }

    /**
     * 医生开具的处方审核未通过
     * 订阅失败发送短信
     * @return bool
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function prescriptionVerifyFail(): bool
    {
        try {
            // 获取问诊订单处方数据
            $params = array();
            $params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id'];
            $order_prescription = OrderPrescription::getOne($params);
            if (empty($order_prescription)) {
                throw new BusinessException("加入推送队列失败:处方数据为空");
            }

            if ($this->push_type == 2) {
                // 订阅
                $sub_data = array();
                $sub_data['push_user_id'] = $this->user['user_id'];
                $sub_data['wx_template_id'] = "kUy70xHlr7ADo4aIHiictM4Te7MSec3E5kHsYvFQu40"; // 处方审核结果通知
                $sub_data['params']['page'] = "Pages/yishi/chufangsetup/index";
                $sub_data['params']['data'] = [
                    "phrase1" => "药师审方不通过",// 审核结果
                    "thing2" => $order_prescription['pharmacist_fail_reason'],// 原因
                    "date3" => $order_prescription['pharmacist_verify_time'],// 审核时间
                    "thing4" => "建议您修改处方并重新为患者开具",// 提示说明
                ];

                // 短信
                $sms_data = array();
                $sms_data['template_code'] = "SMS_271905264";
                $sms_data['scene_desc'] = "医生开具的处方审核未通过";
                $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) {
                    throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
                }
            }
        } catch (\Exception $e) {
            throw new BusinessException("加入推送队列失败" . $e->getMessage());
        }

        return true;
    }

    /**
     * 医师身份通过
     * 短信
     * @return bool
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    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 (\Exception $e) {
            throw new BusinessException("加入推送队列失败" . $e->getMessage());
        }

        return true;
    }

    /**
     * 医师身份未通过
     * 短信
     * @return bool
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    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 (\Exception $e) {
            throw new BusinessException("加入推送队列失败" . $e->getMessage());
        }

        return true;
    }

    /**
     * 多点执业认证审核通过
     * 站内、订阅发送失败发送短信
     * @return bool
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    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 (\Exception $e) {
            throw new BusinessException("加入推送队列失败" . $e->getMessage());
        }

        return true;
    }

    /**
     * 多点执业认证审核未通过
     * 站内、订阅发送失败发送短信
     * @return bool
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    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 (\Exception $e) {
            throw new BusinessException("加入推送队列失败" . $e->getMessage());
        }

        return true;
    }

    /**
     * 医生简介审核通过-因缺少简介表，审核时间使用的是当前时间
     * 站内、订阅发送失败发送短信
     * @return bool
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    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 (\Exception $e) {
            throw new BusinessException("加入推送队列失败" . $e->getMessage());
        }

        return true;
    }

    /**
     * 医生简介审核未通过-因缺少简介表，审核时间使用的是当前时间，驳回理由未填写
     * 站内、订阅发送失败发送短信
     * @return bool
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    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 (\Exception $e) {
            throw new BusinessException("加入推送队列失败" . $e->getMessage());
        }

        return true;
    }

    /**
     * 医师服务费结算成功
     * 站内、短信
     * @param string $withdrawal_id
     * @return bool
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function doctorSettlementSuccess(string $withdrawal_id): bool
    {
        try {
            // 获取医生提现表数据
            $params = array();
            $params['withdrawal_id'] = $withdrawal_id;
            $doctor_withdrawal = DoctorWithdrawal::getOne($params);
            if (empty($doctor_withdrawal)){
                throw new BusinessException("加入推送队列失败:提现数据为空");
            }

            if ($this->push_type == 1) {
                // 站内
                // 计算时间
                $created_at = date('Y',strtotime($doctor_withdrawal['created_at']));
                $now_year = date('Y',time());
                if ($created_at != $now_year){
                    $created_at = date('Y',strtotime($doctor_withdrawal['created_at'])) . '年' . date('m',strtotime($doctor_withdrawal['created_at'])) . "月";
                }else{
                    $created_at = date('m',strtotime($doctor_withdrawal['created_at'])) . '月' . date('m',strtotime($doctor_withdrawal['created_at'])) . "日";
                }

                $data = array();
                $data['user_id'] = $this->user['user_id'];
                $data['notice_type'] = 2;
                $data['from_name'] = "肝胆小秘书";
                $data['notice_brief_title'] = "{$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) {
                    throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
                }
            } elseif ($this->push_type == 3) {
                // 短信
                // 获取系统接诊配置
                $data = array();
                $data['template_code'] = "SMS_271915200";
                $data['scene_desc'] = "医师服务费结算成功";
                $data['phone'] = $this->user['mobile'];
                $data['user_id'] = $this->user['user_id'];

                $template_param = array();
                $template_param['name'] = $this->user['user_name'];
                $template_param['time'] = date('Y-m-d H:i',strtotime($doctor_withdrawal['created_at']));
                $data['template_param'] = $template_param;

                $message = new SendSmsMessageProducer($data);
                $producer = ApplicationContext::getContainer()->get(Producer::class);
                $result = $producer->produce($message);
                if (!$result) {
                    throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
                }
            }
        } catch (\Exception $e) {
            throw new BusinessException("加入推送队列失败" . $e->getMessage());
        }

        return true;
    }

    /**
     * 医师服务费结算失败
     * 站内、短信
     * @param string $withdrawal_id
     * @return bool
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function doctorSettlementFail(string $withdrawal_id): bool
    {
        try {
            // 获取医生提现表数据
            $params = array();
            $params['withdrawal_id'] = $withdrawal_id;
            $doctor_withdrawal = DoctorWithdrawal::getOne($params);
            if (empty($doctor_withdrawal)){
                throw new BusinessException("加入推送队列失败:提现数据为空");
            }

            if ($this->push_type == 1) {
                // 站内
                // 计算时间
                $created_at = date('Y',strtotime($doctor_withdrawal['created_at']));
                $now_year = date('Y',time());
                if ($created_at != $now_year){
                    $created_at = date('Y',strtotime($doctor_withdrawal['created_at'])) . '年' . date('m',strtotime($doctor_withdrawal['created_at'])) . "月";
                }else{
                    $created_at = date('m',strtotime($doctor_withdrawal['created_at'])) . '月' . date('m',strtotime($doctor_withdrawal['created_at'])) . "日";
                }

                $data = array();
                $data['user_id'] = $this->user['user_id'];
                $data['notice_type'] = 2;
                $data['from_name'] = "肝胆小秘书";
                $data['notice_brief_title'] = "{$created_at}提取的服务费结算失败";
                $data['notice_title'] = "{$created_at}服务费结算失败";
                $data['notice_content'] = "{$this->user['user_name']}医生您好，您{$created_at}提取的服务费结算失败，肝胆小秘书会尽快和您取得联系，您也可以选择联系客服主动联系。";

                $data['link_type'] = 11;// 联系客服

                $data['button_type'] = 2;// 联系客服

                $link_params = array();
                $data['link_params'] = json_encode($link_params,JSON_UNESCAPED_UNICODE);// 跳转参数

                $message = new SendStationMessageProducer($data);
                $producer = ApplicationContext::getContainer()->get(Producer::class);
                $result = $producer->produce($message);
                if (!$result) {
                    throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
                }
            } elseif ($this->push_type == 3) {
                // 短信
                // 获取系统接诊配置
                $data = array();
                $data['template_code'] = "SMS_271915200";
                $data['scene_desc'] = "医师服务费结算失败";
                $data['phone'] = $this->user['mobile'];
                $data['user_id'] = $this->user['user_id'];

                $template_param = array();
                $template_param['name'] = $this->user['user_name'];
                $template_param['time'] = date('Y-m-d H:i',strtotime($doctor_withdrawal['created_at']));
                $data['template_param'] = $template_param;

                $message = new SendSmsMessageProducer($data);
                $producer = ApplicationContext::getContainer()->get(Producer::class);
                $result = $producer->produce($message);
                if (!$result) {
                    throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
                }
            }
        } catch (\Exception $e) {
            throw new BusinessException("加入推送队列失败" . $e->getMessage());
        }

        return true;
    }

    /**
     * 小程序升级通知
     * 站内
     * @param string $date 日期
     * @param string $function 功能
     * @return bool
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function DoctorSystemUpgrade(string $date,string $function): bool
    {
        try {
            if ($this->push_type == 1) {
                // 站内
                $data = array();
                $data['user_id'] = $this->user['user_id'];
                $data['notice_type'] = 2;
                $data['from_name'] = "肝胆小秘书";
                $data['notice_brief_title'] = $date . "会更新新的功能，敬请期待";
                $data['notice_title'] = "系统升级";
                $data['notice_content'] = "{$this->user['user_name']}医生，{$date}会更新{$function}功能，敬请期待；";

                $link_params = array();
                $data['link_params'] = json_encode($link_params,JSON_UNESCAPED_UNICODE);// 跳转参数

                $message = new SendStationMessageProducer($data);
                $producer = ApplicationContext::getContainer()->get(Producer::class);
                $result = $producer->produce($message);
                if (!$result) {
                    throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
                }
            }
        } catch (\Exception $e) {
            throw new BusinessException("加入推送队列失败" . $e->getMessage());
        }

        return true;
    }

    /**
     * 小程序升级通知
     * 站内
     * @param string $title 协议名称
     * @return bool
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function DoctorAgreementUpdate(string $title): bool
    {
        try {
            if ($this->push_type == 1) {
                // 站内
                $data = array();
                $data['user_id'] = $this->user['user_id'];
                $data['notice_type'] = 2;
                $data['from_name'] = "肝胆小秘书";
                $data['notice_brief_title'] = "平台对【{$title}】协议进行了更新，请注意查收";
                $data['notice_title'] = "协议更新";
                $data['notice_content'] = "{$this->user['user_name']}医生，平台对【{$title}】协议进行了更新，请注意查收";

                $link_params = array();
                $data['link_params'] = json_encode($link_params,JSON_UNESCAPED_UNICODE);// 跳转参数

                $message = new SendStationMessageProducer($data);
                $producer = ApplicationContext::getContainer()->get(Producer::class);
                $result = $producer->produce($message);
                if (!$result) {
                    throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
                }
            }
        } catch (\Exception $e) {
            throw new BusinessException("加入推送队列失败" . $e->getMessage());
        }

        return true;
    }
}