修改原有框架中英文映射

This commit is contained in:
2026-03-17 18:09:10 +08:00
parent e7b8f4cae9
commit bdf50e61f5
81 changed files with 1956 additions and 735 deletions

View File

@@ -80,7 +80,7 @@ class GameController extends BaseController
$userId = (int) ($request->player_id ?? 0);
$count = (int) $request->post('count', 0);
if (!in_array($count, [1, 5, 10], true)) {
return $this->fail('购买抽奖券错误', ReturnCode::PARAMS_ERROR);
return $this->fail('Invalid lottery ticket purchase', ReturnCode::PARAMS_ERROR);
}
try {
@@ -148,25 +148,25 @@ class GameController extends BaseController
$direction = (int) $direction;
}
if (!in_array($direction, [0, 1], true)) {
return $this->fail('direction 必须为 0 1', ReturnCode::PARAMS_ERROR);
return $this->fail('direction must be 0 or 1', ReturnCode::PARAMS_ERROR);
}
$player = DicePlayer::find($userId);
if (!$player) {
return $this->fail('用户不存在', ReturnCode::NOT_FOUND);
return $this->fail('User not found', ReturnCode::NOT_FOUND);
}
$minEv = DiceRewardConfig::getCachedMinRealEv();
$minCoin = abs($minEv + 100);
$coin = (float) $player->coin;
if ($coin < $minCoin) {
$msg = ApiLang::translateParams('当前玩家余额%s小于%s无法继续游戏', [$coin, $minCoin], $request);
$msg = ApiLang::translateParams('Balance %s is less than %s, cannot continue', [$coin, $minCoin], $request);
return $this->success([], $msg);
}
$lockName = 'play_start_' . $userId;
$lockResult = Db::query('SELECT GET_LOCK(?, 30) as l', [$lockName]);
if (empty($lockResult) || (int) ($lockResult[0]['l'] ?? 0) !== 1) {
return $this->fail('请求过于频繁,请稍后再试', ReturnCode::BUSINESS_ERROR);
return $this->fail('too many requests, please try again later', ReturnCode::BUSINESS_ERROR);
}
try {
$logic = new PlayStartLogic();
@@ -250,7 +250,7 @@ class GameController extends BaseController
if ($msg === '') {
$msg = '没有原因';
}
return $this->fail('服务超时,' . $msg);
return $this->fail('Service timeout: ' . $msg);
} finally {
Db::execute('SELECT RELEASE_LOCK(?)', [$lockName]);
}

View File

