消息模块完善
This commit is contained in:
@@ -13,6 +13,11 @@ class MessageService
|
||||
/** @var Messages */
|
||||
public static $Model = Messages::class;
|
||||
|
||||
// 消息类型
|
||||
const TYPE_SYSTEM = '0'; //系统消息:账户、审核、安全类
|
||||
const TYPE_NOTICE = '1'; //公告消息:平台运营公告
|
||||
const TYPE_DEMAND = '2'; //需求消息:需求/工单/合同/订单等业务流程
|
||||
|
||||
|
||||
/**
|
||||
* @param $to_user_id
|
||||
@@ -23,10 +28,10 @@ class MessageService
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function createData($to_user_id, $title, $content, $extra_json = [], $from_user_id = 0)
|
||||
public static function createData($to_user_id, $title, $content, $extra_json = [], $from_user_id = 0, $message_type = self::TYPE_SYSTEM)
|
||||
{
|
||||
$data = [
|
||||
'message_type' => CommonService::NO,
|
||||
'message_type' => $message_type,
|
||||
'from_user_id' => $from_user_id,
|
||||
'to_user_id' => $to_user_id,
|
||||
'title' => $title,
|
||||
@@ -43,4 +48,48 @@ class MessageService
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送订阅消息时同步写入站内消息
|
||||
* 数据来源:MSG_MAP 中模板的 name / message_type / valueNames / remark / page
|
||||
* @param int $to_user_id 收件用户
|
||||
* @param string $template_id 订阅消息模板ID
|
||||
* @param array $msgData sendMsg 的原始参数 ['values'=>[], 'param'=>[], 'page'=>'']
|
||||
* @param string $page 打包后的跳转页面(含query),如 pages/demand/list/index?opType=my&demandId=1
|
||||
* @return mixed
|
||||
*/
|
||||
public static function createBySubscribe($to_user_id, $template_id, array $msgData = [], $page = '')
|
||||
{
|
||||
$template = SubscribeMessageService::MSG_MAP[$template_id] ?? [];
|
||||
if (!$template) {
|
||||
//未定义的模板不写站内消息
|
||||
return false;
|
||||
}
|
||||
|
||||
//按模板字段名组装可读内容:工单号:xxx;服务项目:xxx;...;备注:xxx
|
||||
$values = $msgData['values'] ?? [];
|
||||
$valueNames = $template['valueNames'] ?? [];
|
||||
$lines = [];
|
||||
foreach ($valueNames as $key => $name) {
|
||||
if (isset($values[$key]) && $values[$key] !== '') {
|
||||
$lines[] = $name . ':' . $values[$key];
|
||||
}
|
||||
}
|
||||
if (!empty($template['remark'])) {
|
||||
$lines[] = '备注:' . $template['remark'];
|
||||
}
|
||||
$content = implode("\n", $lines);
|
||||
|
||||
return self::createData(
|
||||
$to_user_id,
|
||||
$template['name'] ?? '系统通知',
|
||||
$content,
|
||||
[
|
||||
'page' => $page ?: ($template['page'] ?? ''),
|
||||
'template_id' => $template_id,
|
||||
],
|
||||
0, //系统发出
|
||||
$template['message_type'] ?? self::TYPE_SYSTEM
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user