feat: 添加实时广播功能,支持风险预警、玩法切换和赔率更新,增强大厅公共频道的广播能力
This commit is contained in:
66
app/Events/RiskWarningBroadcast.php
Normal file
66
app/Events/RiskWarningBroadcast.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?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:`risk.warning` —— 号码赔付池占用超 80% 预警推送。
|
||||
*
|
||||
* 触发时机:某号码的风险池占用比例超过阈值(默认 80%)时。
|
||||
* 前端处理:该号码的玩法格子显示预警样式(如黄色边框或图标)。
|
||||
*/
|
||||
final class RiskWarningBroadcast implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @param int $drawId 期号 ID
|
||||
* @param string $drawNo 期号编号
|
||||
* @param string $normalizedNumber 标准化后的 4 位号码
|
||||
* @param float $usageRatio 占用比例(0-1 之间,如 0.85 表示 85%)
|
||||
* @param int $emittedAtMs 发送时间戳(毫秒)
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly int $drawId,
|
||||
public readonly string $drawNo,
|
||||
public readonly string $normalizedNumber,
|
||||
public readonly float $usageRatio,
|
||||
public readonly int $emittedAtMs,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 公共频道,所有在大厅的玩家都能收到。
|
||||
*
|
||||
* @return array<int, Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [new Channel('lottery-hall')];
|
||||
}
|
||||
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'risk.warning';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{draw_id: int, draw_no: string, normalized_number: string, usage_ratio: float, usage_percent: int, warning_threshold: float, emitted_at_ms: int}
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'draw_id' => $this->drawId,
|
||||
'draw_no' => $this->drawNo,
|
||||
'normalized_number' => $this->normalizedNumber,
|
||||
'usage_ratio' => round($this->usageRatio, 4),
|
||||
'usage_percent' => (int) round($this->usageRatio * 100),
|
||||
'warning_threshold' => 0.8, // 80% 阈值
|
||||
'emitted_at_ms' => $this->emittedAtMs,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user