- 新增 BaccaratPoolUpdated 事件,用于通过 WebSocket 广播实时下注数据更新 - 增加数据库迁移以在 baccarat_rounds 表中添加对应的下注人数统计字段 - 更新 BaccaratRound 模型以及 BaccaratController,支持实时下注统计更新与 WebSocket 事件分发 - 更新前端 chat.js 以及 baccarat-panel.blade.php,利用 Alpine.js 和 Echo 接收事件并动态渲染 "大"、"小"、"豹子" 的实时下注计数
67 lines
1.6 KiB
PHP
67 lines
1.6 KiB
PHP
<?php
|
||
|
||
/**
|
||
* 文件功能:百家乐押注人数实时广播事件
|
||
*
|
||
* 当有用户成功下注时,向房间内所有用户广播最新的
|
||
* 各选项下注总人次,供前端实时更新面板。
|
||
*
|
||
* @author ChatRoom Laravel
|
||
*
|
||
* @version 1.0.0
|
||
*/
|
||
|
||
namespace App\Events;
|
||
|
||
use App\Models\BaccaratRound;
|
||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||
use Illuminate\Broadcasting\PresenceChannel;
|
||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||
use Illuminate\Foundation\Events\Dispatchable;
|
||
use Illuminate\Queue\SerializesModels;
|
||
|
||
class BaccaratPoolUpdated implements ShouldBroadcastNow
|
||
{
|
||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||
|
||
/**
|
||
* @param BaccaratRound $round 本局信息
|
||
*/
|
||
public function __construct(
|
||
public readonly BaccaratRound $round,
|
||
) {}
|
||
|
||
/**
|
||
* 广播至房间公共频道。
|
||
*
|
||
* @return array<int, \Illuminate\Broadcasting\Channel>
|
||
*/
|
||
public function broadcastOn(): array
|
||
{
|
||
return [new PresenceChannel('room.1')];
|
||
}
|
||
|
||
/**
|
||
* 广播事件名(前端监听 .baccarat.pool_updated)。
|
||
*/
|
||
public function broadcastAs(): string
|
||
{
|
||
return 'baccarat.pool_updated';
|
||
}
|
||
|
||
/**
|
||
* 广播数据。
|
||
*
|
||
* @return array<string, mixed>
|
||
*/
|
||
public function broadcastWith(): array
|
||
{
|
||
return [
|
||
'round_id' => $this->round->id,
|
||
'bet_count_big' => $this->round->bet_count_big,
|
||
'bet_count_small' => $this->round->bet_count_small,
|
||
'bet_count_triple' => $this->round->bet_count_triple,
|
||
];
|
||
}
|
||
}
|