diff --git a/app/Events/BalanceUpdateBroadcast.php b/app/Events/BalanceUpdateBroadcast.php index c219caa..ff8bc61 100644 --- a/app/Events/BalanceUpdateBroadcast.php +++ b/app/Events/BalanceUpdateBroadcast.php @@ -6,7 +6,7 @@ use Illuminate\Broadcasting\Channel; use Illuminate\Queue\SerializesModels; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; +use Illuminate\Contracts\Broadcasting\ShouldBroadcast; /** * 界面文档 §2.1:`balance.update` —— 钱包余额变动推送。 @@ -14,10 +14,19 @@ use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; * 触发时机:转入/转出/下注/派彩等导致余额变动时。 * 前端处理:更新余额显示 + Toast 提示。 */ -final class BalanceUpdateBroadcast implements ShouldBroadcastNow +final class BalanceUpdateBroadcast implements ShouldBroadcast { use Dispatchable, InteractsWithSockets, SerializesModels; + /** 异步广播队列 */ + public string $queue = 'broadcasts'; + + /** 最多重试 3 次 */ + public int $tries = 3; + + /** 单任务超时 10 秒 */ + public int $timeout = 10; + /** * @param int $playerId 玩家 ID(用于频道隔离) * @param string $currencyCode 币种代码 diff --git a/app/Events/DrawCountdownBroadcast.php b/app/Events/DrawCountdownBroadcast.php index e273657..d57d0e1 100644 --- a/app/Events/DrawCountdownBroadcast.php +++ b/app/Events/DrawCountdownBroadcast.php @@ -6,13 +6,43 @@ use Illuminate\Broadcasting\Channel; use Illuminate\Queue\SerializesModels; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; +use Illuminate\Contracts\Broadcasting\ShouldBroadcast; -/** 界面文档 §2.1:`draw.countdown` */ -final class DrawCountdownBroadcast implements ShouldBroadcastNow +/** + * 界面文档 §2.1:`draw.countdown` + * + * 每秒由 `lottery:hall-countdown` 命令派发。使用专用队列 `broadcasts:countdown` + * 与低频广播隔离,并配置短超时 + 单次尝试,避免队列积压时广播过期数据。 + */ +final class DrawCountdownBroadcast implements ShouldBroadcast { use Dispatchable, InteractsWithSockets, SerializesModels; + /** + * 专用倒计时队列,与常规广播队列 `broadcasts` 隔离, + * 避免低频事件阻塞高频 countdown 任务。 + */ + public string $queue = 'broadcasts:countdown'; + + /** + * 单次尝试:倒计时数据时效性极高,失败后重试已无意义。 + */ + public int $tries = 1; + + /** + * 单任务超时 5 秒:广播本身应在 1s 内完成,超时说明 Reverb 连接异常。 + */ + public int $timeout = 5; + + /** + * 从派发起 5 秒内必须开始执行,否则队列工作者自动丢弃。 + * 防止队列积压时大量过期 countdown 事件被顺序处理。 + */ + public function retryUntil(): \DateTimeInterface + { + return now()->addSeconds(5); + } + /** * @param array|null $data 与 GET draw/current 的 data 相同 */ diff --git a/app/Events/DrawResultPublishedBroadcast.php b/app/Events/DrawResultPublishedBroadcast.php index 600c427..3460d60 100644 --- a/app/Events/DrawResultPublishedBroadcast.php +++ b/app/Events/DrawResultPublishedBroadcast.php @@ -6,13 +6,22 @@ use Illuminate\Broadcasting\Channel; use Illuminate\Queue\SerializesModels; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; +use Illuminate\Contracts\Broadcasting\ShouldBroadcast; /** 界面文档 §2.1:`result.published` */ -final class DrawResultPublishedBroadcast implements ShouldBroadcastNow +final class DrawResultPublishedBroadcast implements ShouldBroadcast { use Dispatchable, InteractsWithSockets, SerializesModels; + /** 异步广播队列 */ + public string $queue = 'broadcasts'; + + /** 最多重试 3 次 */ + public int $tries = 3; + + /** 单任务超时 10 秒 */ + public int $timeout = 10; + /** * @param array|null $data 与 GET draw/current 的 data 相同(含 result_items) */ diff --git a/app/Events/DrawStatusChangeBroadcast.php b/app/Events/DrawStatusChangeBroadcast.php index 6f1a92a..50eef9d 100644 --- a/app/Events/DrawStatusChangeBroadcast.php +++ b/app/Events/DrawStatusChangeBroadcast.php @@ -6,13 +6,22 @@ use Illuminate\Broadcasting\Channel; use Illuminate\Queue\SerializesModels; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; +use Illuminate\Contracts\Broadcasting\ShouldBroadcast; /** 界面文档 §2.1:`draw.status_change` */ -final class DrawStatusChangeBroadcast implements ShouldBroadcastNow +final class DrawStatusChangeBroadcast implements ShouldBroadcast { use Dispatchable, InteractsWithSockets, SerializesModels; + /** 异步广播队列 */ + public string $queue = 'broadcasts'; + + /** 最多重试 3 次 */ + public int $tries = 3; + + /** 单任务超时 10 秒 */ + public int $timeout = 10; + /** * @param array|null $data 与 GET draw/current 的 data 相同 */ diff --git a/app/Events/JackpotBurstBroadcast.php b/app/Events/JackpotBurstBroadcast.php index 10405c8..6efe554 100644 --- a/app/Events/JackpotBurstBroadcast.php +++ b/app/Events/JackpotBurstBroadcast.php @@ -6,13 +6,22 @@ use Illuminate\Broadcasting\Channel; use Illuminate\Queue\SerializesModels; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; +use Illuminate\Contracts\Broadcasting\ShouldBroadcast; /** Jackpot 爆池公共广播:`jackpot.burst` */ -final class JackpotBurstBroadcast implements ShouldBroadcastNow +final class JackpotBurstBroadcast implements ShouldBroadcast { use Dispatchable, InteractsWithSockets, SerializesModels; + /** 异步广播队列 */ + public string $queue = 'broadcasts'; + + /** 最多重试 3 次 */ + public int $tries = 3; + + /** 单任务超时 10 秒 */ + public int $timeout = 10; + public function __construct( public readonly int $drawId, public readonly string $drawNo, diff --git a/app/Events/OddsUpdateBroadcast.php b/app/Events/OddsUpdateBroadcast.php index d0b691c..34b0cb5 100644 --- a/app/Events/OddsUpdateBroadcast.php +++ b/app/Events/OddsUpdateBroadcast.php @@ -6,7 +6,7 @@ use Illuminate\Broadcasting\Channel; use Illuminate\Queue\SerializesModels; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; +use Illuminate\Contracts\Broadcasting\ShouldBroadcast; /** * 界面文档 §2.1:`odds.update` —— 赔率变更推送。 @@ -14,10 +14,19 @@ use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; * 触发时机:后台发布新赔率版本时。 * 前端处理:Toast 提示用户赔率已更新,建议重新预览注单。 */ -final class OddsUpdateBroadcast implements ShouldBroadcastNow +final class OddsUpdateBroadcast implements ShouldBroadcast { use Dispatchable, InteractsWithSockets, SerializesModels; + /** 异步广播队列 */ + public string $queue = 'broadcasts'; + + /** 最多重试 3 次 */ + public int $tries = 3; + + /** 单任务超时 10 秒 */ + public int $timeout = 10; + /** * @param int $versionId 新版本 ID * @param string $versionName 版本名称/描述 diff --git a/app/Events/PlayCatalogUpdatedBroadcast.php b/app/Events/PlayCatalogUpdatedBroadcast.php index 7fd4c6a..2968e06 100644 --- a/app/Events/PlayCatalogUpdatedBroadcast.php +++ b/app/Events/PlayCatalogUpdatedBroadcast.php @@ -6,7 +6,7 @@ use Illuminate\Broadcasting\Channel; use Illuminate\Queue\SerializesModels; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; +use Illuminate\Contracts\Broadcasting\ShouldBroadcast; /** * 界面文档扩展:`play.catalog_updated` —— 玩法目录/限额/封顶等生效版本变更。 @@ -14,10 +14,19 @@ use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; * 触发时机:后台发布玩法配置、赔率、风控封顶版本(及同类全量变更)时。 * 前端处理:重新拉取 `GET /api/v1/play/effective`。 */ -final class PlayCatalogUpdatedBroadcast implements ShouldBroadcastNow +final class PlayCatalogUpdatedBroadcast implements ShouldBroadcast { use Dispatchable, InteractsWithSockets, SerializesModels; + /** 异步广播队列 */ + public string $queue = 'broadcasts'; + + /** 最多重试 3 次 */ + public int $tries = 3; + + /** 单任务超时 10 秒 */ + public int $timeout = 10; + /** * @param string $module play_config|odds|risk_cap * @param array|null $meta diff --git a/app/Events/PlayToggleBroadcast.php b/app/Events/PlayToggleBroadcast.php index 5d46aff..36a545f 100644 --- a/app/Events/PlayToggleBroadcast.php +++ b/app/Events/PlayToggleBroadcast.php @@ -6,7 +6,7 @@ use Illuminate\Broadcasting\Channel; use Illuminate\Queue\SerializesModels; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; +use Illuminate\Contracts\Broadcasting\ShouldBroadcast; /** * 界面文档 §2.1:`play.toggle` —— 玩法开关变更推送。 @@ -14,10 +14,19 @@ use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; * 触发时机:后台开启或关闭某玩法时。 * 前端处理:玩法列显示/隐藏或置灰/启用。 */ -final class PlayToggleBroadcast implements ShouldBroadcastNow +final class PlayToggleBroadcast implements ShouldBroadcast { use Dispatchable, InteractsWithSockets, SerializesModels; + /** 异步广播队列 */ + public string $queue = 'broadcasts'; + + /** 最多重试 3 次 */ + public int $tries = 3; + + /** 单任务超时 10 秒 */ + public int $timeout = 10; + /** * @param string $playCode 玩法代码(如 straight_4d, box_2d 等) * @param bool $enabled 是否启用 diff --git a/app/Events/RiskSoldOutBroadcast.php b/app/Events/RiskSoldOutBroadcast.php index 065c07e..ec68968 100644 --- a/app/Events/RiskSoldOutBroadcast.php +++ b/app/Events/RiskSoldOutBroadcast.php @@ -6,7 +6,7 @@ use Illuminate\Broadcasting\Channel; use Illuminate\Queue\SerializesModels; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; +use Illuminate\Contracts\Broadcasting\ShouldBroadcast; /** * 界面文档 §2.1:`risk.sold_out` —— 号码赔付池耗尽推送。 @@ -14,10 +14,19 @@ use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; * 触发时机:某号码的风险池额度被完全占用时。 * 前端处理:该号码的玩法格子标记为售罄(置灰或禁用)。 */ -final class RiskSoldOutBroadcast implements ShouldBroadcastNow +final class RiskSoldOutBroadcast implements ShouldBroadcast { use Dispatchable, InteractsWithSockets, SerializesModels; + /** 异步广播队列 */ + public string $queue = 'broadcasts'; + + /** 最多重试 3 次 */ + public int $tries = 3; + + /** 单任务超时 10 秒 */ + public int $timeout = 10; + /** * @param int $drawId 期号 ID * @param string $drawNo 期号编号(如 20260101-001) diff --git a/app/Events/RiskWarningBroadcast.php b/app/Events/RiskWarningBroadcast.php index 927b437..2124c46 100644 --- a/app/Events/RiskWarningBroadcast.php +++ b/app/Events/RiskWarningBroadcast.php @@ -6,7 +6,7 @@ use Illuminate\Broadcasting\Channel; use Illuminate\Queue\SerializesModels; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; +use Illuminate\Contracts\Broadcasting\ShouldBroadcast; /** * 界面文档 §2.1:`risk.warning` —— 号码赔付池占用超 80% 预警推送。 @@ -14,10 +14,19 @@ use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; * 触发时机:某号码的风险池占用比例超过阈值(默认 80%)时。 * 前端处理:该号码的玩法格子显示预警样式(如黄色边框或图标)。 */ -final class RiskWarningBroadcast implements ShouldBroadcastNow +final class RiskWarningBroadcast implements ShouldBroadcast { use Dispatchable, InteractsWithSockets, SerializesModels; + /** 异步广播队列 */ + public string $queue = 'broadcasts'; + + /** 最多重试 3 次 */ + public int $tries = 3; + + /** 单任务超时 10 秒 */ + public int $timeout = 10; + /** * @param int $drawId 期号 ID * @param string $drawNo 期号编号 diff --git a/database/migrations/2026_06_10_120000_align_postgres_indexes_with_live_schema.php b/database/migrations/2026_06_10_120000_align_postgres_indexes_with_live_schema.php index 9d37581..9e602cb 100644 --- a/database/migrations/2026_06_10_120000_align_postgres_indexes_with_live_schema.php +++ b/database/migrations/2026_06_10_120000_align_postgres_indexes_with_live_schema.php @@ -2,7 +2,6 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; return new class extends Migration @@ -39,10 +38,7 @@ return new class extends Migration private function hasIndex(string $table, string $indexName): bool { - return DB::table('pg_indexes') - ->where('schemaname', 'public') - ->where('tablename', $table) - ->where('indexname', $indexName) - ->exists(); + // 使用 Laravel 内置方法,兼容 PostgreSQL 和 SQLite 测试环境 + return Schema::hasIndex($table, $indexName); } };