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

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