feat: 添加实时广播功能,支持风险预警、玩法切换和赔率更新,增强大厅公共频道的广播能力
This commit is contained in:
62
app/Events/OddsUpdateBroadcast.php
Normal file
62
app/Events/OddsUpdateBroadcast.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
|
||||
/**
|
||||
* 界面文档 §2.1:`odds.update` —— 赔率变更推送。
|
||||
*
|
||||
* 触发时机:后台发布新赔率版本时。
|
||||
* 前端处理:Toast 提示用户赔率已更新,建议重新预览注单。
|
||||
*/
|
||||
final class OddsUpdateBroadcast implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @param int $versionId 新版本 ID
|
||||
* @param string $versionName 版本名称/描述
|
||||
* @param array<string, mixed>|null $diff 差异数据(哪些玩法赔率变化了,可选)
|
||||
* @param int $emittedAtMs 发送时间戳(毫秒)
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly int $versionId,
|
||||
public readonly string $versionName,
|
||||
public readonly ?array $diff,
|
||||
public readonly int $emittedAtMs,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 公共频道,所有在大厅的玩家都能收到。
|
||||
*
|
||||
* @return array<int, Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [new Channel('lottery-hall')];
|
||||
}
|
||||
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'odds.update';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{version_id: int, version_name: string, diff: array<string, mixed>|null, message: string, emitted_at_ms: int}
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'version_id' => $this->versionId,
|
||||
'version_name' => $this->versionName,
|
||||
'diff' => $this->diff,
|
||||
'message' => '赔率已更新,请重新预览注单',
|
||||
'emitted_at_ms' => $this->emittedAtMs,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user