菜单和部分接口返回对语言进行适配

This commit is contained in:
2026-04-20 10:27:01 +08:00
parent 24aab111b5
commit 025cce3e3e
5 changed files with 209 additions and 24 deletions

View File

@@ -159,27 +159,27 @@ final class GameLiveService
{
$record = self::resolveRecord($recordId);
if (!$record) {
return ['ok' => false, 'msg' => '未找到进行中的对局'];
return ['ok' => false, 'msg' => __('No active game in progress')];
}
if (!in_array((int) $record['status'], [0, 1], true)) {
return ['ok' => false, 'msg' => '当前对局状态不可计算'];
return ['ok' => false, 'msg' => __('Current game status does not allow calculation')];
}
$periodSeconds = self::getConfigInt(self::KEY_PERIOD_SECONDS, 30);
$betSeconds = self::getConfigInt(self::KEY_BET_SECONDS, 20);
$elapsed = max(0, time() - (int) $record['period_start_at']);
if ($elapsed < $betSeconds) {
return ['ok' => false, 'msg' => '下注开放时长未结束,暂不可计算'];
return ['ok' => false, 'msg' => __('Betting period has not ended; calculation is not available yet')];
}
self::ensureAiLocked((int) $record['id']);
$record = self::reloadRecord((int) $record['id']);
if (!$record) {
return ['ok' => false, 'msg' => '未找到进行中的对局'];
return ['ok' => false, 'msg' => __('No active game in progress')];
}
$pickMax = self::getPickMaxNumberCount();
if ($manualNumber !== null && ($manualNumber < 1 || $manualNumber > self::DRAW_NUMBER_MAX)) {
return ['ok' => false, 'msg' => '手动开奖号码超出允许范围'];
return ['ok' => false, 'msg' => __('Manual draw number is out of the allowed range')];
}
$bets = Db::name('bet_order')->where('period_id', (int) $record['id'])->select()->toArray();
@@ -215,7 +215,7 @@ final class GameLiveService
return [
'ok' => true,
'msg' => '计算完成',
'msg' => __('Calculation completed'),
'record' => $record,
'period_seconds' => $periodSeconds,
'bet_seconds' => $betSeconds,
@@ -234,23 +234,23 @@ final class GameLiveService
public static function scheduleDraw(?int $recordId, int $manualNumber): array
{
if ($manualNumber < 1 || $manualNumber > self::DRAW_NUMBER_MAX) {
return ['ok' => false, 'msg' => '开奖号码超出允许范围'];
return ['ok' => false, 'msg' => __('Draw number is out of the allowed range')];
}
$record = self::resolveRecord($recordId);
if (!$record) {
return ['ok' => false, 'msg' => '未找到进行中的对局'];
return ['ok' => false, 'msg' => __('No active game in progress')];
}
if (!in_array((int) $record['status'], [0, 1], true)) {
return ['ok' => false, 'msg' => '当前对局状态不可预约开奖'];
return ['ok' => false, 'msg' => __('Current game status does not allow scheduling the draw')];
}
$periodSeconds = self::getConfigInt(self::KEY_PERIOD_SECONDS, 30);
$betSeconds = self::getConfigInt(self::KEY_BET_SECONDS, 20);
$elapsed = max(0, time() - (int) $record['period_start_at']);
if ($elapsed < $betSeconds) {
return ['ok' => false, 'msg' => '下注尚未结束,无法预约开奖'];
return ['ok' => false, 'msg' => __('Betting has not ended; cannot schedule the draw')];
}
if ($elapsed >= $periodSeconds) {
return ['ok' => false, 'msg' => '本期倒计时已结束,请刷新页面'];
return ['ok' => false, 'msg' => __('This period has ended; please refresh the page')];
}
self::ensureAiLocked((int) $record['id']);
@@ -258,11 +258,12 @@ final class GameLiveService
'pending_draw_number' => $manualNumber,
'update_time' => time(),
]);
GameHotDataRedis::gameRecordForget((int) $record['id']);
self::publishSnapshot(null);
return [
'ok' => true,
'msg' => '已预约本期开奖号码,倒计时结束后将使用该号码开奖',
'msg' => __('Draw number scheduled; it will be used when the countdown ends'),
];
}
@@ -273,25 +274,25 @@ final class GameLiveService
{
$record = self::resolveRecord($recordId);
if (!$record) {
return ['ok' => false, 'msg' => '未找到进行中的对局'];
return ['ok' => false, 'msg' => __('No active game in progress')];
}
if (!in_array((int) $record['status'], [0, 1], true)) {
return ['ok' => false, 'msg' => '当前对局状态不可开奖'];
return ['ok' => false, 'msg' => __('Current game status does not allow drawing')];
}
$periodSeconds = self::getConfigInt(self::KEY_PERIOD_SECONDS, 30);
$betSeconds = self::getConfigInt(self::KEY_BET_SECONDS, 20);
$elapsed = max(0, time() - (int) $record['period_start_at']);
if ($elapsed < $betSeconds) {
return ['ok' => false, 'msg' => '下注开放时长未结束,不可开奖'];
return ['ok' => false, 'msg' => __('Betting period has not ended; drawing is not available yet')];
}
if ($elapsed < $periodSeconds) {
return ['ok' => false, 'msg' => '本期倒计时未结束,无法开奖'];
return ['ok' => false, 'msg' => __('Period countdown has not ended; cannot draw yet')];
}
self::ensureAiLocked((int) $record['id']);
$record = self::reloadRecord((int) $record['id']);
if (!$record) {
return ['ok' => false, 'msg' => '未找到进行中的对局'];
return ['ok' => false, 'msg' => __('No active game in progress')];
}
$useManual = $manualNumber;
@@ -342,9 +343,11 @@ final class GameLiveService
Db::commit();
} catch (Throwable $e) {
Db::rollback();
return ['ok' => false, 'msg' => $e->getMessage()];
return ['ok' => false, 'msg' => __('Game live: settlement error') . ': ' . $e->getMessage()];
}
GameHotDataRedis::gameRecordForget((int) $record['id']);
try {
GameRecordStatService::refreshForRecordId((int) $record['id']);
} catch (Throwable) {
@@ -357,7 +360,7 @@ final class GameLiveService
return [
'ok' => true,
'msg' => '开奖完成,派彩中',
'msg' => __('Draw completed; paying out'),
'result_number' => $finalNumber,
'estimated_loss' => $finalLoss,
'payout_until' => $payoutUntil,
@@ -392,6 +395,7 @@ final class GameLiveService
Db::rollback();
return;
}
GameHotDataRedis::gameRecordForget($id);
GameRecordStatService::refreshForRecordId($id);
self::publishSnapshot(null);
}
@@ -565,17 +569,17 @@ final class GameLiveService
private static function resolveRecord(?int $recordId): ?array
{
if ($recordId !== null && $recordId > 0) {
$row = Db::name('game_record')->where('id', $recordId)->find();
$row = GameHotDataRedis::gameRecordById($recordId);
if ($row) {
return $row;
}
}
return Db::name('game_record')->whereIn('status', [0, 1, 2, 3])->order('id', 'desc')->find();
return GameHotDataRedis::gameRecordActive();
}
private static function reloadRecord(int $id): ?array
{
$row = Db::name('game_record')->where('id', $id)->find();
$row = GameHotDataRedis::gameRecordById($id);
return $row ?: null;
}
@@ -584,7 +588,7 @@ final class GameLiveService
*/
private static function ensureAiLocked(int $recordId): void
{
$record = Db::name('game_record')->where('id', $recordId)->find();
$record = GameHotDataRedis::gameRecordById($recordId);
if (!$record) {
return;
}
@@ -605,6 +609,7 @@ final class GameLiveService
'status' => 1,
'update_time' => time(),
]);
GameHotDataRedis::gameRecordForget($recordId);
$record['status'] = 1;
self::publishPublicPeriodLocked($record);
}
@@ -624,6 +629,7 @@ final class GameLiveService
$update['status'] = 1;
}
Db::name('game_record')->where('id', $recordId)->update($update);
GameHotDataRedis::gameRecordForget($recordId);
$record = array_merge($record, $update);
if ($st === 0) {
self::publishPublicPeriodLocked($record);
@@ -653,7 +659,7 @@ final class GameLiveService
private static function getConfigInt(string $key, int $default): int
{
$row = Db::name('game_config')->where('config_key', $key)->find();
$row = GameHotDataRedis::gameConfigRow($key);
if (!$row) {
return $default;
}