1.修复关闭自动创建下一局后还自动创建下一期
This commit is contained in:
@@ -23,6 +23,31 @@ final class GameRecordService
|
||||
return false;
|
||||
}
|
||||
$v = $row['config_value'] ?? '';
|
||||
return self::truthyConfigValue($v);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否允许自动创建下一局(读库,避免 Redis 缓存仍为 1 时误开新期)。
|
||||
*/
|
||||
public static function isAutoCreateEnabled(): bool
|
||||
{
|
||||
return self::getConfigBoolFromDb(self::KEY_AUTO_CREATE);
|
||||
}
|
||||
|
||||
private static function getConfigBoolFromDb(string $key): bool
|
||||
{
|
||||
if ($key === '') {
|
||||
return false;
|
||||
}
|
||||
$row = Db::name('game_config')->where('config_key', $key)->find();
|
||||
if (!$row) {
|
||||
return false;
|
||||
}
|
||||
return self::truthyConfigValue($row['config_value'] ?? '');
|
||||
}
|
||||
|
||||
private static function truthyConfigValue(mixed $v): bool
|
||||
{
|
||||
return $v === '1' || $v === 1;
|
||||
}
|
||||
|
||||
@@ -51,7 +76,7 @@ final class GameRecordService
|
||||
|
||||
public static function tickAutoCreate(): void
|
||||
{
|
||||
if (!self::getConfigBool(self::KEY_AUTO_CREATE)) {
|
||||
if (!self::isAutoCreateEnabled()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@@ -78,10 +103,6 @@ final class GameRecordService
|
||||
|
||||
public static function createNextRecordAfterDraw(): ?string
|
||||
{
|
||||
// 派彩结束后是否自动开新局:由 period_auto_create_enabled 控制
|
||||
if (!self::getConfigBool(self::KEY_AUTO_CREATE)) {
|
||||
return null;
|
||||
}
|
||||
return self::createNextRecordRowIfNoActive();
|
||||
}
|
||||
|
||||
@@ -90,7 +111,7 @@ final class GameRecordService
|
||||
*/
|
||||
public static function isLiveRuntimeEnabled(): bool
|
||||
{
|
||||
return self::getConfigBool(self::KEY_AUTO_CREATE);
|
||||
return self::isAutoCreateEnabled();
|
||||
}
|
||||
|
||||
public static function setLiveRuntimeEnabled(bool $enabled): void
|
||||
@@ -103,7 +124,7 @@ final class GameRecordService
|
||||
*/
|
||||
public static function bootstrapPeriodWhenRuntimeEnabled(): void
|
||||
{
|
||||
if (!self::getConfigBool(self::KEY_AUTO_CREATE)) {
|
||||
if (!self::isAutoCreateEnabled()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@@ -116,6 +137,7 @@ final class GameRecordService
|
||||
{
|
||||
$now = time();
|
||||
$v = $enabled ? '1' : '0';
|
||||
GameHotDataRedis::gameConfigForget(self::KEY_AUTO_CREATE);
|
||||
self::upsertConfig(self::KEY_AUTO_CREATE, $v, 'int', '是否允许自动创建下一局(全局仅一局)', $now);
|
||||
}
|
||||
|
||||
@@ -124,7 +146,7 @@ final class GameRecordService
|
||||
*/
|
||||
public static function createNextRecordRow(): string
|
||||
{
|
||||
$created = self::createNextRecordRowIfNoActive();
|
||||
$created = self::createNextRecordRowIfNoActive(false);
|
||||
if ($created === null) {
|
||||
throw new \RuntimeException((string) __('There is an unfinished round; cannot create a new one'));
|
||||
}
|
||||
@@ -134,9 +156,14 @@ final class GameRecordService
|
||||
|
||||
/**
|
||||
* 幂等插入下一期:有进行中局则不插入,返回 null。
|
||||
*
|
||||
* @param bool $requireAutoCreate true=须开启自动开局(定时/派彩后);false=手动创建下一期
|
||||
*/
|
||||
public static function createNextRecordRowIfNoActive(): ?string
|
||||
public static function createNextRecordRowIfNoActive(bool $requireAutoCreate = true): ?string
|
||||
{
|
||||
if ($requireAutoCreate && !self::isAutoCreateEnabled()) {
|
||||
return null;
|
||||
}
|
||||
$lock = GameHotDataLock::tryAcquireWithWait(GameHotDataLock::TYPE_GAME_RECORD, self::AUTO_CREATE_LOCK_KEY, 1500);
|
||||
if (!$lock['acquired']) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user