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; } }