780 lines
35 KiB
PHP
780 lines
35 KiB
PHP
<?php
|
||
|
||
namespace App\Services;
|
||
|
||
use App\Constants\DoctorTitleCode;
|
||
use App\Constants\HttpEnumCode;
|
||
use App\Exception\BusinessException;
|
||
use App\Model\Hospital;
|
||
use App\Model\User;
|
||
use App\Model\UserDoctor;
|
||
use App\Model\UserPatient;
|
||
use App\Model\UserPharmacist;
|
||
use App\Utils\Log;
|
||
use Extend\TencentIm\Account;
|
||
use Extend\TencentIm\Message;
|
||
use Extend\TencentIm\Profile;
|
||
use GuzzleHttp\Exception\GuzzleException;
|
||
use Hyperf\Redis\Redis;
|
||
use Psr\Container\ContainerExceptionInterface;
|
||
use Psr\Container\NotFoundExceptionInterface;
|
||
|
||
class ImService extends BaseService
|
||
{
|
||
/**
|
||
* 检测并创建账号
|
||
* @param string $user_id
|
||
* @return bool
|
||
* @throws GuzzleException
|
||
*/
|
||
public function createAccount(string $user_id): bool
|
||
{
|
||
try {
|
||
$params = array();
|
||
$params['user_id'] = $user_id;
|
||
$user = User::getOne($params);
|
||
if (empty($user)) {
|
||
throw new BusinessException("用户数据错误");
|
||
}
|
||
|
||
$avatar = addAliyunOssWebsite($user['avatar']);
|
||
|
||
$account = new Account();
|
||
// 查询账号导入状态
|
||
$res = $account->checkAccountStatus($user['user_id']);
|
||
if (!$res) {
|
||
// 创建单个账号
|
||
$account->createAccount($user_id, $user['user_name'], $avatar);
|
||
}
|
||
|
||
// 检测用户资料
|
||
$profile = new Profile();
|
||
$result = $profile->getOneAccountPortraitList($user['user_id']);
|
||
if (!empty($result)) {
|
||
$arg = array();
|
||
|
||
// 头像
|
||
if (in_array('Tag_Profile_IM_Image', $result)) {
|
||
$arg['Tag_Profile_IM_Image'] = $avatar;
|
||
}
|
||
|
||
// 性别
|
||
if (in_array('Tag_Profile_IM_Gender', $result)) {
|
||
$arg['Tag_Profile_IM_Gender'] = sexToImSex($user['sex']);
|
||
}
|
||
|
||
if ($user['user_type'] == 2) {
|
||
$params = array();
|
||
$params['user_id'] = $user['user_id'];
|
||
$user_doctor = UserDoctor::getOne($params);
|
||
if (empty($user_doctor)) {
|
||
throw new BusinessException("医生数据错误");
|
||
}
|
||
|
||
// 获取订单医生医院
|
||
$params = array();
|
||
$params['hospital_id'] = $user_doctor['hospital_id'];
|
||
$hospital = Hospital::getOne($params);
|
||
if (empty($hospital)) {
|
||
throw new BusinessException("医生医院数据错误");
|
||
}
|
||
|
||
// 医院
|
||
if (in_array('Tag_Profile_Custom_Hname', $result)) {
|
||
$arg['Tag_Profile_Custom_Hname'] = $hospital['hospital_name'];
|
||
}
|
||
|
||
// 职称
|
||
if (in_array('Tag_Profile_Custom_Title', $result)) {
|
||
$arg['Tag_Profile_Custom_Title'] = $user_doctor['doctor_title'] ?? DoctorTitleCode::getMessage($user_doctor['doctor_title']);
|
||
}
|
||
}
|
||
|
||
if (!empty($arg)) {
|
||
$profile->setProfile($user['user_id'], $arg);
|
||
}
|
||
}
|
||
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
throw new BusinessException($e->getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 设置用户资料
|
||
* @param string $user_id
|
||
* @return bool
|
||
* @throws GuzzleException
|
||
*/
|
||
public function setUserProfile(string $user_id): bool
|
||
{
|
||
try {
|
||
$params = array();
|
||
$params['user_id'] = $user_id;
|
||
$user = User::getOne($params);
|
||
if (empty($user)) {
|
||
throw new BusinessException("用户数据错误");
|
||
}
|
||
|
||
$avatar = addAliyunOssWebsite($user['avatar']);
|
||
|
||
// 检测用户资料
|
||
$profile = new Profile();
|
||
$result = $profile->getOneAccountPortraitList($user['user_id']);
|
||
|
||
if (!empty($result)) {
|
||
$arg = array();
|
||
|
||
// 头像
|
||
if (in_array('Tag_Profile_IM_Image', $result)) {
|
||
$arg['Tag_Profile_IM_Image'] = $avatar;
|
||
}
|
||
|
||
// 性别
|
||
if (in_array('Tag_Profile_IM_Gender', $result)) {
|
||
$arg['Tag_Profile_IM_Gender'] = sexToImSex($user['sex']);
|
||
}
|
||
|
||
if ($user['user_type'] == 2) {
|
||
$params = array();
|
||
$params['user_id'] = $user['user_id'];
|
||
$user_doctor = UserDoctor::getOne($params);
|
||
if (empty($user_doctor)) {
|
||
throw new BusinessException("医生数据错误");
|
||
}
|
||
|
||
// 获取订单医生医院
|
||
$params = array();
|
||
$params['hospital_id'] = $user_doctor['hospital_id'];
|
||
$hospital = Hospital::getOne($params);
|
||
if (empty($hospital)) {
|
||
throw new BusinessException("医生医院数据错误");
|
||
}
|
||
|
||
// 医院
|
||
if (in_array('Tag_Profile_Custom_Hname', $result)) {
|
||
$arg['Tag_Profile_Custom_Hname'] = $hospital['hospital_name'];
|
||
}
|
||
|
||
// 职称
|
||
if (in_array('Tag_Profile_Custom_Title', $result)) {
|
||
$arg['Tag_Profile_Custom_Title'] = $user_doctor['doctor_title'] ?? DoctorTitleCode::getMessage($user_doctor['doctor_title']);
|
||
}
|
||
}
|
||
|
||
if (!empty($arg)) {
|
||
$profile->setProfile($user['user_id'], $arg);
|
||
}
|
||
}
|
||
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
throw new BusinessException($e->getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 验证回调签名
|
||
* @param string $request_time 签名时间戳
|
||
* @param string $sign 签名
|
||
* @return bool
|
||
*/
|
||
public function validateSign(string $request_time, string $sign): bool
|
||
{
|
||
$token = config('im.token');
|
||
if (empty($token)) {
|
||
throw new BusinessException("Im Token Config Error");
|
||
}
|
||
|
||
$sys_sign = hash("sha256", $token . $request_time);
|
||
if ($sign != $sys_sign) {
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* 添加最近联系人会话记录缓存
|
||
* @param string $doctor_id 医生id
|
||
* @param string $inquiry_type 订单类型(自定义字段 1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药)
|
||
* @param string $patient_user_id 患者用户id
|
||
* @param array $content 内容
|
||
* @return void
|
||
* @throws ContainerExceptionInterface
|
||
* @throws NotFoundExceptionInterface
|
||
*/
|
||
public function addRecentContactRecordCache(string $doctor_id, string $inquiry_type, string $patient_user_id, array $content): void
|
||
{
|
||
$redis_key = "recentContact" . $doctor_id . $inquiry_type;
|
||
|
||
$hash_key = $patient_user_id;
|
||
|
||
$redis = $this->container->get(Redis::class);
|
||
|
||
$redis->hSet($redis_key, $hash_key, json_encode($content, JSON_UNESCAPED_UNICODE));
|
||
}
|
||
|
||
/**
|
||
* 发送消息
|
||
* @param string $from_user_id 发送者id
|
||
* @param string $to_user_id 接受者id
|
||
* @param array $message_content 内容 对应 MsgBody.MsgContent
|
||
* @param string $message_type 消息类型 具体查看(https://cloud.tencent.com/document/product/269/2720)
|
||
* @param array $cloud_custom_data 自定义字段
|
||
* @return void
|
||
*/
|
||
public function sendMessage(string $from_user_id, string $to_user_id, array $message_content, string $message_type, array $cloud_custom_data): void
|
||
{
|
||
try {
|
||
if (!empty($from_user_id)) {
|
||
// 检测并创建发送者资料
|
||
$this->setUserProfile($from_user_id);
|
||
}
|
||
|
||
// 检测并创建接收者资料
|
||
$this->setUserProfile($to_user_id);
|
||
|
||
$message = new Message();
|
||
|
||
$arg = array();
|
||
if (!empty($from_user_id)) {
|
||
$arg['From_Account'] = $from_user_id; // 发送方user_id 如系统发送,无需填写
|
||
}
|
||
$arg['To_Account'] = $to_user_id; // 接收方user_id
|
||
$arg['ForbidCallbackControl'] = ['ForbidBeforeSendMsgCallback'];
|
||
$arg['SendMsgControl'] = [];
|
||
|
||
$arg['MsgBody'] = [
|
||
[
|
||
"MsgType" => $message_type,
|
||
"MsgContent" => $message_content,
|
||
]
|
||
];
|
||
|
||
$arg['CloudCustomData'] = "";
|
||
if (!empty($cloud_custom_data)) {
|
||
$arg['CloudCustomData'] = json_encode($cloud_custom_data, JSON_UNESCAPED_UNICODE);
|
||
}
|
||
|
||
// 该条消息是否需要已读回执,0为不需要,1为需要,默认为0
|
||
$arg['IsNeedReadReceipt'] = 1;
|
||
|
||
$message->sendMessage($arg);
|
||
} catch (\Exception $e) {
|
||
throw new BusinessException($e->getMessage());
|
||
} catch (GuzzleException $e) {
|
||
throw new BusinessException($e->getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 问诊已完成
|
||
* @param array|object $order_inquiry 问诊订单数据
|
||
* @param string $doctor_user_id 医生用户id
|
||
* @param string $patient_user_id 患者用户id
|
||
* @return void
|
||
*/
|
||
public function inquiryComplete(array|object $order_inquiry, string $doctor_user_id, string $patient_user_id): void
|
||
{
|
||
try {
|
||
// 发送消息
|
||
$cloud_custom_data = array();
|
||
$cloud_custom_data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||
$cloud_custom_data['is_system'] = 1;
|
||
$cloud_custom_data['inquiry_type'] = $order_inquiry['inquiry_type'];
|
||
$cloud_custom_data['message_rounds'] = 0;
|
||
$cloud_custom_data['patient_family_data']['patient_name'] = $order_inquiry['patient_name'];
|
||
$cloud_custom_data['patient_family_data']['patient_sex'] = $order_inquiry['patient_sex'];
|
||
$cloud_custom_data['patient_family_data']['patient_age'] = $order_inquiry['patient_age'];
|
||
|
||
// 消息内容 医生-患者
|
||
$message_content_data = array();
|
||
$message_content_data['message_type'] = 1;
|
||
$message_content_data['title'] = "—问诊已结束—";
|
||
$message_content_data['desc'] = "线上咨询不能代替面诊,医生建议仅供参考。";
|
||
$message_content = [
|
||
'Data' => json_encode($message_content_data, JSON_UNESCAPED_UNICODE),
|
||
];
|
||
|
||
$this->sendMessage($doctor_user_id, $patient_user_id, $message_content, "TIMCustomElem", $cloud_custom_data);
|
||
} catch (\Exception $e) {
|
||
throw new BusinessException($e->getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 等待医生接诊
|
||
* @param array|object $order_inquiry 问诊订单数据
|
||
* @param string $doctor_user_id 医生用户id
|
||
* @param string $patient_user_id 患者用户id
|
||
* @return void
|
||
*/
|
||
public function waitDoctorInquiry(array|object $order_inquiry, string $doctor_user_id, string $patient_user_id): void
|
||
{
|
||
try {
|
||
// 发送消息
|
||
$cloud_custom_data = array();
|
||
$cloud_custom_data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||
$cloud_custom_data['is_system'] = 1;
|
||
$cloud_custom_data['inquiry_type'] = $order_inquiry['inquiry_type'];
|
||
$cloud_custom_data['message_rounds'] = 0;
|
||
$cloud_custom_data['patient_family_data']['patient_name'] = $order_inquiry['patient_name'];
|
||
$cloud_custom_data['patient_family_data']['patient_sex'] = $order_inquiry['patient_sex'];
|
||
$cloud_custom_data['patient_family_data']['patient_age'] = $order_inquiry['patient_age'];
|
||
|
||
// 消息内容 医生-患者
|
||
$message_content_data = array();
|
||
$message_content_data['message_type'] = 1;
|
||
$message_content_data['title'] = "—等待医生接诊—";
|
||
if ($order_inquiry['inquiry_type'] == 1) {
|
||
$message_content_data['desc'] = "温馨提示:当前服务为专家问诊,医师接诊后可以在24小时内和医生沟通20个回合。医生繁忙请耐心等待,医生接诊会后第一时间短信通知您。";
|
||
} elseif ($order_inquiry['inquiry_type'] == 2) {
|
||
$message_content_data['desc'] = "温馨提示:请耐心等待,您可继续补充病情,便于医生接诊后更快确认病情。";
|
||
} elseif ($order_inquiry['inquiry_type'] == 3) {
|
||
$message_content_data['desc'] = "温馨提示:当前服务为公益问诊,医师接诊后可以在24小时内和医生沟通10个回合。医生繁忙请耐心等待,医生接诊会后第一时间短信通知您。";
|
||
} else {
|
||
$message_content_data['desc'] = "温馨提示:请耐心等待,您可继续补充病情,便于医生接诊后更快确认病情。";
|
||
}
|
||
$message_content = [
|
||
'Data' => json_encode($message_content_data, JSON_UNESCAPED_UNICODE),
|
||
];
|
||
|
||
$this->sendMessage($doctor_user_id, $patient_user_id, $message_content, "TIMCustomElem", $cloud_custom_data);
|
||
} catch (\Exception $e) {
|
||
throw new BusinessException($e->getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 医生接诊
|
||
* @param array|object $order_inquiry 问诊订单数据
|
||
* @param string $doctor_user_id 医生用户id
|
||
* @param string $patient_user_id 患者用户id
|
||
* @return void
|
||
*/
|
||
public function doctorInquiry(array|object $order_inquiry, string $doctor_user_id, string $patient_user_id): void
|
||
{
|
||
try {
|
||
// 发送消息
|
||
$cloud_custom_data = array();
|
||
$cloud_custom_data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||
$cloud_custom_data['is_system'] = 1;
|
||
$cloud_custom_data['inquiry_type'] = $order_inquiry['inquiry_type'];
|
||
$cloud_custom_data['message_rounds'] = 0;
|
||
$cloud_custom_data['patient_family_data']['patient_name'] = $order_inquiry['patient_name'];
|
||
$cloud_custom_data['patient_family_data']['patient_sex'] = $order_inquiry['patient_sex'];
|
||
$cloud_custom_data['patient_family_data']['patient_age'] = $order_inquiry['patient_age'];
|
||
|
||
// 消息内容 医生-患者
|
||
$message_content_data = array();
|
||
$message_content_data['message_type'] = 1;
|
||
|
||
if ($order_inquiry['inquiry_type'] == 1) {
|
||
$message_content_data['title'] = "—问诊已开始,本次问诊可持续24小时—";
|
||
$message_content_data['desc'] = "医生已接诊,为提高沟通效率,您可一次性如实补充病情(具体症状,患病时长,用药情况及想咨询的问题等)。线上咨询不能代替面诊,医生建议仅供参考。";
|
||
} elseif ($order_inquiry['inquiry_type'] == 2) {
|
||
$message_content_data['title'] = "—问诊已开始,本次问诊可持续60分钟—";
|
||
$message_content_data['desc'] = "医生已接诊,为提高沟通效率,您可一次性如实补充病情(具体症状,患病时长,就医用药情况及想咨询的问题等)。线上咨询不能代替面诊,医生建议仅供参考。";
|
||
} elseif ($order_inquiry['inquiry_type'] == 3) {
|
||
$message_content_data['title'] = "—问诊已开始,本次问诊可持续24小时—";
|
||
$message_content_data['desc'] = "医生已接诊,为提高沟通效率,您可一次性如实补充病情(具体症状,患病时长,就医用药情况及想咨询的问题等)。线上咨询不能代替面诊,医生建议仅供参考。";
|
||
} elseif ($order_inquiry['inquiry_type'] == 4) {
|
||
$message_content_data['title'] = "—问诊已开始,本次问诊可持续30分钟—";
|
||
$message_content_data['desc'] = "医生已接诊,为提高沟通效率,您可一次性如实补充病情(具体症状,患病时长,就医用药情况及想咨询的问题等)。线上咨询不能代替面诊,医生建议仅供参考。";
|
||
}
|
||
$message_content = [
|
||
'Data' => json_encode($message_content_data, JSON_UNESCAPED_UNICODE),
|
||
];
|
||
|
||
$this->sendMessage($doctor_user_id, $patient_user_id, $message_content, "TIMCustomElem", $cloud_custom_data);
|
||
} catch (\Exception $e) {
|
||
throw new BusinessException($e->getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 医生超时未接诊
|
||
* @param array|object $order_inquiry
|
||
* @param string $doctor_user_id
|
||
* @param string $patient_user_id
|
||
* @return void
|
||
*/
|
||
public function doctorUnInquiry(array|object $order_inquiry, string $doctor_user_id, string $patient_user_id): void
|
||
{
|
||
try {
|
||
// 发送消息
|
||
$cloud_custom_data = array();
|
||
$cloud_custom_data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||
$cloud_custom_data['is_system'] = 1;
|
||
$cloud_custom_data['inquiry_type'] = $order_inquiry['inquiry_type'];
|
||
$cloud_custom_data['message_rounds'] = 0;
|
||
$cloud_custom_data['patient_family_data']['patient_name'] = $order_inquiry['patient_name'];
|
||
$cloud_custom_data['patient_family_data']['patient_sex'] = $order_inquiry['patient_sex'];
|
||
$cloud_custom_data['patient_family_data']['patient_age'] = $order_inquiry['patient_age'];
|
||
|
||
// 消息内容 医生-患者
|
||
$message_content_data = array();
|
||
$message_content_data['message_type'] = 1;
|
||
$message_content_data['title'] = "—医生未接诊—";
|
||
$message_content_data['desc'] = "医生因工作繁忙未能及时接诊,请您谅解。所支付金额会在24小时内原路退回,再次感谢您的支持";
|
||
|
||
$message_content = [
|
||
'Data' => json_encode($message_content_data, JSON_UNESCAPED_UNICODE),
|
||
];
|
||
|
||
$this->sendMessage($doctor_user_id, $patient_user_id, $message_content, "TIMCustomElem", $cloud_custom_data);
|
||
} catch (\Exception $e) {
|
||
throw new BusinessException($e->getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 处方已开具
|
||
* @param array|object $order_inquiry
|
||
* @param string $doctor_user_id
|
||
* @param string $patient_user_id
|
||
* @param string $product_name
|
||
* @param string $order_prescription_id
|
||
* @param string|int $message_type 6/7
|
||
* @return void
|
||
*/
|
||
public function prescriptionIssued(array|object $order_inquiry, string $doctor_user_id, string $patient_user_id, string $product_name, string $order_prescription_id, string|int $message_type): void
|
||
{
|
||
try {
|
||
// 发送消息
|
||
$cloud_custom_data = array();
|
||
$cloud_custom_data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||
$cloud_custom_data['is_system'] = 1;
|
||
$cloud_custom_data['inquiry_type'] = $order_inquiry['inquiry_type'];
|
||
$cloud_custom_data['message_rounds'] = 0;
|
||
$cloud_custom_data['patient_family_data']['patient_name'] = $order_inquiry['patient_name'];
|
||
$cloud_custom_data['patient_family_data']['patient_sex'] = $order_inquiry['patient_sex'];
|
||
$cloud_custom_data['patient_family_data']['patient_age'] = $order_inquiry['patient_age'];
|
||
|
||
// 消息内容
|
||
$message_content_data = array();
|
||
$message_content_data['message_type'] = $message_type;
|
||
$message_content_data['title'] = "处方已开具";
|
||
$message_content_data['desc'] = "";
|
||
$message_content_data['data']['order_inquiry_id'] = (string)$order_inquiry['order_inquiry_id'];
|
||
$message_content_data['data']['order_prescription_id'] = $order_prescription_id;
|
||
$message_content_data['data']['product_name'] = $product_name ?? "药品";
|
||
$message_content_data['data']['pharmacist_verify_time'] = date('Y-m-d H:i:s', time());;
|
||
$message_content = [
|
||
'Data' => json_encode($message_content_data, JSON_UNESCAPED_UNICODE),
|
||
];
|
||
|
||
$this->sendMessage($doctor_user_id, $patient_user_id, $message_content, "TIMCustomElem", $cloud_custom_data);
|
||
|
||
} catch (\Exception $e) {
|
||
throw new BusinessException($e->getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 问诊退款
|
||
* @param array|object $order_inquiry 问诊订单数据
|
||
* @param string $doctor_user_id 医生用户id
|
||
* @param string $patient_user_id 患者用户id
|
||
* @return void
|
||
*/
|
||
public function inquiryRefund(array|object $order_inquiry, string $doctor_user_id, string $patient_user_id): void
|
||
{
|
||
try {
|
||
// 发送消息
|
||
$cloud_custom_data = array();
|
||
$cloud_custom_data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||
$cloud_custom_data['is_system'] = 1;
|
||
$cloud_custom_data['inquiry_type'] = $order_inquiry['inquiry_type'];
|
||
$cloud_custom_data['message_rounds'] = 0;
|
||
$cloud_custom_data['patient_family_data']['patient_name'] = $order_inquiry['patient_name'];
|
||
$cloud_custom_data['patient_family_data']['patient_sex'] = $order_inquiry['patient_sex'];
|
||
$cloud_custom_data['patient_family_data']['patient_age'] = $order_inquiry['patient_age'];
|
||
|
||
// 消息内容 医生-患者
|
||
$message_content_data = array();
|
||
$message_content_data['message_type'] = 1;
|
||
$message_content_data['title'] = "—问诊退款—";
|
||
$message_content_data['desc'] = "平台已自动发起退款,请注意查看账户信息。";
|
||
|
||
$message_content = [
|
||
'Data' => json_encode($message_content_data, JSON_UNESCAPED_UNICODE),
|
||
];
|
||
|
||
$this->sendMessage($doctor_user_id, $patient_user_id, $message_content, "TIMCustomElem", $cloud_custom_data);
|
||
} catch (\Exception $e) {
|
||
throw new BusinessException($e->getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 问诊结束评价通知
|
||
* @param array|object $order_inquiry
|
||
* @param string $doctor_user_id
|
||
* @param string $patient_user_id
|
||
* @return void
|
||
*/
|
||
public function inquiryEndEvaluation(array|object $order_inquiry, string $doctor_user_id, string $patient_user_id): void
|
||
{
|
||
// 发送消息
|
||
$cloud_custom_data = array();
|
||
$cloud_custom_data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||
$cloud_custom_data['is_system'] = 1;
|
||
$cloud_custom_data['inquiry_type'] = $order_inquiry['inquiry_type'];
|
||
$cloud_custom_data['message_rounds'] = 0;
|
||
$cloud_custom_data['patient_family_data']['patient_name'] = $order_inquiry['patient_name'];
|
||
$cloud_custom_data['patient_family_data']['patient_sex'] = $order_inquiry['patient_sex'];
|
||
$cloud_custom_data['patient_family_data']['patient_age'] = $order_inquiry['patient_age'];
|
||
|
||
// 消息内容 - 患者-医生
|
||
$message_content_data = array();
|
||
$message_content_data['message_type'] = 2; // 订单结束评价弹出
|
||
// $message_content_data['title'] = "评价";
|
||
$message_content_data['desc'] = "";
|
||
$message_content_data['data']['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||
|
||
$message_content = [
|
||
'Data' => json_encode($message_content_data, JSON_UNESCAPED_UNICODE),
|
||
];
|
||
|
||
$this->sendMessage($doctor_user_id, $patient_user_id, $message_content, "TIMCustomElem", $cloud_custom_data);
|
||
|
||
}
|
||
|
||
/**
|
||
* 药师审核中
|
||
* @param array|object $order_inquiry
|
||
* @param string $order_prescription_id
|
||
* @param string $product_name
|
||
* @param string $doctor_user_id
|
||
* @param string $patient_user_id
|
||
* @return void
|
||
*/
|
||
public function pharmacistVerify(array|object $order_inquiry, string $order_prescription_id, string $product_name, string $doctor_user_id, string $patient_user_id): void
|
||
{
|
||
try {
|
||
// 发送消息
|
||
$cloud_custom_data = array();
|
||
$cloud_custom_data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||
$cloud_custom_data['is_system'] = 1;
|
||
$cloud_custom_data['inquiry_type'] = $order_inquiry['inquiry_type'];
|
||
$cloud_custom_data['message_rounds'] = 0;
|
||
$cloud_custom_data['patient_family_data']['patient_name'] = $order_inquiry['patient_name'];
|
||
$cloud_custom_data['patient_family_data']['patient_sex'] = $order_inquiry['patient_sex'];
|
||
$cloud_custom_data['patient_family_data']['patient_age'] = $order_inquiry['patient_age'];
|
||
|
||
// 消息内容 医生-患者
|
||
$message_content_data = array();
|
||
$message_content_data['message_type'] = 6;
|
||
$message_content_data['title'] = "药师审核中";
|
||
$message_content_data['desc'] = "";
|
||
$message_content_data['data']['order_inquiry_id'] = (string)$order_inquiry['order_inquiry_id'];
|
||
$message_content_data['data']['order_prescription_id'] = $order_prescription_id;
|
||
$message_content_data['data']['product_name'] = $product_name ?: "药品";
|
||
$message_content_data['data']['pharmacist_verify_time'] = date('Y-m-d H:i:s', time());;
|
||
|
||
$message_content = [
|
||
'Data' => json_encode($message_content_data, JSON_UNESCAPED_UNICODE),
|
||
];
|
||
|
||
$this->sendMessage($doctor_user_id, $patient_user_id, $message_content, "TIMCustomElem", $cloud_custom_data);
|
||
} catch (\Exception $e) {
|
||
throw new BusinessException($e->getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 问诊已结束
|
||
* @param array|object $order_inquiry 问诊订单数据
|
||
* @param string $doctor_user_id 医生用户id
|
||
* @param string $patient_user_id 患者用户id
|
||
* @return void
|
||
*/
|
||
public function inquiryFinish(array|object $order_inquiry, string $doctor_user_id, string $patient_user_id): void
|
||
{
|
||
try {
|
||
// 发送消息
|
||
$cloud_custom_data = array();
|
||
$cloud_custom_data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||
$cloud_custom_data['is_system'] = 1;
|
||
$cloud_custom_data['inquiry_type'] = $order_inquiry['inquiry_type'];
|
||
$cloud_custom_data['message_rounds'] = 0;
|
||
$cloud_custom_data['patient_family_data']['patient_name'] = $order_inquiry['patient_name'];
|
||
$cloud_custom_data['patient_family_data']['patient_sex'] = $order_inquiry['patient_sex'];
|
||
$cloud_custom_data['patient_family_data']['patient_age'] = $order_inquiry['patient_age'];
|
||
|
||
// 消息内容 医生-患者
|
||
$message_content_data = array();
|
||
$message_content_data['message_type'] = 1;
|
||
$message_content_data['title'] = "—问诊已结束—";
|
||
$message_content_data['desc'] = "本次问诊服务已正式结束,祝您早日康复,再次感谢您的支持。";
|
||
$message_content = [
|
||
'Data' => json_encode($message_content_data, JSON_UNESCAPED_UNICODE),
|
||
];
|
||
|
||
$this->sendMessage($doctor_user_id, $patient_user_id, $message_content, "TIMCustomElem", $cloud_custom_data);
|
||
} catch (\Exception $e) {
|
||
throw new BusinessException($e->getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 横幅通知-医生有新问诊
|
||
* @param array|object $order_inquiry
|
||
* @param string $doctor_user_id 用户id
|
||
* @return void
|
||
*/
|
||
public function bannerNoticeNewInquiry(array|object $order_inquiry, string $doctor_user_id): void
|
||
{
|
||
try {
|
||
// 发送消息
|
||
$cloud_custom_data = array();
|
||
$cloud_custom_data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||
$cloud_custom_data['is_system'] = 1;
|
||
$cloud_custom_data['inquiry_type'] = $order_inquiry['inquiry_type'];
|
||
$cloud_custom_data['message_rounds'] = 0;
|
||
$cloud_custom_data['patient_family_data']['patient_name'] = $order_inquiry['patient_name'];
|
||
$cloud_custom_data['patient_family_data']['patient_sex'] = $order_inquiry['patient_sex'];
|
||
$cloud_custom_data['patient_family_data']['patient_age'] = $order_inquiry['patient_age'];
|
||
|
||
if ($order_inquiry['inquiry_type'] == 1 || $order_inquiry['inquiry_type'] == 3) {
|
||
// 专家、公益
|
||
$desc = "24小时内未接诊,平台将自动取消问诊";
|
||
}else{
|
||
// 快速、购药
|
||
$desc = "5分钟内未接诊,平台将自动取消问诊";
|
||
}
|
||
|
||
// 消息内容
|
||
$message_content_data = array();
|
||
$message_content_data['message_type'] = 8;
|
||
$message_content_data['title'] = "您有一个新的问诊服务等待接诊";
|
||
$message_content_data['desc'] = $desc;
|
||
$message_content_data['data']['message_path'] = "/Pages/yishi/wenzhen_v2/wenzhen";
|
||
$message_content = [
|
||
'Data' => json_encode($message_content_data, JSON_UNESCAPED_UNICODE),
|
||
];
|
||
|
||
$this->sendMessage("", $doctor_user_id, $message_content, "TIMCustomElem", $cloud_custom_data);
|
||
} catch (\Exception $e) {
|
||
throw new BusinessException($e->getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 糖组检测报告
|
||
* @param array|object $order_detection 检测订单数据
|
||
* @param string $doctor_user_id 医生user_id
|
||
* @param string $patient_user_id 患者user_id
|
||
* @param string $disease_class_names 疾病数据
|
||
* @param string $detection_project_name
|
||
* @return void
|
||
*/
|
||
public function detectionTestReport(array|object $order_detection,string $doctor_user_id, string $patient_user_id,string $disease_class_names,string $detection_project_name): void
|
||
{
|
||
try {
|
||
// 发送消息
|
||
$cloud_custom_data = array();
|
||
$cloud_custom_data['order_inquiry_id'] = (string)$order_detection['order_inquiry_id'];
|
||
$cloud_custom_data['is_system'] = 1;
|
||
$cloud_custom_data['inquiry_type'] = 5; // 订单类型(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药 5:检测)
|
||
$cloud_custom_data['message_rounds'] = 0;
|
||
$cloud_custom_data['order_no'] = $order_detection['detection_no'];
|
||
$cloud_custom_data['patient_family_data']['patient_name'] = $order_detection['patient_name'];
|
||
$cloud_custom_data['patient_family_data']['patient_sex'] = $order_detection['patient_sex'];
|
||
$cloud_custom_data['patient_family_data']['patient_age'] = $order_detection['patient_age'];
|
||
|
||
// 消息内容
|
||
$message_content_data = array();
|
||
$message_content_data['message_type'] = 10;
|
||
$message_content_data['title'] = $detection_project_name;
|
||
$message_content_data['desc'] = "";
|
||
$message_content_data['data']['order_no'] = (string)$order_detection['detection_no'];
|
||
$message_content_data['data']['disease_class_names'] = $disease_class_names;
|
||
$message_content_data['data']['message_path'] = "/pages/checkOrderDetail/checkOrderDetail?order_detection_id=" . $order_detection['detection_no']; // 跳转地址(小程序内页)
|
||
$message_content = [
|
||
'Data' => json_encode($message_content_data, JSON_UNESCAPED_UNICODE),
|
||
];
|
||
|
||
$this->sendMessage($patient_user_id,$doctor_user_id, $message_content, "TIMCustomElem", $cloud_custom_data);
|
||
|
||
} catch (\Throwable $e) {
|
||
throw new BusinessException($e->getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 糖组检测报告-文字
|
||
* @param array|object $order_detection
|
||
* @param string $doctor_name 医生名称
|
||
* @param string $detection_project_name 检测项目名称
|
||
* @param string $doctor_user_id 医生user_id
|
||
* @param string $patient_user_id 患者user_id
|
||
* @return void
|
||
*/
|
||
public function detectionTestReportStr(array|object $order_detection,string $doctor_name,string $detection_project_name,string $doctor_user_id, string $patient_user_id): void
|
||
{
|
||
try {
|
||
// 消息内容
|
||
$cloud_custom_data = array();
|
||
$cloud_custom_data['order_inquiry_id'] = (string)$order_detection['order_inquiry_id'];
|
||
$cloud_custom_data['is_system'] = 1;
|
||
$cloud_custom_data['inquiry_type'] = 5; // 订单类型(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药 5:检测)
|
||
$cloud_custom_data['message_rounds'] = 0;
|
||
$cloud_custom_data['order_no'] = $order_detection['detection_no'];
|
||
$cloud_custom_data['patient_family_data']['patient_name'] = $order_detection['patient_name'];
|
||
$cloud_custom_data['patient_family_data']['patient_sex'] = $order_detection['patient_sex'];
|
||
$cloud_custom_data['patient_family_data']['patient_age'] = $order_detection['patient_age'];
|
||
|
||
$message_content = [
|
||
'Text' => $doctor_name . "医生您好,您给我开具的【" . $detection_project_name . "】检测项目报告已经出来啦,请您抽空查看报告并做一下解读,谢谢。",
|
||
];
|
||
|
||
$this->sendMessage($patient_user_id,$doctor_user_id, $message_content, "TIMTextElem", $cloud_custom_data);
|
||
|
||
} catch (\Throwable $e) {
|
||
throw new BusinessException($e->getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 患者病例
|
||
* @param array|object $order_inquiry
|
||
* @param string $doctor_user_id
|
||
* @param string $disease_desc
|
||
* @return void
|
||
*/
|
||
public function patientCase(array|object $order_inquiry, string $doctor_user_id,string|null $disease_desc): void
|
||
{
|
||
try {
|
||
// 发送消息
|
||
$cloud_custom_data = array();
|
||
$cloud_custom_data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||
$cloud_custom_data['is_system'] = 1;
|
||
$cloud_custom_data['inquiry_type'] = $order_inquiry['inquiry_type'];
|
||
$cloud_custom_data['message_rounds'] = 0;
|
||
$cloud_custom_data['patient_family_data']['patient_name'] = $order_inquiry['patient_name'];
|
||
$cloud_custom_data['patient_family_data']['patient_sex'] = $order_inquiry['patient_sex'];
|
||
$cloud_custom_data['patient_family_data']['patient_age'] = $order_inquiry['patient_age'];
|
||
|
||
// 消息内容
|
||
$message_content_data = array();
|
||
$message_content_data['message_type'] = 11;
|
||
$message_content_data['title'] = "患者信息";
|
||
$message_content_data['desc'] = "";
|
||
$message_content_data['data']['order_no'] = $order_inquiry['inquiry_no'];
|
||
$message_content_data['data']['disease_desc'] = $disease_desc ?: "";
|
||
$message_content_data['data']['message_path'] = "/Pages/yishi/case/index?order_inquiry_id=" . $order_inquiry['order_inquiry_id']; // 跳转地址(小程序内页)
|
||
$message_content = [
|
||
'Data' => json_encode($message_content_data, JSON_UNESCAPED_UNICODE),
|
||
];
|
||
|
||
$this->sendMessage($doctor_user_id, $order_inquiry['user_id'], $message_content, "TIMCustomElem", $cloud_custom_data);
|
||
|
||
} catch (\Throwable $e) {
|
||
throw new BusinessException($e->getMessage());
|
||
}
|
||
}
|
||
} |