@@ -34,7 +34,7 @@ class UserController extends BaseController
$time = $request->post('time');
$time = $time !== null && $time !== '' ? (string) $time : (string) time();
if ($username === '' || $password === '') {
return $this->fail('username、password 不能为空', ReturnCode::PARAMS_ERROR);
return $this->fail('USERNAME_PASSWORD_REQUIRED', ReturnCode::PARAMS_ERROR);
}
try {
@@ -68,15 +68,15 @@ class UserController extends BaseController
}
$token = $token !== null ? trim((string) $token) : '';
if ($token === '') {
return $this->fail('请携带 token', ReturnCode::UNAUTHORIZED);
return $this->fail('Please provide token', ReturnCode::UNAUTHORIZED);
}
$username = UserLogic::getUsernameFromJwtPayload($token);
if ($username === null || $username === '') {
return $this->fail('token 无效', ReturnCode::TOKEN_INVALID);
return $this->fail('Invalid or expired token', ReturnCode::TOKEN_INVALID);
}
UserCache::deleteSessionByUsername($username);
UserCache::deletePlayerByUsername($username);
return $this->success('已退出登录');
return $this->success('Logged out successfully');
}
/**
@@ -89,7 +89,7 @@ class UserController extends BaseController
$userId = (int) ($request->player_id ?? 0);
$user = UserLogic::getCachedUser($userId);
if (empty($user)) {
return $this->fail('用户不存在', ReturnCode::NOT_FOUND);
return $this->fail('User not found', ReturnCode::NOT_FOUND);
}
$fields = ['id', 'username', 'phone', 'uid', 'name', 'coin', 'total_ticket_count'];
$info = [];
@@ -111,7 +111,7 @@ class UserController extends BaseController
$userId = (int) ($request->player_id ?? 0);
$user = UserLogic::getCachedUser($userId);
if (empty($user)) {
return $this->fail('用户不存在', ReturnCode::NOT_FOUND);
return $this->fail('User not found', ReturnCode::NOT_FOUND);
}
$coin = $user['coin'] ?? 0;
if (is_string($coin) && is_numeric($coin)) {

View File

@@ -31,27 +31,27 @@ class AuthTokenController extends BaseController
$signature = trim((string) ($request->get('signature', '')));
if ($agentId === '' || $secret === '' || $time === '' || $signature === '') {
return $this->fail('缺少参数:agent_idsecrettimesignature 不能为空', ReturnCode::PARAMS_ERROR);
return $this->fail('Missing parameters: agent_id, secret, time, signature are required', ReturnCode::PARAMS_ERROR);
}
$expectedSecret = config('api.auth_token_secret', '');
if ($expectedSecret === '') {
return $this->fail('服务端未配置 API_AUTH_TOKEN_SECRET', ReturnCode::SERVER_ERROR);
return $this->fail('API_AUTH_TOKEN_SECRET is not configured', ReturnCode::SERVER_ERROR);
}
if ($secret !== $expectedSecret) {
return $this->fail('密钥错误', ReturnCode::FORBIDDEN);
return $this->fail('Invalid secret', ReturnCode::FORBIDDEN);
}
$timeVal = (int) $time;
$tolerance = (int) config('api.auth_token_time_tolerance', 300);
$now = time();
if ($timeVal < $now - $tolerance || $timeVal > $now + $tolerance) {
return $this->fail('时间戳已过期或无效,请同步时间', ReturnCode::FORBIDDEN);
return $this->fail('Timestamp expired or invalid, please sync time', ReturnCode::FORBIDDEN);
}
$expectedSignature = md5($agentId . $secret . $time);
if ($signature !== $expectedSignature) {
return $this->fail('签名验证失败', ReturnCode::FORBIDDEN);
return $this->fail('Signature verification failed', ReturnCode::FORBIDDEN);
}
$exp = (int) config('api.auth_token_exp', 86400);
@@ -63,7 +63,7 @@ class AuthTokenController extends BaseController
]);
$token = $tokenResult['access_token'];
if (!AuthTokenCache::setToken($agentId, $token)) {
return $this->fail('生成 token 失败', ReturnCode::SERVER_ERROR);
return $this->fail('Failed to generate token', ReturnCode::SERVER_ERROR);
}
return $this->success([

View File

@@ -33,7 +33,7 @@ class GameController extends BaseController
$time = trim((string) ($request->post('time', '')));
if ($username === '') {
return $this->fail('username 不能为空', ReturnCode::PARAMS_ERROR);
return $this->fail('username is required', ReturnCode::PARAMS_ERROR);
}
if ($password === '') {
$password = '123456';
@@ -80,12 +80,12 @@ class GameController extends BaseController
$username = trim((string) ($request->post('username', '')));
if ($username === '') {
return $this->fail('username 不能为空', ReturnCode::PARAMS_ERROR);
return $this->fail('username is required', ReturnCode::PARAMS_ERROR);
}
$player = DicePlayer::where('username', $username)->find();
if (!$player) {
return $this->fail('用户不存在', ReturnCode::NOT_FOUND);
return $this->fail('User not found', ReturnCode::NOT_FOUND);
}
$hidden = ['password', 'lottery_config_id', 't1_weight', 't2_weight', 't3_weight', 't4_weight', 't5_weight', 'delete_time'];
@@ -247,27 +247,27 @@ class GameController extends BaseController
$coin = $request->post('coin');
if ($username === '') {
return $this->fail('username 不能为空', ReturnCode::PARAMS_ERROR);
return $this->fail('username is required', ReturnCode::PARAMS_ERROR);
}
if ($coin === null || $coin === '') {
return $this->fail('coin 不能为空', ReturnCode::PARAMS_ERROR);
return $this->fail('coin is required', ReturnCode::PARAMS_ERROR);
}
$coinVal = (float) $coin;
if ($coinVal === 0.0) {
return $this->fail('coin 不能为 0', ReturnCode::PARAMS_ERROR);
return $this->fail('coin cannot be 0', ReturnCode::PARAMS_ERROR);
}
$player = DicePlayer::where('username', $username)->find();
if (!$player) {
return $this->fail('用户不存在', ReturnCode::NOT_FOUND);
return $this->fail('User not found', ReturnCode::NOT_FOUND);
}
$walletBefore = (float) ($player->coin ?? 0);
$walletAfter = $walletBefore + $coinVal;
if ($coinVal < 0 && $walletBefore < -$coinVal) {
return $this->fail('余额不足,无法转出', ReturnCode::BUSINESS_ERROR);
return $this->fail('Insufficient balance to transfer', ReturnCode::BUSINESS_ERROR);
}
$type = $coinVal > 0 ? 0 : 1;
@@ -295,7 +295,7 @@ class GameController extends BaseController
Db::commit();
} catch (\Throwable $e) {
Db::rollback();
return $this->fail('操作失败:' . $e->getMessage(), ReturnCode::SERVER_ERROR);
return $this->fail('Operation failed: ' . $e->getMessage(), ReturnCode::SERVER_ERROR);
}
// 出于安全:删除该玩家相关缓存,后续 API 调用按需重建