diff --git a/backend/app/services/message/Notice.php b/backend/app/services/message/Notice.php index a62f93cdc..68e69bf6f 100644 --- a/backend/app/services/message/Notice.php +++ b/backend/app/services/message/Notice.php @@ -13,6 +13,7 @@ use app\services\message\admin\NoticeLogServices; use app\services\message\pipeline\SendNoticeService; use crmeb\exceptions\NoticeSendException; use crmeb\plugin\ModuleStateChecker; +use crmeb\services\notice\AbstractNoticeChannel; use crmeb\services\notice\NoticeChannelInterface; use crmeb\services\notice\NoticeMessage; use think\facade\Log; @@ -311,13 +312,16 @@ class Notice { try { $message = $target['message']; + // 日志展示实际发出的文案,写入前用业务变量渲染模板占位符 + $title = AbstractNoticeChannel::renderTemplate($message->title, $message->variables); + $content = AbstractNoticeChannel::renderTemplate($message->content, $message->variables); $logId = $this->logServices()->createLog( $message->mark, $message->uid, $target['channel_key'], $target['channel_name'], - $message->title, - $message->content + $title, + $content ); if ($ok) { $this->logServices()->logSuccess($logId); diff --git a/backend/crmeb/services/notice/AbstractNoticeChannel.php b/backend/crmeb/services/notice/AbstractNoticeChannel.php index c9696925b..cfc1bbf71 100644 --- a/backend/crmeb/services/notice/AbstractNoticeChannel.php +++ b/backend/crmeb/services/notice/AbstractNoticeChannel.php @@ -69,12 +69,13 @@ abstract class AbstractNoticeChannel implements NoticeChannelInterface * * 值统一转 string,避免 int 参数触发 str_replace TypeError; * 非标量值(数组/对象)跳过不参与替换。 + * 静态入口供写发送日志等非渠道场景复用,与实例方法行为一致。 * * @param string $text 模板文本(含 {key} 占位符) * @param array $variables 扁平业务变量 * @return string */ - protected function renderPlaceholders(string $text, array $variables): string + public static function renderTemplate(string $text, array $variables): string { if ($text === '' || empty($variables)) { return $text; @@ -87,4 +88,16 @@ abstract class AbstractNoticeChannel implements NoticeChannelInterface } return $text; } + + /** + * 实例侧占位符渲染(委托静态实现,保持子类调用习惯) + * + * @param string $text 模板文本(含 {key} 占位符) + * @param array $variables 扁平业务变量 + * @return string + */ + protected function renderPlaceholders(string $text, array $variables): string + { + return static::renderTemplate($text, $variables); + } } diff --git a/frontend/admin/src/pages/setting/notification/log/index.vue b/frontend/admin/src/pages/setting/notification/log/index.vue index 63edc4b04..f0209de61 100644 --- a/frontend/admin/src/pages/setting/notification/log/index.vue +++ b/frontend/admin/src/pages/setting/notification/log/index.vue @@ -152,44 +152,34 @@ - - - - {{ detailData.id }} - - - {{ detailData.mark }} - - - {{ detailData.uid || '-' }} - - - {{ detailData.channel_name || detailData.channel_key }} - - - {{ detailData.title || '-' }} - - -