1
This commit is contained in:
parent
e1a6606169
commit
e847874ecd
@ -4,7 +4,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Amqp\Consumer;
|
||||
|
||||
use App\Model\LogMessagePush;
|
||||
use App\Model\MessageNotice;
|
||||
use App\Model\OrderInquiry;
|
||||
use App\Model\User;
|
||||
use App\Services\ImService;
|
||||
use App\Utils\Log;
|
||||
use Hyperf\Amqp\Result;
|
||||
@ -22,18 +25,34 @@ class SendStationMessageConsumer extends ConsumerMessage
|
||||
{
|
||||
Log::getInstance()->info("开始执行 站内消息推送 队列:" . json_encode($data, JSON_UNESCAPED_UNICODE));
|
||||
|
||||
// 验证参数
|
||||
if (!isset($data['notice_id'])){
|
||||
Log::getInstance()->info("站内消息推送失败:参数错误");
|
||||
// 验证推送参数
|
||||
$res = $this->checkPushParams($data);
|
||||
if (!$res){
|
||||
Log::getInstance()->error("站内消息推送失败:入参错误");
|
||||
return Result::DROP;
|
||||
}
|
||||
|
||||
// 获取推送信息数据
|
||||
// 验证用户信息
|
||||
$params = array();
|
||||
$params['notice_id'] = $data['notice_id'];
|
||||
$message_notice = MessageNotice::getOne($params);
|
||||
if (empty($message_notice)){
|
||||
Log::getInstance()->info("站内消息推送失败:无推送表数据");
|
||||
$params['user_id'] = $data['user_id'];
|
||||
$user = User::getOne($params);
|
||||
if(empty($user)){
|
||||
Log::getInstance()->error("站内消息推送失败:推送用户信息错误");
|
||||
return Result::DROP;
|
||||
}
|
||||
|
||||
if ($data['notice_type'] == 1){
|
||||
// 医生服务通知
|
||||
$message_type = 3;
|
||||
}elseif ($data['notice_type'] == 2){
|
||||
// 医生系统公告
|
||||
$message_type = 4;
|
||||
}elseif ($data['notice_type'] == 3){
|
||||
// 患者系统消息
|
||||
$message_type = 5;
|
||||
}else{
|
||||
Log::getInstance()->error("站内消息推送失败:消息类型错误");
|
||||
$this->saveErrorPushLog($user['user_type'],$data,"消息类型错误");
|
||||
return Result::DROP;
|
||||
}
|
||||
|
||||
@ -46,26 +65,149 @@ class SendStationMessageConsumer extends ConsumerMessage
|
||||
$cloud_custom_data['order_inquiry_id'] = "";
|
||||
$cloud_custom_data['is_system'] = 1;
|
||||
$cloud_custom_data['inquiry_type'] = "";
|
||||
$cloud_custom_data['message_rounds'] = "";
|
||||
$cloud_custom_data['message_rounds'] = 0;
|
||||
|
||||
// 消息内容
|
||||
$message_content_data = array();
|
||||
$message_content_data['message_type'] = 1;
|
||||
$message_content_data['content'] = "--等待医生接诊--";
|
||||
$message_content_data['desc'] = "温馨提示:您可继续补充问诊内容,便于更快确认病情,医生均在临床一线工作,还请耐心等待,医生接诊会第一时间短信通知您。";
|
||||
$message_content_data['message_type'] = $message_type;
|
||||
$message_content_data['content'] = $data['notice_title'] ?: "消息推送";
|
||||
$message_content_data['desc'] = $data['notice_content'] ?? "";
|
||||
$message_content = [
|
||||
'Data' => json_encode($message_content_data,JSON_UNESCAPED_UNICODE),
|
||||
];
|
||||
|
||||
$ImService->sendMessage("", $user['user_id'], $message_content, "TIMCustomElem", $cloud_custom_data);
|
||||
|
||||
// 新增通知消息表
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Log::getInstance()->info("站内消息推送成功");
|
||||
$this->saveSuccessPushLog($user['user_type'],$data['sub_data']);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::getInstance()->error("站内消息推送执行失败:" . $e->getMessage());
|
||||
|
||||
$this->saveErrorPushLog($user['user_type'],$data,$e->getMessage());
|
||||
}
|
||||
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证推送参数
|
||||
* @param $push_data
|
||||
* @return bool
|
||||
*/
|
||||
private function checkPushParams($push_data): bool
|
||||
{
|
||||
// 用户id(接受者)
|
||||
if (!isset($push_data['user_id'])){
|
||||
return false;
|
||||
}
|
||||
|
||||
// 消息类型(1:医生服务通知 2:医生系统公告 3:患者系统消息)
|
||||
if (!isset($push_data['notice_type'])){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// 患者系统消息存在
|
||||
if ($push_data['notice_type'] == 3){
|
||||
// 系统消息类型(患者端系统消息存在 1:服务消息 2:福利消息 3:退款消息 4:物流消息)
|
||||
if (!isset($push_data['notice_system_type'])){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 医生服务通知存在
|
||||
if ($push_data['notice_type'] == 1){
|
||||
// 问诊类型(医生端服务通知存在 1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药)
|
||||
if (!isset($push_data['notice_system_type'])){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Log::getInstance()->info("站内消息推送成功");
|
||||
return Result::ACK;
|
||||
// 消息标题
|
||||
if (!isset($push_data['notice_title'])){
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录成功日志
|
||||
* @param string|int $user_type 用户类型
|
||||
* @param array $push_data 需发送的站内消息数据
|
||||
* @return void
|
||||
*/
|
||||
private function saveSuccessPushLog(string|int $user_type,array $push_data): void
|
||||
{
|
||||
$data = array();
|
||||
$data['to_user_id'] = $push_data['user_id'];
|
||||
$data['user_type'] = $user_type;
|
||||
$data['type'] = 1;
|
||||
$data['status'] = 1;
|
||||
$data['content'] = json_encode($push_data,JSON_UNESCAPED_UNICODE);
|
||||
$log_message_push = LogMessagePush::addLogMessagePush($data);
|
||||
if (empty($log_message_push)){
|
||||
Log::getInstance()->error("站内消息推送成功,增加推送日志失败:" . json_encode($data,JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录成功日志
|
||||
* @param string|int $user_type 用户类型
|
||||
* @param array $push_data 需发送的站内消息数据
|
||||
* @param string $fail_reason 失败原因
|
||||
* @return void
|
||||
*/
|
||||
private function saveErrorPushLog(string|int $user_type,array $push_data,string $fail_reason): void
|
||||
{
|
||||
$data = array();
|
||||
$data['to_user_id'] = $push_data['user_id'];
|
||||
$data['user_type'] = $user_type;
|
||||
$data['type'] = 1;
|
||||
$data['status'] = 2;
|
||||
$data['fail_reason'] = $fail_reason ?: "";
|
||||
$data['content'] = json_encode($push_data,JSON_UNESCAPED_UNICODE);
|
||||
$log_message_push = LogMessagePush::addLogMessagePush($data);
|
||||
if (empty($log_message_push)){
|
||||
Log::getInstance()->error("站内消息推送成功,增加推送日志失败:" . json_encode($data,JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
// private function saveMessageNotice(){
|
||||
// $notice_data = array();
|
||||
// $notice_data['user_id'] = $user['user_id'];
|
||||
// $notice_data['user_type'] = $user['user_type'];
|
||||
// $notice_data['notice_type'] = $data['notice_type'];
|
||||
// if (isset($data['notice_system_type'])){
|
||||
// $notice_data['notice_system_type'] = $data['notice_system_type'] ;
|
||||
// }
|
||||
//
|
||||
// $notice_data['read_status'] = 0;
|
||||
//
|
||||
// if (isset($data['inquiry_type'])){
|
||||
// $notice_data['inquiry_type'] = $data['inquiry_type'] ;
|
||||
// }
|
||||
//
|
||||
// if (isset($data['from_name'])){
|
||||
// $notice_data['from_name'] = $data['from_name'] ;
|
||||
// }
|
||||
//
|
||||
// $notice_data['notice_title'] = $data['notice_title'] ;
|
||||
// $notice_data['notice_send_time'] = date('Y-m-d H:i:s',time());
|
||||
//
|
||||
// if (isset($data['notice_content'])){
|
||||
// $notice_data['notice_content'] = $data['notice_content'] ;
|
||||
// }
|
||||
//
|
||||
// if (isset($data['notice_content'])){
|
||||
// $notice_data['notice_content'] = $data['notice_content'] ;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@ -175,7 +175,6 @@ class SendSubMessageConsumer extends ConsumerMessage
|
||||
$data['user_type'] = $user_type;
|
||||
$data['type'] = 2;
|
||||
$data['status'] = 1;
|
||||
$data['send_reason'] = $sub_data['send_reason'];
|
||||
$data['content'] = json_encode($sub_data['params'],JSON_UNESCAPED_UNICODE);
|
||||
$log_message_push = LogMessagePush::addLogMessagePush($data);
|
||||
if (empty($log_message_push)){
|
||||
@ -198,7 +197,6 @@ class SendSubMessageConsumer extends ConsumerMessage
|
||||
$data['type'] = 2;
|
||||
$data['status'] = 2;
|
||||
$data['fail_reason'] = $fail_reason ?: "";
|
||||
$data['send_reason'] = $sub_data['send_reason'];
|
||||
$data['content'] = json_encode($sub_data['params'],JSON_UNESCAPED_UNICODE);
|
||||
$log_message_push = LogMessagePush::addLogMessagePush($data);
|
||||
if (empty($log_message_push)){
|
||||
|
||||
@ -13,7 +13,18 @@ class SendStationMessageProducer extends ProducerMessage
|
||||
/**
|
||||
* @param $data
|
||||
* [
|
||||
* "notice_id":"通知消息表主键id"
|
||||
* "user_id":"用户id(接受者)",
|
||||
* "notice_type":"消息类型(1:医生服务通知 2:医生系统公告 3:患者系统消息)",
|
||||
* "notice_system_type":"系统消息类型(患者端系统消息存在 1:服务消息 2:福利消息 3:退款消息 4:物流消息)",
|
||||
* "inquiry_type:"问诊类型(医生端服务通知存在 1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药)",
|
||||
* "from_name:"发送人姓名",
|
||||
* "notice_title:"消息标题",
|
||||
* "notice_content:"内容",
|
||||
* "button_type:"按钮类型(1:我的账户 2:联系客服 3:查看协议 4:订单详情 5:查看处方 )",
|
||||
* "link_type:"跳转页面类型(1:聊天详情页 2:问诊结束列表页 3:问诊消息列表页 4:我的名片 5:我的简介 6:我的账户 7:我的福利 8:药品订单详情页 9:物流详情 10:问诊订单详情 11:联系客服 12:协议详情 13:处方详情)",
|
||||
* "link_params:"跳转参数(json)",
|
||||
* "show_type:"展示类型(1:医生数据)",
|
||||
* "show_params:"展示数据(json)",
|
||||
* ]
|
||||
*/
|
||||
public function __construct($data)
|
||||
|
||||
@ -20,7 +20,6 @@ class SendSubMessageProducer extends ProducerMessage
|
||||
* "sub_data" => [
|
||||
* "push_user_id" // 用户id(被推送者)
|
||||
* "template_title" // 推送的模版名称
|
||||
* "send_reason" // 发送原因
|
||||
* "params" => [ // 推送所需的参数
|
||||
* "page" // 跳转页面
|
||||
* "data" => [
|
||||
|
||||
@ -33,7 +33,7 @@ class LogMessagePush extends Model
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = ['log_id', 'to_user_id', 'user_type', 'type', 'status', 'fail_reason', 'send_reason', 'content', 'created_at', 'updated_at'];
|
||||
protected array $fillable = ['log_id', 'to_user_id', 'user_type', 'type', 'status', 'fail_reason', 'content', 'created_at', 'updated_at'];
|
||||
|
||||
protected string $primaryKey = "log_id";
|
||||
|
||||
|
||||
@ -637,6 +637,7 @@ class InquiryService extends BaseService
|
||||
$result = array();
|
||||
$result['doctor_user_id'] = $user_doctor['user_id'];
|
||||
$result['patient_user_id'] = $order_inquiry['user_id'];
|
||||
$result['doctor_id'] = $order_inquiry['doctor_id'];
|
||||
$result['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
$result['patient_name'] = $order_inquiry['patient_name'];
|
||||
$result['patient_sex'] = $order_inquiry['patient_sex'];
|
||||
|
||||
@ -52,6 +52,10 @@ class MessageNoticeService extends BaseService
|
||||
if (!empty($item['show_params'])) {
|
||||
$item['show_params'] = json_decode($item['show_params']);
|
||||
}
|
||||
|
||||
if (!empty($item['notice_send_time'])) {
|
||||
$item['notice_send_time'] = date('Y-m-d H:i',strtotime($item['notice_send_time']));
|
||||
}
|
||||
}
|
||||
}
|
||||
return success($result);
|
||||
@ -98,6 +102,10 @@ class MessageNoticeService extends BaseService
|
||||
if (!empty($item['show_params'])) {
|
||||
$item['show_params'] = json_decode($item['show_params'], true);
|
||||
}
|
||||
|
||||
if (!empty($item['notice_send_time'])) {
|
||||
$item['notice_send_time'] = date('Y-m-d H:i',strtotime($item['notice_send_time']));
|
||||
}
|
||||
}
|
||||
}
|
||||
return success($result);
|
||||
@ -131,6 +139,10 @@ class MessageNoticeService extends BaseService
|
||||
$message_notice['show_params'] = json_decode($message_notice['show_params'], true);
|
||||
}
|
||||
|
||||
if (!empty($message_notice['notice_send_time'])) {
|
||||
$message_notice['notice_send_time'] = date('Y-m-d H:i',strtotime($message_notice['notice_send_time']));
|
||||
}
|
||||
|
||||
return success($message_notice->toArray());
|
||||
}
|
||||
|
||||
@ -295,6 +307,10 @@ class MessageNoticeService extends BaseService
|
||||
if (!empty($item['show_params'])) {
|
||||
$item['show_params'] = json_decode($item['show_params']);
|
||||
}
|
||||
|
||||
if (!empty($item['notice_send_time'])) {
|
||||
$item['notice_send_time'] = date('Y-m-d H:i',strtotime($item['notice_send_time']));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -603,7 +603,7 @@ Router::addGroup('/message', function () {
|
||||
Router::put('/read/{notice_id:\d+}', [MessageNoticeController::class, 'putMessageReadId']);
|
||||
|
||||
// 一键消息已读
|
||||
Router::get('/read', [MessageNoticeController::class, 'putMessageRead']);
|
||||
Router::put('/read', [MessageNoticeController::class, 'putMessageRead']);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user