1.期号记录修改为纯数字

This commit is contained in:
2026-05-29 11:53:12 +08:00
parent 0aa0809ad1
commit f286fcc56f
5 changed files with 113 additions and 10 deletions

View File

@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
namespace app\common\library\game;
use support\think\Db;
/**
* 游戏期号:纯数字生成与对外展示格式化。
*/
final class GamePeriodNo
{
/**
* 生成下一期业务期号(纯数字字符串,递增)。
*/
public static function generateNext(): string
{
$maxIdRaw = Db::name('game_record')->max('id');
$maxId = filter_var($maxIdRaw, FILTER_VALIDATE_INT);
if ($maxId === false) {
$maxId = 0;
}
$maxNumericRow = Db::name('game_record')
->whereRaw("period_no REGEXP '^[0-9]+$'")
->fieldRaw('MAX(CAST(period_no AS UNSIGNED)) AS max_no')
->find();
$maxNumericRaw = is_array($maxNumericRow) ? ($maxNumericRow['max_no'] ?? null) : null;
$maxNumeric = filter_var($maxNumericRaw, FILTER_VALIDATE_INT);
if ($maxNumeric === false) {
$maxNumeric = 0;
}
$next = max($maxId, $maxNumeric) + 1;
return (string) $next;
}
/**
* 对外 API / 列表展示的纯数字期号;历史非数字期号回退为 period_id。
*/
public static function toDisplay(string $periodNo, int $periodId = 0): string
{
$trimmed = trim($periodNo);
if ($trimmed !== '' && ctype_digit($trimmed)) {
return $trimmed;
}
if ($periodId > 0) {
return (string) $periodId;
}
return $trimmed;
}
}

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace app\common\service;
use app\common\library\game\GamePeriodNo;
use support\think\Db;
use Throwable;
@@ -192,7 +193,7 @@ final class GameRecordService
private static function generatePeriodNo(): string
{
return date('Ymd-His') . '-' . substr(bin2hex(random_bytes(4)), 0, 8);
return GamePeriodNo::generateNext();
}
private static function truthyConfigInput(mixed $v): bool