赠送金币改为私聊通知
This commit is contained in:
@@ -1244,7 +1244,7 @@ class ChatController extends Controller
|
||||
* 用户间赠送金币(任何登录用户均可调用)
|
||||
*
|
||||
* 从自己的余额中扣除指定金额,转入对方账户,
|
||||
* 并在房间内通过「系统传音」广播一条赠送提示。
|
||||
* 并以私聊消息的方式仅通知赠送双方。
|
||||
*/
|
||||
public function giftGold(Request $request): JsonResponse
|
||||
{
|
||||
@@ -1287,20 +1287,20 @@ class ChatController extends Controller
|
||||
$sender->decrement('jjb', $amount);
|
||||
$receiver->increment('jjb', $amount);
|
||||
|
||||
// 广播一条消息:发送者/接收者路由到 say2(下方包厢),其他人路由到 say1(公屏)
|
||||
// 原理:前端 isRelatedToMe = isMe || to_user===me → say2;否则 → say1
|
||||
// 写入真正的私聊消息,避免其他旁观用户在公屏看到赠金币通知。
|
||||
$giftMsg = [
|
||||
'id' => $this->chatState->nextMessageId($roomId),
|
||||
'room_id' => $roomId,
|
||||
'from_user' => $sender->username,
|
||||
'to_user' => $toName,
|
||||
'content' => "悄悄赠送给你 {$amount} 金币!💝",
|
||||
'is_secret' => false,
|
||||
'content' => "赠送了你 {$amount} 金币!💝",
|
||||
'is_secret' => true,
|
||||
'font_color' => '#b45309',
|
||||
'action' => '',
|
||||
'sent_at' => now()->toDateTimeString(),
|
||||
];
|
||||
|
||||
// 推入 Redis + WebSocket + 异步落库,保持与普通私聊一致的展示与历史记录行为。
|
||||
$this->chatState->pushMessage($roomId, $giftMsg);
|
||||
broadcast(new MessageSent($roomId, $giftMsg));
|
||||
SaveMessageJob::dispatch($giftMsg);
|
||||
|
||||
Reference in New Issue
Block a user