赠金币通知:发送者/接收者在包厢窗口显示,其他人在公屏显示(利用 to_user 路由机制)
This commit is contained in:
@@ -1178,22 +1178,23 @@ class ChatController extends Controller
|
||||
$sender->decrement('jjb', $amount);
|
||||
$receiver->increment('jjb', $amount);
|
||||
|
||||
// 广播「系统传音」条目至全房间
|
||||
$sysMsg = [
|
||||
// 广播一条消息:发送者/接收者路由到 say2(下方包厢),其他人路由到 say1(公屏)
|
||||
// 原理:前端 isRelatedToMe = isMe || to_user===me → say2;否则 → say1
|
||||
$giftMsg = [
|
||||
'id' => $this->chatState->nextMessageId($roomId),
|
||||
'room_id' => $roomId,
|
||||
'from_user' => '系统传音',
|
||||
'to_user' => '大家',
|
||||
'content' => "💝 【{$sender->username}】 向 【{$toName}】 赠送了 {$amount} 金币!",
|
||||
'from_user' => $sender->username,
|
||||
'to_user' => $toName,
|
||||
'content' => "悄悄赠送给你 {$amount} 金币!💝",
|
||||
'is_secret' => false,
|
||||
'font_color' => '#b45309',
|
||||
'action' => '',
|
||||
'sent_at' => now()->toDateTimeString(),
|
||||
];
|
||||
|
||||
$this->chatState->pushMessage($roomId, $sysMsg);
|
||||
broadcast(new MessageSent($roomId, $sysMsg));
|
||||
SaveMessageJob::dispatch($sysMsg);
|
||||
$this->chatState->pushMessage($roomId, $giftMsg);
|
||||
broadcast(new MessageSent($roomId, $giftMsg));
|
||||
SaveMessageJob::dispatch($giftMsg);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
|
||||
Reference in New Issue
Block a user