修复:礼物系统消息字段名改为 from_user/to_user/sent_at 与前端 appendMessage() 匹配,触发金色边框样式

This commit is contained in:
2026-02-27 16:30:41 +08:00
parent 157aee3812
commit 43956d286e

View File

@@ -110,24 +110,25 @@ class ShopController extends Controller
'lightning' => '⚡',
'snow' => '❄️',
];
// 赠礼消息文案(简洁精美)
$icon = $icons[$result['play_effect']] ?? '✨';
$toStr = $targetUsername ? "{$targetUsername}" : '全体聊友';
$msgText = $message
? "{$message}"
: '';
$sysContent = "{$icon}{$user->username}】送出了一张 [{$item->name}],赠给 {$toStr}{$msgText}";
$remarkPart = $message ? "{$message}" : '';
$sysContent = "{$icon} {$user->username} 送了一张【{$item->name}】给 {$toStr}{$remarkPart}";
// 广播系统消息到公屏(ShouldBroadcastNow 模式
// 广播系统消息到公屏(字段名与前端 appendMessage() 保持一致
$sysMsgEvent = new MessageSent(
roomId: $roomId,
message: [
'id' => 0,
'room_id' => $roomId,
'username' => '系统',
'from_user' => '系统传音', // 触发金色左边框样式(已有处理分支)
'to_user' => '大家',
'content' => $sysContent,
'type' => 'sys',
'color' => '#cc6600',
'created_at' => now()->toDateTimeString(),
'font_color' => '#cc6600',
'sent_at' => now()->format('H:i:s'),
'is_secret' => false,
'action' => null,
]
);
broadcast($sysMsgEvent);