Files
lotteryLaravel/app/Events/RiskSoldOutBroadcast.php

62 lines
1.8 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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.sold_out` —— 号码赔付池耗尽推送。
*
* 触发时机:某号码的风险池额度被完全占用时。
* 前端处理:该号码的玩法格子标记为售罄(置灰或禁用)。
*/
final class RiskSoldOutBroadcast implements ShouldBroadcastNow
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* @param int $drawId 期号 ID
* @param string $drawNo 期号编号(如 20260101-001
* @param string $normalizedNumber 标准化后的 4 位号码
* @param int $emittedAtMs 发送时间戳(毫秒)
*/
public function __construct(
public readonly int $drawId,
public readonly string $drawNo,
public readonly string $normalizedNumber,
public readonly int $emittedAtMs,
) {}
/**
* 公共频道,所有在大厅的玩家都能收到。
*
* @return array<int, Channel>
*/
public function broadcastOn(): array
{
return [new Channel('lottery-hall')];
}
public function broadcastAs(): string
{
return 'risk.sold_out';
}
/**
* @return array{draw_id: int, draw_no: string, normalized_number: string, emitted_at_ms: int}
*/
public function broadcastWith(): array
{
return [
'draw_id' => $this->drawId,
'draw_no' => $this->drawNo,
'normalized_number' => $this->normalizedNumber,
'emitted_at_ms' => $this->emittedAtMs,
];
}
}