优化游戏实时对局页面

This commit is contained in:
2026-04-21 10:02:16 +08:00
parent 17eadddaa2
commit aad00e10f8
9 changed files with 622 additions and 41 deletions

View File

@@ -13,6 +13,9 @@ final class GameRecordService
public const KEY_MANUAL_CREATE = 'period_manual_create_enabled';
/** 后台「游戏实时对局」运行开关0=暂停自动开奖与派彩后自动创建下一期1=运行 */
public const KEY_LIVE_RUNTIME = 'game_live_runtime_enabled';
private const ACTIVE_STATUSES = [0, 1, 2, 3];
public static function getConfigBool(string $key): bool
@@ -50,6 +53,9 @@ final class GameRecordService
public static function tickAutoCreate(): void
{
if (!self::isLiveRuntimeEnabled()) {
return;
}
if (!self::getConfigBool(self::KEY_AUTO_CREATE)) {
return;
}
@@ -80,12 +86,55 @@ final class GameRecordService
public static function createNextRecordAfterDraw(): ?string
{
if (!self::isLiveRuntimeEnabled()) {
return null;
}
if (self::hasActiveRecord()) {
return null;
}
return self::createNextRecordRow();
}
/**
* 未配置键时视为开启(兼容旧库未跑迁移)。
*/
public static function isLiveRuntimeEnabled(): bool
{
$row = GameHotDataRedis::gameConfigRow(self::KEY_LIVE_RUNTIME);
if ($row === null) {
return true;
}
$v = $row['config_value'] ?? '';
return $v === '1' || $v === 1;
}
public static function setLiveRuntimeEnabled(bool $enabled): void
{
$now = time();
$v = $enabled ? '1' : '0';
self::upsertConfig(
self::KEY_LIVE_RUNTIME,
$v,
'int',
'后台「游戏实时对局」运行开关0=维护禁止下注、结束后不自动开新期当局仍自动开奖并结算1=运行',
$now
);
}
/**
* 重新开启游戏时:若无进行中/未结清对局,则立即创建新一期(与定时任务「无局时自动创建」语义一致,供开关打开时立刻开局)。
*/
public static function bootstrapPeriodWhenRuntimeEnabled(): void
{
if (self::hasActiveRecord()) {
return;
}
try {
self::createNextRecordRow();
} catch (Throwable) {
}
}
private static function createNextRecordRow(): string
{
$periodNo = self::generatePeriodNo();