修改原有框架中英文映射
This commit is contained in:
@@ -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]);
|
||||
}
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -31,27 +31,27 @@ class AuthTokenController extends BaseController
|
||||
$signature = trim((string) ($request->get('signature', '')));
|
||||
|
||||
if ($agentId === '' || $secret === '' || $time === '' || $signature === '') {
|
||||
return $this->fail('缺少参数:agent_id、secret、time、signature 不能为空', 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([
|
||||
|
||||
@@ -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 调用按需重建
|
||||
|
||||
@@ -2,151 +2,38 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* API 英文文案(请求头 lang=en 时使用)
|
||||
* key 为中文原文,value 为英文
|
||||
* API 英文文案(对外接口推荐:英文 key)
|
||||
* 请求头 lang=en 时使用,key 为英文错误码,value 为英文展示文案
|
||||
*/
|
||||
return [
|
||||
'success' => 'Success',
|
||||
'fail' => 'Fail',
|
||||
'username、password 不能为空' => 'username and password are required',
|
||||
'请携带 token' => 'Please provide token',
|
||||
'token 无效' => 'Invalid or expired token',
|
||||
'已退出登录' => 'Logged out successfully',
|
||||
'用户不存在' => 'User not found',
|
||||
'username 不能为空' => 'username is required',
|
||||
'密码错误' => 'Wrong password',
|
||||
'账号已被禁用,无法登录' => 'Account is disabled and cannot log in',
|
||||
'购买抽奖券错误' => 'Invalid lottery ticket purchase',
|
||||
'平台币不足' => 'Insufficient balance',
|
||||
'direction 必须为 0 或 1' => 'direction must be 0 or 1',
|
||||
'当前玩家余额%s小于%s无法继续游戏' => 'Balance %s is less than %s, cannot continue',
|
||||
'服务超时,' => 'Service timeout: ',
|
||||
'没有原因' => 'Unknown reason',
|
||||
'缺少参数:agent_id、secret、time、signature 不能为空' => 'Missing parameters: agent_id, secret, time, signature are required',
|
||||
'服务端未配置 API_AUTH_TOKEN_SECRET' => 'API_AUTH_TOKEN_SECRET is not configured',
|
||||
'密钥错误' => 'Invalid secret',
|
||||
'时间戳已过期或无效,请同步时间' => 'Timestamp expired or invalid, please sync time',
|
||||
'签名验证失败' => 'Signature verification failed',
|
||||
'生成 token 失败' => 'Failed to generate token',
|
||||
'coin 不能为空' => 'coin is required',
|
||||
'coin 不能为 0' => 'coin cannot be 0',
|
||||
'余额不足,无法转出' => 'Insufficient balance to transfer',
|
||||
'操作失败:' => 'Operation failed: ',
|
||||
'服务超时,没有原因' => 'Service timeout: Unknown reason',
|
||||
// PlayStartLogic / GameLogic
|
||||
'抽奖券不足' => 'Insufficient lottery tickets',
|
||||
'奖池配置不存在' => 'Lottery config not found',
|
||||
'配置ID %s 不存在或档位为空' => 'Config ID %s not found or tier is empty',
|
||||
'该方向下暂无可用路径配置' => 'No path config available for this direction',
|
||||
// Dice / pool config
|
||||
'奖池配置不存在(需 name=default)' => 'Lottery pool config not found (name=default required)',
|
||||
'暂无可用奖励配置' => 'No available reward config',
|
||||
'未找到 name=default 的奖池配置,请先创建' => 'No name=default pool config found, please create one first',
|
||||
// Dice / wallet & tickets
|
||||
'参数错误:需要有效的 player_id 和 type(3=加点,4=扣点)' => 'Invalid params: player_id and type are required (3=add, 4=deduct)',
|
||||
'平台币变动必须大于 0' => 'Coin change must be greater than 0',
|
||||
'玩家不存在' => 'Player not found',
|
||||
'扣点数量不能大于当前余额' => 'Deduct amount cannot exceed current balance',
|
||||
// Dice / reward config record
|
||||
'测试记录不存在' => 'Test record not found',
|
||||
'付费奖池配置不存在' => 'Paid pool config not found',
|
||||
'免费奖池配置不存在' => 'Free pool config not found',
|
||||
'各抽奖次数仅支持 0、100、500、1000、5000' => 'Counts only support 0, 100, 500, 1000, 5000',
|
||||
'付费或免费至少一种方向次数之和大于 0' => 'Sum of paid/free direction counts must be greater than 0',
|
||||
'付费未选择奖池配置时,请填写付费自定义档位概率(T1~T5)' => 'When paid pool is not selected, please fill paid custom tier probabilities (T1–T5)',
|
||||
'付费档位概率每档只能 0-100%' => 'Paid tier probability must be between 0 and 100%',
|
||||
'付费档位概率 T1~T5 之和不能超过 100%' => 'Paid tier probabilities (T1–T5) sum cannot exceed 100%',
|
||||
'免费未选择奖池配置时,请填写免费自定义档位概率(T1~T5)' => 'When free pool is not selected, please fill free custom tier probabilities (T1–T5)',
|
||||
'免费档位概率每档只能 0-100%' => 'Free tier probability must be between 0 and 100%',
|
||||
'免费档位概率 T1~T5 之和不能超过 100%' => 'Free tier probabilities (T1–T5) sum cannot exceed 100%',
|
||||
// Dice / reward
|
||||
'存在无效的配置ID' => 'Invalid config ID exists',
|
||||
'存在无效的 DiceReward id' => 'Invalid DiceReward id exists',
|
||||
'奖励配置为空,请先维护 dice_reward_config' => 'Reward config is empty, please maintain dice_reward_config first',
|
||||
// Dice / reward_config
|
||||
'测试次数仅支持 100、500、1000、5000、10000' => 'Test count only supports 100, 500, 1000, 5000, 10000',
|
||||
// SaiAdmin permissions & auth
|
||||
'没有权限操作该部门数据' => 'No permission to operate department data',
|
||||
'没有权限操作该角色数据' => 'No permission to operate role data',
|
||||
'没有权限操作该数据' => 'No permission to operate this data',
|
||||
'禁止批量删除操作' => 'Batch delete is not allowed',
|
||||
'超级管理员禁止删除' => 'Super admin cannot be deleted',
|
||||
'原密码错误' => 'Old password is incorrect',
|
||||
'上级部门和当前部门不能相同' => 'Parent department cannot be the same as current department',
|
||||
'不能将上级部门设置为当前部门的子部门' => 'Cannot set parent department to a child of current department',
|
||||
'该部门下存在子部门,请先删除子部门' => 'This department has sub-departments, please delete them first',
|
||||
'该部门下存在用户,请先删除或者转移用户' => 'This department has users, please delete or transfer them first',
|
||||
'您的登录凭证错误或者已过期,请重新登录' => 'Your login credential is invalid or expired, please login again',
|
||||
'登录凭证校验失败' => 'Login credential verification failed',
|
||||
// Saipackage install
|
||||
'插件的基础配置信息错误' => 'Plugin base config is invalid',
|
||||
'插件已经存在' => 'Plugin already exists',
|
||||
'该插件的安装目录已经被占用' => 'Plugin install directory is already occupied',
|
||||
'文件不存在' => 'File not found',
|
||||
// UserLogic
|
||||
'手机号格式错误,仅支持 +60 开头的马来西亚号码(如 +60123456789)' => 'Invalid phone format, only +60 Malaysia numbers supported (e.g. +60123456789)',
|
||||
// TokenMiddleware / Auth (api/user/*, api/game/*)
|
||||
'请携带 auth-token' => 'Please provide auth-token',
|
||||
'auth-token 已过期' => 'auth-token expired',
|
||||
'auth-token 无效' => 'auth-token invalid',
|
||||
'auth-token 格式无效' => 'auth-token format invalid',
|
||||
'auth-token 无效或已失效' => 'auth-token invalid or expired',
|
||||
'token 已过期,请重新登录' => 'Token expired, please login again',
|
||||
'token 格式无效' => 'Token format invalid',
|
||||
'请注册' => 'Please register',
|
||||
'请重新登录' => 'Please login again',
|
||||
'请重新登录(当前账号已在其他处登录)' => 'Please login again (account logged in elsewhere)',
|
||||
// DiceRewardLogic 动态文案(占位符)
|
||||
'奖励配置需覆盖 26 个格位(id 0-25 或 1-26),当前仅 %s 条,无法完整生成 5-30 共26个点数、顺时针与逆时针的奖励对照' => 'Reward config must cover 26 cells (id 0-25 or 1-26), currently only %s, cannot generate full 5-30 points and clockwise/counterclockwise mapping',
|
||||
// SystemUserLogic / BaseController 等(validate 等动态 message 无 key,保留原文)
|
||||
// CheckLogin
|
||||
// BaseLogic / Crontab / Menu / Post / Role / Dict / Config / Category / Attachment / Database
|
||||
'数据不存在' => 'Data not found',
|
||||
'不能设置父级为自身' => 'Cannot set parent to self',
|
||||
'该菜单下存在子菜单,请先删除子菜单' => 'This menu has sub-menus, please delete them first',
|
||||
'导入文件错误,请上传正确的文件格式xlsx' => 'Import file error, please upload correct xlsx file',
|
||||
'不能操作比当前账户职级高的角色' => 'Cannot operate roles with higher level than current account',
|
||||
'该字典标识已存在' => 'This dict code already exists',
|
||||
'修改数据异常,请检查' => 'Update data error, please check',
|
||||
'删除数据异常,请检查' => 'Delete data error, please check',
|
||||
'字典类型不存在' => 'Dict type not found',
|
||||
'配置数据未找到' => 'Config data not found',
|
||||
'系统默认分组,无法删除' => 'System default group cannot be deleted',
|
||||
'配置组未找到' => 'Config group not found',
|
||||
'上级分类和当前分类不能相同' => 'Parent category cannot be the same as current',
|
||||
'不能将上级分类设置为当前分类的子分类' => 'Cannot set parent category as child of current',
|
||||
'该部门下存在子分类,请先删除子分类' => 'This category has sub-categories, please delete them first',
|
||||
'目标分类不存在' => 'Target category not found',
|
||||
'获取文件资源失败' => 'Failed to get file resource',
|
||||
'创建图片资源失败' => 'Failed to create image resource',
|
||||
'文件格式错误' => 'Invalid file format',
|
||||
'文件保存失败' => 'Failed to save file',
|
||||
'当前表不支持回收站功能' => 'Current table does not support recycle bin',
|
||||
'模板不存在' => 'Template not found',
|
||||
'任务类型异常' => 'Invalid task type',
|
||||
'数据库配置读取失败' => 'Failed to read database config',
|
||||
'应用类型必须为plugin或者app' => 'App type must be plugin or app',
|
||||
'请先设置应用名称' => 'Please set app name first',
|
||||
'请选择要生成的表' => 'Please select tables to generate',
|
||||
'非调试模式下,不允许生成文件' => 'File generation not allowed in non-debug mode',
|
||||
'登录凭获取失败,请检查' => 'Failed to get login credential, please check',
|
||||
'文件大小超过限制' => 'File size exceeds limit',
|
||||
'不支持该格式的文件上传' => 'File format not supported for upload',
|
||||
'该上传模式不存在' => 'Upload mode not found',
|
||||
'切片上传服务必须在 HTTP 请求环境下调用' => 'Chunk upload must be called in HTTP request context',
|
||||
'切片文件查找失败,请重新上传' => 'Chunk file not found, please upload again',
|
||||
'未设置邮件配置' => 'Mail config not set',
|
||||
'请执行 composer require phpmailer/phpmailer 并重启' => 'Please run composer require phpmailer/phpmailer and restart',
|
||||
'仅超级管理员能够操作' => 'Only super admin can perform this action',
|
||||
'等待依赖安装' => 'Waiting for dependencies to be installed',
|
||||
'插件目录不存在' => 'Plugin directory not found',
|
||||
'该插件的基础配置信息不完善' => 'Plugin base config is incomplete',
|
||||
'参数错误' => 'Invalid parameters',
|
||||
'不能设置父级为自身' => 'Cannot set parent to self',
|
||||
'该分类下存在子分类,请先删除子分类' => 'This category has sub-categories, please delete them first',
|
||||
'无法打开文件,或者文件创建失败' => 'Cannot open file or create file failed',
|
||||
'系统生成文件错误' => 'System file generation error',
|
||||
'模板目录不存在!' => 'Template directory not found',
|
||||
'文件类型异常,无法生成指定文件!' => 'Invalid file type, cannot generate file',
|
||||
'前端目录查找失败,必须与后端目录为同级目录!' => 'Frontend directory not found, must be same level as backend',
|
||||
'SUCCESS' => 'Success',
|
||||
'FAIL' => 'Fail',
|
||||
'TOKEN_REQUIRED' => 'Please provide token',
|
||||
'TOKEN_INVALID' => 'Invalid or expired token',
|
||||
'TOKEN_EXPIRED_RELOGIN' => 'Token expired, please login again',
|
||||
'TOKEN_FORMAT_INVALID' => 'Token format invalid',
|
||||
'AUTH_TOKEN_REQUIRED' => 'Please provide auth-token',
|
||||
'AUTH_TOKEN_EXPIRED' => 'auth-token expired',
|
||||
'AUTH_TOKEN_INVALID' => 'auth-token invalid',
|
||||
'AUTH_TOKEN_FORMAT_INVALID' => 'auth-token format invalid',
|
||||
'AUTH_TOKEN_INVALID_OR_EXPIRED' => 'auth-token invalid or expired',
|
||||
'USER_NOT_FOUND' => 'User not found',
|
||||
'USERNAME_REQUIRED' => 'username is required',
|
||||
'USERNAME_PASSWORD_REQUIRED' => 'username and password are required',
|
||||
'PASSWORD_WRONG' => 'Wrong password',
|
||||
'ACCOUNT_DISABLED' => 'Account is disabled and cannot log in',
|
||||
'BUY_TICKET_ERROR' => 'Invalid lottery ticket purchase',
|
||||
'INSUFFICIENT_BALANCE' => 'Insufficient balance',
|
||||
'INSUFFICIENT_TICKETS' => 'Insufficient lottery tickets',
|
||||
'DIRECTION_INVALID' => 'direction must be 0 or 1',
|
||||
'BALANCE_LESS_THAN_MIN' => 'Balance %s is less than %s, cannot continue',
|
||||
'LOTTERY_CONFIG_NOT_FOUND' => 'Lottery config not found',
|
||||
'LOTTERY_POOL_CONFIG_NOT_FOUND_DEFAULT' => 'Lottery pool config not found (name=default required)',
|
||||
'LOTTERY_POOL_CONFIG_DEFAULT_NOT_FOUND' => 'No name=default pool config found, please create one first',
|
||||
'NO_AVAILABLE_REWARD_CONFIG' => 'No available reward config',
|
||||
'CONFIG_ID_NOT_FOUND_OR_TIER_EMPTY' => 'Config ID %s not found or tier is empty',
|
||||
'DATA_NOT_FOUND' => 'Data not found',
|
||||
'BATCH_DELETE_FORBIDDEN' => 'Batch delete is not allowed',
|
||||
'SUPER_ADMIN_CANNOT_DELETE' => 'Super admin cannot be deleted',
|
||||
'OLD_PASSWORD_WRONG' => 'Old password is incorrect',
|
||||
];
|
||||
|
||||
150
server/app/api/lang/legacy_en.php
Normal file
150
server/app/api/lang/legacy_en.php
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* 旧版兼容:中文 => 英文 映射表
|
||||
* 历史代码中大量直接抛中文/返回中文 message,lang=en 时用于兼容翻译。
|
||||
* 新版推荐使用英文错误码(key)+ resource/translations/api/{zh,en}.php。
|
||||
*/
|
||||
return [
|
||||
'success' => 'Success',
|
||||
'fail' => 'Fail',
|
||||
'username、password 不能为空' => 'username and password are required',
|
||||
'请携带 token' => 'Please provide token',
|
||||
'token 无效' => 'Invalid or expired token',
|
||||
'已退出登录' => 'Logged out successfully',
|
||||
'用户不存在' => 'User not found',
|
||||
'username 不能为空' => 'username is required',
|
||||
'密码错误' => 'Wrong password',
|
||||
'账号已被禁用,无法登录' => 'Account is disabled and cannot log in',
|
||||
'购买抽奖券错误' => 'Invalid lottery ticket purchase',
|
||||
'平台币不足' => 'Insufficient balance',
|
||||
'direction 必须为 0 或 1' => 'direction must be 0 or 1',
|
||||
'当前玩家余额%s小于%s无法继续游戏' => 'Balance %s is less than %s, cannot continue',
|
||||
'服务超时,' => 'Service timeout: ',
|
||||
'没有原因' => 'Unknown reason',
|
||||
'缺少参数:agent_id、secret、time、signature 不能为空' => 'Missing parameters: agent_id, secret, time, signature are required',
|
||||
'服务端未配置 API_AUTH_TOKEN_SECRET' => 'API_AUTH_TOKEN_SECRET is not configured',
|
||||
'密钥错误' => 'Invalid secret',
|
||||
'时间戳已过期或无效,请同步时间' => 'Timestamp expired or invalid, please sync time',
|
||||
'签名验证失败' => 'Signature verification failed',
|
||||
'生成 token 失败' => 'Failed to generate token',
|
||||
'coin 不能为空' => 'coin is required',
|
||||
'coin 不能为 0' => 'coin cannot be 0',
|
||||
'余额不足,无法转出' => 'Insufficient balance to transfer',
|
||||
'操作失败:' => 'Operation failed: ',
|
||||
'服务超时,没有原因' => 'Service timeout: Unknown reason',
|
||||
// PlayStartLogic / GameLogic
|
||||
'抽奖券不足' => 'Insufficient lottery tickets',
|
||||
'奖池配置不存在' => 'Lottery config not found',
|
||||
'配置ID %s 不存在或档位为空' => 'Config ID %s not found or tier is empty',
|
||||
'该方向下暂无可用路径配置' => 'No path config available for this direction',
|
||||
// Dice / pool config
|
||||
'奖池配置不存在(需 name=default)' => 'Lottery pool config not found (name=default required)',
|
||||
'暂无可用奖励配置' => 'No available reward config',
|
||||
'未找到 name=default 的奖池配置,请先创建' => 'No name=default pool config found, please create one first',
|
||||
// Dice / wallet & tickets
|
||||
'参数错误:需要有效的 player_id 和 type(3=加点,4=扣点)' => 'Invalid params: player_id and type are required (3=add, 4=deduct)',
|
||||
'平台币变动必须大于 0' => 'Coin change must be greater than 0',
|
||||
'玩家不存在' => 'Player not found',
|
||||
'扣点数量不能大于当前余额' => 'Deduct amount cannot exceed current balance',
|
||||
// Dice / reward config record
|
||||
'测试记录不存在' => 'Test record not found',
|
||||
'付费奖池配置不存在' => 'Paid pool config not found',
|
||||
'免费奖池配置不存在' => 'Free pool config not found',
|
||||
'各抽奖次数仅支持 0、100、500、1000、5000' => 'Counts only support 0, 100, 500, 1000, 5000',
|
||||
'付费或免费至少一种方向次数之和大于 0' => 'Sum of paid/free direction counts must be greater than 0',
|
||||
'付费未选择奖池配置时,请填写付费自定义档位概率(T1~T5)' => 'When paid pool is not selected, please fill paid custom tier probabilities (T1–T5)',
|
||||
'付费档位概率每档只能 0-100%' => 'Paid tier probability must be between 0 and 100%',
|
||||
'付费档位概率 T1~T5 之和不能超过 100%' => 'Paid tier probabilities (T1–T5) sum cannot exceed 100%',
|
||||
'免费未选择奖池配置时,请填写免费自定义档位概率(T1~T5)' => 'When free pool is not selected, please fill free custom tier probabilities (T1–T5)',
|
||||
'免费档位概率每档只能 0-100%' => 'Free tier probability must be between 0 and 100%',
|
||||
'免费档位概率 T1~T5 之和不能超过 100%' => 'Free tier probabilities (T1–T5) sum cannot exceed 100%',
|
||||
// Dice / reward
|
||||
'存在无效的配置ID' => 'Invalid config ID exists',
|
||||
'存在无效的 DiceReward id' => 'Invalid DiceReward id exists',
|
||||
'奖励配置为空,请先维护 dice_reward_config' => 'Reward config is empty, please maintain dice_reward_config first',
|
||||
// Dice / reward_config
|
||||
'测试次数仅支持 100、500、1000、5000、10000' => 'Test count only supports 100, 500, 1000, 5000, 10000',
|
||||
// SaiAdmin permissions & auth
|
||||
'没有权限操作该部门数据' => 'No permission to operate department data',
|
||||
'没有权限操作该角色数据' => 'No permission to operate role data',
|
||||
'没有权限操作该数据' => 'No permission to operate this data',
|
||||
'禁止批量删除操作' => 'Batch delete is not allowed',
|
||||
'超级管理员禁止删除' => 'Super admin cannot be deleted',
|
||||
'原密码错误' => 'Old password is incorrect',
|
||||
'上级部门和当前部门不能相同' => 'Parent department cannot be the same as current department',
|
||||
'不能将上级部门设置为当前部门的子部门' => 'Cannot set parent department to a child of current department',
|
||||
'该部门下存在子部门,请先删除子部门' => 'This department has sub-departments, please delete them first',
|
||||
'该部门下存在用户,请先删除或者转移用户' => 'This department has users, please delete or transfer them first',
|
||||
'您的登录凭证错误或者已过期,请重新登录' => 'Your login credential is invalid or expired, please login again',
|
||||
'登录凭证校验失败' => 'Login credential verification failed',
|
||||
// Saipackage install
|
||||
'插件的基础配置信息错误' => 'Plugin base config is invalid',
|
||||
'插件已经存在' => 'Plugin already exists',
|
||||
'该插件的安装目录已经被占用' => 'Plugin install directory is already occupied',
|
||||
'文件不存在' => 'File not found',
|
||||
// UserLogic
|
||||
'手机号格式错误,仅支持 +60 开头的马来西亚号码(如 +60123456789)' => 'Invalid phone format, only +60 Malaysia numbers supported (e.g. +60123456789)',
|
||||
// TokenMiddleware / Auth (api/user/*, api/game/*)
|
||||
'请携带 auth-token' => 'Please provide auth-token',
|
||||
'auth-token 已过期' => 'auth-token expired',
|
||||
'auth-token 无效' => 'auth-token invalid',
|
||||
'auth-token 格式无效' => 'auth-token format invalid',
|
||||
'auth-token 无效或已失效' => 'auth-token invalid or expired',
|
||||
'token 已过期,请重新登录' => 'Token expired, please login again',
|
||||
'token 格式无效' => 'Token format invalid',
|
||||
'请注册' => 'Please register',
|
||||
'请重新登录' => 'Please login again',
|
||||
'请重新登录(当前账号已在其他处登录)' => 'Please login again (account logged in elsewhere)',
|
||||
// DiceRewardLogic 动态文案(占位符)
|
||||
'奖励配置需覆盖 26 个格位(id 0-25 或 1-26),当前仅 %s 条,无法完整生成 5-30 共26个点数、顺时针与逆时针的奖励对照' => 'Reward config must cover 26 cells (id 0-25 or 1-26), currently only %s, cannot generate full 5-30 points and clockwise/counterclockwise mapping',
|
||||
// 通用
|
||||
'数据不存在' => 'Data not found',
|
||||
'不能设置父级为自身' => 'Cannot set parent to self',
|
||||
'该菜单下存在子菜单,请先删除子菜单' => 'This menu has sub-menus, please delete them first',
|
||||
'导入文件错误,请上传正确的文件格式xlsx' => 'Import file error, please upload correct xlsx file',
|
||||
'不能操作比当前账户职级高的角色' => 'Cannot operate roles with higher level than current account',
|
||||
'该字典标识已存在' => 'This dict code already exists',
|
||||
'修改数据异常,请检查' => 'Update data error, please check',
|
||||
'删除数据异常,请检查' => 'Delete data error, please check',
|
||||
'字典类型不存在' => 'Dict type not found',
|
||||
'配置数据未找到' => 'Config data not found',
|
||||
'系统默认分组,无法删除' => 'System default group cannot be deleted',
|
||||
'配置组未找到' => 'Config group not found',
|
||||
'上级分类和当前分类不能相同' => 'Parent category cannot be the same as current',
|
||||
'不能将上级分类设置为当前分类的子分类' => 'Cannot set parent category as child of current',
|
||||
'该部门下存在子分类,请先删除子分类' => 'This category has sub-categories, please delete them first',
|
||||
'目标分类不存在' => 'Target category not found',
|
||||
'获取文件资源失败' => 'Failed to get file resource',
|
||||
'创建图片资源失败' => 'Failed to create image resource',
|
||||
'文件格式错误' => 'Invalid file format',
|
||||
'文件保存失败' => 'Failed to save file',
|
||||
'当前表不支持回收站功能' => 'Current table does not support recycle bin',
|
||||
'模板不存在' => 'Template not found',
|
||||
'任务类型异常' => 'Invalid task type',
|
||||
'数据库配置读取失败' => 'Failed to read database config',
|
||||
'应用类型必须为plugin或者app' => 'App type must be plugin or app',
|
||||
'请先设置应用名称' => 'Please set app name first',
|
||||
'请选择要生成的表' => 'Please select tables to generate',
|
||||
'非调试模式下,不允许生成文件' => 'File generation not allowed in non-debug mode',
|
||||
'登录凭获取失败,请检查' => 'Failed to get login credential, please check',
|
||||
'文件大小超过限制' => 'File size exceeds limit',
|
||||
'不支持该格式的文件上传' => 'File format not supported for upload',
|
||||
'该上传模式不存在' => 'Upload mode not found',
|
||||
'切片上传服务必须在 HTTP 请求环境下调用' => 'Chunk upload must be called in HTTP request context',
|
||||
'切片文件查找失败,请重新上传' => 'Chunk file not found, please upload again',
|
||||
'未设置邮件配置' => 'Mail config not set',
|
||||
'请执行 composer require phpmailer/phpmailer 并重启' => 'Please run composer require phpmailer/phpmailer and restart',
|
||||
'仅超级管理员能够操作' => 'Only super admin can perform this action',
|
||||
'等待依赖安装' => 'Waiting for dependencies to be installed',
|
||||
'插件目录不存在' => 'Plugin directory not found',
|
||||
'该插件的基础配置信息不完善' => 'Plugin base config is incomplete',
|
||||
'参数错误' => 'Invalid parameters',
|
||||
'该分类下存在子分类,请先删除子分类' => 'This category has sub-categories, please delete them first',
|
||||
'无法打开文件,或者文件创建失败' => 'Cannot open file or create file failed',
|
||||
'系统生成文件错误' => 'System file generation error',
|
||||
'模板目录不存在!' => 'Template directory not found',
|
||||
'文件类型异常,无法生成指定文件!' => 'Invalid file type, cannot generate file',
|
||||
'前端目录查找失败,必须与后端目录为同级目录!' => 'Frontend directory not found, must be same level as backend',
|
||||
];
|
||||
40
server/app/api/lang/zh.php
Normal file
40
server/app/api/lang/zh.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* API 中文文案(对外接口推荐:英文 key)
|
||||
* 请求头 lang=zh 时使用,key 为英文错误码,value 为中文展示文案
|
||||
*/
|
||||
return [
|
||||
'SUCCESS' => '成功',
|
||||
'FAIL' => '失败',
|
||||
'TOKEN_REQUIRED' => '请携带 token',
|
||||
'TOKEN_INVALID' => 'token 无效',
|
||||
'TOKEN_EXPIRED_RELOGIN' => 'token 已过期,请重新登录',
|
||||
'TOKEN_FORMAT_INVALID' => 'token 格式无效',
|
||||
'AUTH_TOKEN_REQUIRED' => '请携带 auth-token',
|
||||
'AUTH_TOKEN_EXPIRED' => 'auth-token 已过期',
|
||||
'AUTH_TOKEN_INVALID' => 'auth-token 无效',
|
||||
'AUTH_TOKEN_FORMAT_INVALID' => 'auth-token 格式无效',
|
||||
'AUTH_TOKEN_INVALID_OR_EXPIRED' => 'auth-token 无效或已失效',
|
||||
'USER_NOT_FOUND' => '用户不存在',
|
||||
'USERNAME_REQUIRED' => 'username 不能为空',
|
||||
'USERNAME_PASSWORD_REQUIRED' => 'username、password 不能为空',
|
||||
'PASSWORD_WRONG' => '密码错误',
|
||||
'ACCOUNT_DISABLED' => '账号已被禁用,无法登录',
|
||||
'BUY_TICKET_ERROR' => '购买抽奖券错误',
|
||||
'INSUFFICIENT_BALANCE' => '平台币不足',
|
||||
'INSUFFICIENT_TICKETS' => '抽奖券不足',
|
||||
'DIRECTION_INVALID' => 'direction 必须为 0 或 1',
|
||||
'BALANCE_LESS_THAN_MIN' => '当前玩家余额%s小于%s无法继续游戏',
|
||||
'LOTTERY_CONFIG_NOT_FOUND' => '奖池配置不存在',
|
||||
'LOTTERY_POOL_CONFIG_NOT_FOUND_DEFAULT' => '奖池配置不存在(需 name=default)',
|
||||
'LOTTERY_POOL_CONFIG_DEFAULT_NOT_FOUND' => '未找到 name=default 的奖池配置,请先创建',
|
||||
'NO_AVAILABLE_REWARD_CONFIG' => '暂无可用奖励配置',
|
||||
'CONFIG_ID_NOT_FOUND_OR_TIER_EMPTY' => '配置ID %s 不存在或档位为空',
|
||||
'DATA_NOT_FOUND' => '数据不存在',
|
||||
'BATCH_DELETE_FORBIDDEN' => '禁止批量删除操作',
|
||||
'SUPER_ADMIN_CANNOT_DELETE' => '超级管理员禁止删除',
|
||||
'OLD_PASSWORD_WRONG' => '原密码错误',
|
||||
];
|
||||
|
||||
@@ -35,7 +35,7 @@ class GameLogic
|
||||
public function buyLotteryTickets(int $playerId, int $count): array
|
||||
{
|
||||
if (!isset(self::PACKAGES[$count])) {
|
||||
throw new ApiException('购买抽奖券错误');
|
||||
throw new ApiException('Invalid lottery ticket purchase');
|
||||
}
|
||||
$pack = self::PACKAGES[$count];
|
||||
$cost = $pack['coin'];
|
||||
@@ -45,11 +45,11 @@ class GameLogic
|
||||
|
||||
$player = DicePlayer::find($playerId);
|
||||
if (!$player) {
|
||||
throw new ApiException('用户不存在');
|
||||
throw new ApiException('User not found');
|
||||
}
|
||||
$coinBefore = (float) $player->coin;
|
||||
if ($coinBefore < $cost) {
|
||||
throw new ApiException('平台币不足');
|
||||
throw new ApiException('Insufficient balance');
|
||||
}
|
||||
|
||||
$coinAfter = $coinBefore - $cost;
|
||||
|
||||
@@ -53,7 +53,7 @@ class PlayStartLogic
|
||||
{
|
||||
$player = DicePlayer::find($playerId);
|
||||
if (!$player) {
|
||||
throw new ApiException('用户不存在');
|
||||
throw new ApiException('User not found');
|
||||
}
|
||||
|
||||
$minEv = DiceRewardConfig::getCachedMinRealEv();
|
||||
@@ -66,7 +66,7 @@ class PlayStartLogic
|
||||
$paid = (int) ($player->paid_ticket_count ?? 0);
|
||||
$free = (int) ($player->free_ticket_count ?? 0);
|
||||
if ($paid + $free <= 0) {
|
||||
throw new ApiException('抽奖券不足');
|
||||
throw new ApiException('Insufficient lottery tickets');
|
||||
}
|
||||
|
||||
$lotteryService = LotteryService::getOrCreate($playerId);
|
||||
@@ -74,7 +74,7 @@ class PlayStartLogic
|
||||
$configType0 = DiceLotteryPoolConfig::where('name', 'default')->find();
|
||||
$configType1 = DiceLotteryPoolConfig::where('name', 'killScore')->find();
|
||||
if (!$configType0) {
|
||||
throw new ApiException('奖池配置不存在(需 name=default)');
|
||||
throw new ApiException('Lottery pool config not found (name=default required)');
|
||||
}
|
||||
|
||||
// 玩家累计盈利:仅统计 lottery_config_id=type=0 的成功对局(中奖金额-100*局数)
|
||||
@@ -119,7 +119,7 @@ class PlayStartLogic
|
||||
}
|
||||
if ($chosen === null) {
|
||||
Log::error("多次摇取档位后仍无有效 DiceReward");
|
||||
throw new ApiException('暂无可用奖励配置');
|
||||
throw new ApiException('No available reward config');
|
||||
}
|
||||
|
||||
$startIndex = (int) ($chosen['start_index'] ?? 0);
|
||||
|
||||
@@ -29,7 +29,7 @@ class UserLogic
|
||||
public static function validatePhone(string $phone): void
|
||||
{
|
||||
if (!preg_match(self::PHONE_REGEX, $phone)) {
|
||||
throw new ApiException('手机号格式错误,仅支持 +60 开头的马来西亚号码(如 +60123456789)');
|
||||
throw new ApiException('Invalid phone format, only +60 Malaysia numbers supported (e.g. +60123456789)');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,17 +52,17 @@ class UserLogic
|
||||
{
|
||||
$username = trim($username);
|
||||
if ($username === '') {
|
||||
throw new ApiException('username 不能为空');
|
||||
throw new ApiException('username is required');
|
||||
}
|
||||
|
||||
$player = DicePlayer::where('username', $username)->find();
|
||||
if ($player) {
|
||||
if ((int) ($player->status ?? 1) === 0) {
|
||||
throw new ApiException('账号已被禁用,无法登录');
|
||||
throw new ApiException('Account is disabled and cannot log in');
|
||||
}
|
||||
$hashed = $this->hashPassword($password);
|
||||
if ($player->password !== $hashed) {
|
||||
throw new ApiException('密码错误');
|
||||
throw new ApiException('Wrong password');
|
||||
}
|
||||
$currentCoin = (float) $player->coin;
|
||||
$player->coin = $currentCoin + $coin;
|
||||
|
||||
@@ -25,31 +25,31 @@ class AuthTokenMiddleware implements MiddlewareInterface
|
||||
$token = $request->header('auth-token');
|
||||
$token = $token !== null ? trim((string) $token) : '';
|
||||
if ($token === '') {
|
||||
throw new ApiException('请携带 auth-token', ReturnCode::UNAUTHORIZED);
|
||||
throw new ApiException('Please provide auth-token', ReturnCode::UNAUTHORIZED);
|
||||
}
|
||||
|
||||
try {
|
||||
$decoded = JwtToken::verify(1, $token);
|
||||
} catch (JwtTokenExpiredException $e) {
|
||||
throw new ApiException('auth-token 已过期', ReturnCode::TOKEN_INVALID);
|
||||
throw new ApiException('auth-token expired', ReturnCode::TOKEN_INVALID);
|
||||
} catch (JwtTokenException $e) {
|
||||
throw new ApiException('auth-token 无效', ReturnCode::TOKEN_INVALID);
|
||||
throw new ApiException('auth-token invalid', ReturnCode::TOKEN_INVALID);
|
||||
} catch (\Throwable $e) {
|
||||
throw new ApiException('auth-token 格式无效', ReturnCode::TOKEN_INVALID);
|
||||
throw new ApiException('auth-token format invalid', ReturnCode::TOKEN_INVALID);
|
||||
}
|
||||
|
||||
$extend = $decoded['extend'] ?? [];
|
||||
if ((string) ($extend['plat'] ?? '') !== 'api_auth_token') {
|
||||
throw new ApiException('auth-token 无效', ReturnCode::TOKEN_INVALID);
|
||||
throw new ApiException('auth-token invalid', ReturnCode::TOKEN_INVALID);
|
||||
}
|
||||
$agentId = trim((string) ($extend['agent_id'] ?? ''));
|
||||
if ($agentId === '') {
|
||||
throw new ApiException('auth-token 无效', ReturnCode::TOKEN_INVALID);
|
||||
throw new ApiException('auth-token invalid', ReturnCode::TOKEN_INVALID);
|
||||
}
|
||||
|
||||
$currentToken = AuthTokenCache::getTokenByAgentId($agentId);
|
||||
if ($currentToken === null || $currentToken !== $token) {
|
||||
throw new ApiException('auth-token 无效或已失效', ReturnCode::TOKEN_INVALID);
|
||||
throw new ApiException('auth-token invalid or expired', ReturnCode::TOKEN_INVALID);
|
||||
}
|
||||
|
||||
$request->agent_id = $agentId;
|
||||
|
||||
@@ -32,38 +32,38 @@ class TokenMiddleware implements MiddlewareInterface
|
||||
}
|
||||
$token = $token !== null ? trim((string) $token) : '';
|
||||
if ($token === '') {
|
||||
throw new ApiException('请携带 token', ReturnCode::UNAUTHORIZED);
|
||||
throw new ApiException('Please provide token', ReturnCode::UNAUTHORIZED);
|
||||
}
|
||||
|
||||
try {
|
||||
$decoded = JwtToken::verify(1, $token);
|
||||
} catch (JwtTokenExpiredException $e) {
|
||||
throw new ApiException('token 已过期,请重新登录', ReturnCode::TOKEN_INVALID);
|
||||
throw new ApiException('Token expired, please login again', ReturnCode::TOKEN_INVALID);
|
||||
} catch (JwtTokenException $e) {
|
||||
throw new ApiException('token 无效', ReturnCode::TOKEN_INVALID);
|
||||
throw new ApiException('Invalid or expired token', ReturnCode::TOKEN_INVALID);
|
||||
} catch (\Throwable $e) {
|
||||
throw new ApiException('token 格式无效', ReturnCode::TOKEN_INVALID);
|
||||
throw new ApiException('Token format invalid', ReturnCode::TOKEN_INVALID);
|
||||
}
|
||||
|
||||
$extend = $decoded['extend'] ?? [];
|
||||
if ((string) ($extend['plat'] ?? '') !== 'api_login') {
|
||||
throw new ApiException('token 无效', ReturnCode::TOKEN_INVALID);
|
||||
throw new ApiException('Invalid or expired token', ReturnCode::TOKEN_INVALID);
|
||||
}
|
||||
$username = trim((string) ($extend['username'] ?? ''));
|
||||
if ($username === '') {
|
||||
throw new ApiException('token 无效', ReturnCode::TOKEN_INVALID);
|
||||
throw new ApiException('Invalid or expired token', ReturnCode::TOKEN_INVALID);
|
||||
}
|
||||
|
||||
$currentToken = UserCache::getSessionTokenByUsername($username);
|
||||
if ($currentToken === null || $currentToken === '') {
|
||||
$player = DicePlayer::where('username', $username)->find();
|
||||
if (!$player) {
|
||||
throw new ApiException('请注册', ReturnCode::TOKEN_INVALID);
|
||||
throw new ApiException('Please register', ReturnCode::TOKEN_INVALID);
|
||||
}
|
||||
throw new ApiException('请重新登录', ReturnCode::TOKEN_INVALID);
|
||||
throw new ApiException('Please login again', ReturnCode::TOKEN_INVALID);
|
||||
}
|
||||
if ($currentToken !== $token) {
|
||||
throw new ApiException('请重新登录(当前账号已在其他处登录)', ReturnCode::TOKEN_INVALID);
|
||||
throw new ApiException('Please login again (account logged in elsewhere)', ReturnCode::TOKEN_INVALID);
|
||||
}
|
||||
|
||||
// 优先从 Redis 缓存取玩家,避免每次请求都查库
|
||||
@@ -76,7 +76,7 @@ class TokenMiddleware implements MiddlewareInterface
|
||||
$player = DicePlayer::where('username', $username)->find();
|
||||
if (!$player) {
|
||||
UserCache::deleteSessionByUsername($username);
|
||||
throw new ApiException('请重新登录', ReturnCode::TOKEN_INVALID);
|
||||
throw new ApiException('Please login again', ReturnCode::TOKEN_INVALID);
|
||||
}
|
||||
UserCache::setPlayerByUsername($username, $player->hidden(['password'])->toArray());
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ class ApiLang
|
||||
private const LANG_EN = 'en';
|
||||
private const LANG_ZH = 'zh';
|
||||
|
||||
/** @var array<string, array<string, string>> locale => [ 中文 => 译文 ] */
|
||||
/** @var array<string, array<string, string>> lang => [ key => message ] */
|
||||
private static array $messages = [];
|
||||
|
||||
/**
|
||||
@@ -42,21 +42,31 @@ class ApiLang
|
||||
}
|
||||
|
||||
/**
|
||||
* 翻译文案:lang=zh 返回原文(中文),lang=en 返回英文映射
|
||||
* 语言文件优先从 Webman resource/translations/api/{locale}.php 加载,否则从 app/api/lang 加载
|
||||
* 翻译文案(对外接口 message):
|
||||
* - 推荐:抛英文 key(如 USER_NOT_FOUND),根据 lang 返回对应语言
|
||||
* - 兼容:仍抛中文原文时,lang=en 按旧映射翻译,否则原样返回
|
||||
*
|
||||
* 语言文件优先从 Webman config('translation.path')/api/{lang}.php 加载
|
||||
*/
|
||||
public static function translate(string $message, ?Request $request = null): string
|
||||
{
|
||||
$lang = self::getLang($request);
|
||||
if ($lang !== self::LANG_EN) {
|
||||
return $message;
|
||||
$map = self::loadMessages($lang);
|
||||
if (isset($map[$message])) {
|
||||
return (string) $map[$message];
|
||||
}
|
||||
$map = self::loadMessages(self::LANG_EN);
|
||||
return $map[$message] ?? $message;
|
||||
|
||||
// 若传入的是中文/原文,则按固定规则生成英文 key(MSG_XXXXXXXX)再翻译
|
||||
$key = self::toMsgKey($message);
|
||||
if ($key !== null && isset($map[$key])) {
|
||||
return (string) $map[$key];
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载某语言的 API 文案(key=中文,value=译文)
|
||||
* 加载某语言的 API 文案(推荐:key=英文,value=对应语言文案)
|
||||
*/
|
||||
private static function loadMessages(string $locale): array
|
||||
{
|
||||
@@ -70,13 +80,34 @@ class ApiLang
|
||||
$path = $base . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . $locale . '.php';
|
||||
}
|
||||
}
|
||||
if (($path === null || !is_file($path)) && $locale === self::LANG_EN) {
|
||||
$path = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR . 'en.php';
|
||||
if ($path !== null && is_file($path)) {
|
||||
self::$messages[$locale] = require $path;
|
||||
return self::$messages[$locale];
|
||||
}
|
||||
self::$messages[$locale] = ($path !== null && is_file($path)) ? (require $path) : [];
|
||||
|
||||
// 回退到 app/api/lang/{lang}.php(同样使用英文 key)
|
||||
$fallback = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR . $locale . '.php';
|
||||
self::$messages[$locale] = is_file($fallback) ? (require $fallback) : [];
|
||||
return self::$messages[$locale];
|
||||
}
|
||||
|
||||
/**
|
||||
* 将原文转换为英文 key(只包含英文字符/数字/下划线):MSG_XXXXXXXX(crc32)
|
||||
* 若入参已经是英文 key,则返回 null(表示无需转换)
|
||||
*/
|
||||
private static function toMsgKey(string $message): ?string
|
||||
{
|
||||
$trim = trim($message);
|
||||
if ($trim === '') {
|
||||
return null;
|
||||
}
|
||||
// 已经是英文错误码 key(只允许 A-Z/0-9/_,且至少 3 位)
|
||||
if (preg_match('/^[A-Z0-9_]{3,}$/', $trim) === 1) {
|
||||
return null;
|
||||
}
|
||||
return 'MSG_' . strtoupper(sprintf('%08X', crc32($trim)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 带占位符的翻译,如 translateParams('当前玩家余额%s小于%s无法继续游戏', [$coin, $minCoin])
|
||||
* 先翻译再替换(en 文案使用 %s 占位)
|
||||
|
||||
@@ -60,7 +60,7 @@ class DiceConfigController extends BaseController
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
} else {
|
||||
return $this->fail('未查找到信息');
|
||||
return $this->fail('not found');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,9 +76,9 @@ class DiceConfigController extends BaseController
|
||||
$this->validate('save', $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('添加成功');
|
||||
return $this->success('add success');
|
||||
} else {
|
||||
return $this->fail('添加失败');
|
||||
return $this->fail('add failed');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,9 +94,9 @@ class DiceConfigController extends BaseController
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
return $this->success('修改成功');
|
||||
return $this->success('update success');
|
||||
} else {
|
||||
return $this->fail('修改失败');
|
||||
return $this->fail('update failed');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,13 +110,13 @@ class DiceConfigController extends BaseController
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
return $this->fail('please select data to delete');
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
return $this->success('删除成功');
|
||||
return $this->success('delete success');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
return $this->fail('delete failed');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ class DiceLotteryPoolConfigController extends BaseController
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
} else {
|
||||
return $this->fail('未查找到信息');
|
||||
return $this->fail('not found');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,9 +101,9 @@ class DiceLotteryPoolConfigController extends BaseController
|
||||
$this->validate('save', $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('添加成功');
|
||||
return $this->success('add success');
|
||||
} else {
|
||||
return $this->fail('添加失败');
|
||||
return $this->fail('add failed');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,9 +119,9 @@ class DiceLotteryPoolConfigController extends BaseController
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
return $this->success('修改成功');
|
||||
return $this->success('update success');
|
||||
} else {
|
||||
return $this->fail('修改失败');
|
||||
return $this->fail('update failed');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,13 +135,13 @@ class DiceLotteryPoolConfigController extends BaseController
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
return $this->fail('please select data to delete');
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
return $this->success('删除成功');
|
||||
return $this->success('delete success');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
return $this->fail('delete failed');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ class DiceLotteryPoolConfigController extends BaseController
|
||||
* 获取当前彩金池(Redis 实例化,无则按 type=0 创建)
|
||||
* 返回含玩家累计盈利 profit_amount 实时值,供前端轮询展示
|
||||
*/
|
||||
#[Permission('色子奖池配置列表', 'dice:lottery_pool_config:index:index')]
|
||||
#[Permission('色子奖池配置列表', 'dice:lottery_pool_config:index:getCurrentPool')]
|
||||
public function getCurrentPool(Request $request): Response
|
||||
{
|
||||
$data = $this->logic->getCurrentPool();
|
||||
@@ -159,21 +159,21 @@ class DiceLotteryPoolConfigController extends BaseController
|
||||
/**
|
||||
* 更新当前彩金池:仅可修改 safety_line、t1_weight~t5_weight,不可修改 profit_amount
|
||||
*/
|
||||
#[Permission('色子奖池配置修改', 'dice:lottery_pool_config:index:update')]
|
||||
#[Permission('色子奖池配置修改', 'dice:lottery_pool_config:index:updateCurrentPool')]
|
||||
public function updateCurrentPool(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->logic->updateCurrentPool($data);
|
||||
return $this->success('保存成功');
|
||||
return $this->success('save success');
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置当前彩金池的玩家累计盈利:将 profit_amount 置为 0
|
||||
*/
|
||||
#[Permission('色子奖池配置修改', 'dice:lottery_pool_config:index:update')]
|
||||
#[Permission('色子奖池配置修改', 'dice:lottery_pool_config:index:resetProfitAmount')]
|
||||
public function resetProfitAmount(Request $request): Response
|
||||
{
|
||||
$this->logic->resetProfitAmount();
|
||||
return $this->success('重置成功');
|
||||
return $this->success('reset success');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,11 +120,11 @@ class DicePlayRecordController extends BaseController
|
||||
$id = $request->input('id', '');
|
||||
$model = $this->logic->read($id);
|
||||
if (!$model) {
|
||||
return $this->fail('未查找到信息');
|
||||
return $this->fail('not found');
|
||||
}
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||
return $this->fail('无权限查看该记录');
|
||||
return $this->fail('no permission to view this record');
|
||||
}
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
@@ -142,9 +142,9 @@ class DicePlayRecordController extends BaseController
|
||||
$this->validate('save', $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('添加成功');
|
||||
return $this->success('add success');
|
||||
} else {
|
||||
return $this->fail('添加失败');
|
||||
return $this->fail('add failed');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,9 +160,9 @@ class DicePlayRecordController extends BaseController
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
return $this->success('修改成功');
|
||||
return $this->success('update success');
|
||||
} else {
|
||||
return $this->fail('修改失败');
|
||||
return $this->fail('update failed');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,13 +176,13 @@ class DicePlayRecordController extends BaseController
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
return $this->fail('please select data to delete');
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
return $this->success('删除成功');
|
||||
return $this->success('delete success');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
return $this->fail('delete failed');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ class DicePlayRecordTestController extends BaseController
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
} else {
|
||||
return $this->fail('未查找到信息');
|
||||
return $this->fail('not found');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,9 +91,9 @@ class DicePlayRecordTestController extends BaseController
|
||||
$this->validate('save', $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('添加成功');
|
||||
return $this->success('add success');
|
||||
} else {
|
||||
return $this->fail('添加失败');
|
||||
return $this->fail('add failed');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,9 +109,9 @@ class DicePlayRecordTestController extends BaseController
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
return $this->success('修改成功');
|
||||
return $this->success('update success');
|
||||
} else {
|
||||
return $this->fail('修改失败');
|
||||
return $this->fail('update failed');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,13 +125,13 @@ class DicePlayRecordTestController extends BaseController
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
return $this->fail('please select data to delete');
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
return $this->success('删除成功');
|
||||
return $this->success('delete success');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
return $this->fail('delete failed');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,9 +146,9 @@ class DicePlayRecordTestController extends BaseController
|
||||
try {
|
||||
$table = (new \app\dice\model\play_record_test\DicePlayRecordTest())->getTable();
|
||||
Db::execute('TRUNCATE TABLE `' . $table . '`');
|
||||
return $this->success('已清空所有测试数据');
|
||||
return $this->success('all test data cleared');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->fail('清空失败:' . $e->getMessage());
|
||||
return $this->fail('clear failed: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,11 +110,11 @@ class DicePlayerController extends BaseController
|
||||
$id = $request->input('id', '');
|
||||
$model = $this->logic->read($id);
|
||||
if (!$model) {
|
||||
return $this->fail('未查找到信息');
|
||||
return $this->fail('not found');
|
||||
}
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||
return $this->fail('无权限查看该记录');
|
||||
return $this->fail('no permission to view this record');
|
||||
}
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
@@ -142,9 +142,9 @@ class DicePlayerController extends BaseController
|
||||
if ($player && $player->username !== '') {
|
||||
UserCache::deletePlayerByUsername($player->username);
|
||||
}
|
||||
return $this->success('添加成功');
|
||||
return $this->success('add success');
|
||||
}
|
||||
return $this->fail('添加失败');
|
||||
return $this->fail('add failed');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,7 +161,7 @@ class DicePlayerController extends BaseController
|
||||
if ($model) {
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||
return $this->fail('无权限修改该记录');
|
||||
return $this->fail('no permission to update this record');
|
||||
}
|
||||
}
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
@@ -172,9 +172,9 @@ class DicePlayerController extends BaseController
|
||||
if ($player && $player->username !== '') {
|
||||
UserCache::deletePlayerByUsername($player->username);
|
||||
}
|
||||
return $this->success('修改成功');
|
||||
return $this->success('update success');
|
||||
}
|
||||
return $this->fail('修改失败');
|
||||
return $this->fail('update failed');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -188,16 +188,16 @@ class DicePlayerController extends BaseController
|
||||
$id = $request->input('id');
|
||||
$status = $request->input('status');
|
||||
if ($id === null || $id === '') {
|
||||
return $this->fail('缺少参数 id');
|
||||
return $this->fail('missing parameter id');
|
||||
}
|
||||
if ($status === null || $status === '') {
|
||||
return $this->fail('缺少参数 status');
|
||||
return $this->fail('missing parameter status');
|
||||
}
|
||||
$model = $this->logic->read($id);
|
||||
if ($model) {
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||
return $this->fail('无权限修改该记录');
|
||||
return $this->fail('no permission to update this record');
|
||||
}
|
||||
}
|
||||
$this->logic->edit($id, ['status' => (int) $status]);
|
||||
@@ -207,7 +207,7 @@ class DicePlayerController extends BaseController
|
||||
if ($player && $player->username !== '') {
|
||||
UserCache::deletePlayerByUsername($player->username);
|
||||
}
|
||||
return $this->success('修改成功');
|
||||
return $this->success('update success');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,7 +220,7 @@ class DicePlayerController extends BaseController
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
return $this->fail('please select data to delete');
|
||||
}
|
||||
$ids = is_array($ids) ? $ids : explode(',', (string) $ids);
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
@@ -235,7 +235,7 @@ class DicePlayerController extends BaseController
|
||||
}
|
||||
$ids = $validIds;
|
||||
if (empty($ids)) {
|
||||
return $this->fail('无权限删除所选数据');
|
||||
return $this->fail('no permission to delete selected data');
|
||||
}
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
@@ -248,9 +248,9 @@ class DicePlayerController extends BaseController
|
||||
UserCache::deletePlayerByUsername($player->username);
|
||||
}
|
||||
}
|
||||
return $this->success('删除成功');
|
||||
return $this->success('delete success');
|
||||
}
|
||||
return $this->fail('删除失败');
|
||||
return $this->fail('delete failed');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -88,11 +88,11 @@ class DicePlayerTicketRecordController extends BaseController
|
||||
$id = $request->input('id', '');
|
||||
$model = $this->logic->read($id);
|
||||
if (!$model) {
|
||||
return $this->fail('未查找到信息');
|
||||
return $this->fail('not found');
|
||||
}
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||
return $this->fail('无权限查看该记录');
|
||||
return $this->fail('no permission to view this record');
|
||||
}
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
@@ -110,9 +110,9 @@ class DicePlayerTicketRecordController extends BaseController
|
||||
$this->validate('save', $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('添加成功');
|
||||
return $this->success('add success');
|
||||
} else {
|
||||
return $this->fail('添加失败');
|
||||
return $this->fail('add failed');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,9 +128,9 @@ class DicePlayerTicketRecordController extends BaseController
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
return $this->success('修改成功');
|
||||
return $this->success('update success');
|
||||
} else {
|
||||
return $this->fail('修改失败');
|
||||
return $this->fail('update failed');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,13 +144,13 @@ class DicePlayerTicketRecordController extends BaseController
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
return $this->fail('please select data to delete');
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
return $this->success('删除成功');
|
||||
return $this->success('delete success');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
return $this->fail('delete failed');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -85,15 +85,15 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
{
|
||||
$playerId = $request->input('player_id');
|
||||
if ($playerId === null || $playerId === '') {
|
||||
return $this->fail('缺少 player_id');
|
||||
return $this->fail('missing player_id');
|
||||
}
|
||||
$player = DicePlayer::field('coin,admin_id')->where('id', $playerId)->find();
|
||||
if (!$player) {
|
||||
return $this->fail('玩家不存在');
|
||||
return $this->fail('Player not found');
|
||||
}
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($player->admin_id ?? 0), $allowedIds, true)) {
|
||||
return $this->fail('无权限操作该玩家');
|
||||
return $this->fail('no permission to operate this player');
|
||||
}
|
||||
return $this->success(['wallet_before' => (float) $player['coin']]);
|
||||
}
|
||||
@@ -109,11 +109,11 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
$id = $request->input('id', '');
|
||||
$model = $this->logic->read($id);
|
||||
if (!$model) {
|
||||
return $this->fail('未查找到信息');
|
||||
return $this->fail('not found');
|
||||
}
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||
return $this->fail('无权限查看该记录');
|
||||
return $this->fail('no permission to view this record');
|
||||
}
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
@@ -133,13 +133,13 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
$coin = isset($data['coin']) ? (float) $data['coin'] : null;
|
||||
|
||||
if ($playerId === null || $playerId === '') {
|
||||
return $this->fail('请选择玩家');
|
||||
return $this->fail('please select player');
|
||||
}
|
||||
if (!in_array($type, [3, 4], true)) {
|
||||
return $this->fail('操作类型必须为 3=加点 或 4=扣点');
|
||||
return $this->fail('operation type must be 3 (add) or 4 (deduct)');
|
||||
}
|
||||
if ($coin === null || $coin <= 0) {
|
||||
return $this->fail('平台币变动必须大于 0');
|
||||
return $this->fail('Coin change must be greater than 0');
|
||||
}
|
||||
|
||||
$data['player_id'] = $playerId;
|
||||
@@ -163,20 +163,20 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
}
|
||||
}
|
||||
if ($adminId === null || $adminId <= 0) {
|
||||
return $this->fail('请先登录');
|
||||
return $this->fail('please login first');
|
||||
}
|
||||
|
||||
$player = DicePlayer::field('admin_id')->where('id', $playerId)->find();
|
||||
if ($player) {
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($player->admin_id ?? 0), $allowedIds, true)) {
|
||||
return $this->fail('无权限操作该玩家');
|
||||
return $this->fail('no permission to operate this player');
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$this->logic->adminOperate($data, $adminId);
|
||||
return $this->success('操作成功');
|
||||
return $this->success('operation success');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
@@ -194,9 +194,9 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
$this->validate('save', $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('添加成功');
|
||||
return $this->success('add success');
|
||||
} else {
|
||||
return $this->fail('添加失败');
|
||||
return $this->fail('add failed');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,9 +212,9 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
return $this->success('修改成功');
|
||||
return $this->success('update success');
|
||||
} else {
|
||||
return $this->fail('修改失败');
|
||||
return $this->fail('update failed');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,13 +228,13 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
return $this->fail('please select data to delete');
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
return $this->success('删除成功');
|
||||
return $this->success('delete success');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
return $this->fail('delete failed');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,11 +29,11 @@ class DiceRewardController extends BaseController
|
||||
{
|
||||
$direction = $request->input('direction', null);
|
||||
if ($direction === null || $direction === '') {
|
||||
return $this->fail('请传入 direction(0=顺时针 1=逆时针)');
|
||||
return $this->fail('please provide direction (0=clockwise, 1=counterclockwise)');
|
||||
}
|
||||
$direction = (int) $direction;
|
||||
if (!in_array($direction, [DiceReward::DIRECTION_CLOCKWISE, DiceReward::DIRECTION_COUNTERCLOCKWISE], true)) {
|
||||
return $this->fail('direction 必须为 0(顺时针)或 1(逆时针)');
|
||||
return $this->fail('direction must be 0 (clockwise) or 1 (counterclockwise)');
|
||||
}
|
||||
$tier = $request->input('tier', '');
|
||||
$page = (int) $request->input('page', 1);
|
||||
@@ -120,11 +120,11 @@ class DiceRewardController extends BaseController
|
||||
{
|
||||
$recordId = (int) $request->input('record_id', 0);
|
||||
if ($recordId <= 0) {
|
||||
return $this->fail('请传入 record_id');
|
||||
return $this->fail('please provide record_id');
|
||||
}
|
||||
$record = DiceRewardConfigRecord::find($recordId);
|
||||
if (!$record) {
|
||||
return $this->fail('记录不存在');
|
||||
return $this->fail('record not found');
|
||||
}
|
||||
$arr = $record->toArray();
|
||||
$data = [
|
||||
@@ -147,9 +147,9 @@ class DiceRewardController extends BaseController
|
||||
try {
|
||||
$table = (new DicePlayRecordTest())->getTable();
|
||||
Db::execute('TRUNCATE TABLE `' . $table . '`');
|
||||
return $this->success('已清空测试数据');
|
||||
return $this->success('test data cleared');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->fail('清空失败:' . $e->getMessage());
|
||||
return $this->fail('clear failed: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,12 +162,12 @@ class DiceRewardController extends BaseController
|
||||
{
|
||||
$items = $request->post('items', []);
|
||||
if (!is_array($items)) {
|
||||
return $this->fail('参数 items 必须为数组');
|
||||
return $this->fail('parameter items must be an array');
|
||||
}
|
||||
try {
|
||||
$logic = new DiceRewardLogic();
|
||||
$logic->batchUpdateWeights($items);
|
||||
return $this->success('保存成功');
|
||||
return $this->success('save success');
|
||||
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
@@ -182,16 +182,16 @@ class DiceRewardController extends BaseController
|
||||
{
|
||||
$direction = (int) $request->post('direction', 0);
|
||||
if (!in_array($direction, [DiceReward::DIRECTION_CLOCKWISE, DiceReward::DIRECTION_COUNTERCLOCKWISE], true)) {
|
||||
return $this->fail('direction 必须为 0(顺时针)或 1(逆时针)');
|
||||
return $this->fail('direction must be 0 (clockwise) or 1 (counterclockwise)');
|
||||
}
|
||||
$items = $request->post('items', []);
|
||||
if (!is_array($items)) {
|
||||
return $this->fail('参数 items 必须为数组');
|
||||
return $this->fail('parameter items must be an array');
|
||||
}
|
||||
try {
|
||||
$logic = new DiceRewardLogic();
|
||||
$logic->batchUpdateWeightsByDirection($direction, $items);
|
||||
return $this->success('保存成功');
|
||||
return $this->success('save success');
|
||||
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ class DiceRewardConfigController extends BaseController
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
} else {
|
||||
return $this->fail('未查找到信息');
|
||||
return $this->fail('not found');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,9 +80,9 @@ class DiceRewardConfigController extends BaseController
|
||||
$this->validate('save', $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('添加成功');
|
||||
return $this->success('add success');
|
||||
} else {
|
||||
return $this->fail('添加失败');
|
||||
return $this->fail('add failed');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,9 +98,9 @@ class DiceRewardConfigController extends BaseController
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
return $this->success('修改成功');
|
||||
return $this->success('update success');
|
||||
} else {
|
||||
return $this->fail('修改失败');
|
||||
return $this->fail('update failed');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ class DiceRewardConfigController extends BaseController
|
||||
{
|
||||
$items = $request->post('items', []);
|
||||
if (! is_array($items)) {
|
||||
return $this->fail('参数 items 必须为数组');
|
||||
return $this->fail('parameter items must be an array');
|
||||
}
|
||||
$err = $this->logic->validateBatchUpdateItems($items);
|
||||
if ($err !== null) {
|
||||
@@ -124,7 +124,7 @@ class DiceRewardConfigController extends BaseController
|
||||
$this->validate('batch_update', array_merge($item, ['id' => $item['id']]));
|
||||
}
|
||||
$this->logic->batchUpdate($items);
|
||||
return $this->success('保存成功');
|
||||
return $this->success('save success');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,13 +137,13 @@ class DiceRewardConfigController extends BaseController
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
return $this->fail('please select data to delete');
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
return $this->success('删除成功');
|
||||
return $this->success('delete success');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
return $this->fail('delete failed');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,12 +171,12 @@ class DiceRewardConfigController extends BaseController
|
||||
{
|
||||
$items = $request->post('items', []);
|
||||
if (!is_array($items)) {
|
||||
return $this->fail('参数 items 必须为数组');
|
||||
return $this->fail('parameter items must be an array');
|
||||
}
|
||||
try {
|
||||
$rewardLogic = new DiceRewardLogic();
|
||||
$rewardLogic->batchUpdateWeights($items);
|
||||
return $this->success('保存成功');
|
||||
return $this->success('save success');
|
||||
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
@@ -193,14 +193,14 @@ class DiceRewardConfigController extends BaseController
|
||||
{
|
||||
$items = $request->post('items', []);
|
||||
if (! is_array($items)) {
|
||||
return $this->fail('参数 items 必须为数组');
|
||||
return $this->fail('parameter items must be an array');
|
||||
}
|
||||
$err = $this->logic->validateBigwinWeightItems($items);
|
||||
if ($err !== null) {
|
||||
return $this->fail($err);
|
||||
}
|
||||
$this->logic->batchUpdateBigwinWeight($items);
|
||||
return $this->success('保存成功');
|
||||
return $this->success('save success');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -215,7 +215,7 @@ class DiceRewardConfigController extends BaseController
|
||||
try {
|
||||
$rewardLogic = new DiceRewardLogic();
|
||||
$result = $rewardLogic->createRewardReferenceFromConfig();
|
||||
return $this->success($result, '创建奖励对照成功');
|
||||
return $this->success($result, 'create reward mapping success');
|
||||
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ class DiceRewardConfigRecordController extends BaseController
|
||||
$data['admin_name'] = $this->getAdminName((int) ($data['admin_id'] ?? 0));
|
||||
return $this->success($data);
|
||||
} else {
|
||||
return $this->fail('未查找到信息');
|
||||
return $this->fail('not found');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,9 +96,9 @@ class DiceRewardConfigRecordController extends BaseController
|
||||
$this->validate('save', $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('添加成功');
|
||||
return $this->success('add success');
|
||||
} else {
|
||||
return $this->fail('添加失败');
|
||||
return $this->fail('add failed');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,9 +114,9 @@ class DiceRewardConfigRecordController extends BaseController
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
return $this->success('修改成功');
|
||||
return $this->success('update success');
|
||||
} else {
|
||||
return $this->fail('修改失败');
|
||||
return $this->fail('update failed');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,13 +130,13 @@ class DiceRewardConfigRecordController extends BaseController
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
return $this->fail('please select data to delete');
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
return $this->success('删除成功');
|
||||
return $this->success('delete success');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
return $this->fail('delete failed');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ class DiceRewardConfigRecordController extends BaseController
|
||||
{
|
||||
$recordId = (int) $request->post('record_id', 0);
|
||||
if ($recordId <= 0) {
|
||||
return $this->fail('请指定测试记录');
|
||||
return $this->fail('please specify test record');
|
||||
}
|
||||
$paidId = $request->post('paid_lottery_config_id', null);
|
||||
$freeId = $request->post('free_lottery_config_id', null);
|
||||
@@ -159,7 +159,7 @@ class DiceRewardConfigRecordController extends BaseController
|
||||
$lotteryConfigId = $legacyId !== null && $legacyId !== '' ? (int) $legacyId : null;
|
||||
try {
|
||||
$this->logic->importFromRecord($recordId, $paidLotteryConfigId, $freeLotteryConfigId, $lotteryConfigId);
|
||||
return $this->success('导入成功,已刷新 DiceReward、DiceRewardConfig(BIGWIN)、奖池配置');
|
||||
return $this->success('import success, refreshed DiceReward, DiceRewardConfig(BIGWIN), and pool config');
|
||||
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class DiceLotteryPoolConfigLogic extends BaseLogic
|
||||
{
|
||||
$configType0 = DiceLotteryPoolConfig::where('name', 'default')->find();
|
||||
if (!$configType0) {
|
||||
throw new ApiException('未找到 name=default 的奖池配置,请先创建');
|
||||
throw new ApiException('No name=default pool config found, please create one first');
|
||||
}
|
||||
$configType1 = DiceLotteryPoolConfig::where('name', 'killScore')->find();
|
||||
$row0 = $configType0->toArray();
|
||||
|
||||
@@ -50,20 +50,20 @@ class DicePlayerWalletRecordLogic extends BaseLogic
|
||||
$coin = (float) ($data['coin'] ?? 0);
|
||||
|
||||
if ($playerId <= 0 || !in_array($type, [3, 4], true)) {
|
||||
throw new ApiException('参数错误:需要有效的 player_id 和 type(3=加点,4=扣点)');
|
||||
throw new ApiException('Invalid params: player_id and type are required (3=add, 4=deduct)');
|
||||
}
|
||||
if ($coin <= 0) {
|
||||
throw new ApiException('平台币变动必须大于 0');
|
||||
throw new ApiException('Coin change must be greater than 0');
|
||||
}
|
||||
|
||||
$player = DicePlayer::where('id', $playerId)->find();
|
||||
if (!$player) {
|
||||
throw new ApiException('玩家不存在');
|
||||
throw new ApiException('Player not found');
|
||||
}
|
||||
|
||||
$walletBefore = (float) ($player['coin'] ?? 0);
|
||||
if ($type === 4 && $walletBefore < $coin) {
|
||||
throw new ApiException('扣点数量不能大于当前余额');
|
||||
throw new ApiException('Deduct amount cannot exceed current balance');
|
||||
}
|
||||
|
||||
$walletAfter = $type === 3 ? $walletBefore + $coin : $walletBefore - $coin;
|
||||
|
||||
@@ -86,7 +86,7 @@ class DiceRewardLogic
|
||||
$id = isset($item['id']) ? (int) $item['id'] : 0;
|
||||
$weight = isset($item['weight']) ? (int) $item['weight'] : self::WEIGHT_MIN;
|
||||
if ($id <= 0) {
|
||||
throw new ApiException('存在无效的配置ID');
|
||||
throw new ApiException('Invalid config ID exists');
|
||||
}
|
||||
$weight = max(self::WEIGHT_MIN, min(self::WEIGHT_MAX, $weight));
|
||||
|
||||
@@ -199,7 +199,7 @@ class DiceRewardLogic
|
||||
$id = isset($item['reward_id']) ? (int) $item['reward_id'] : 0;
|
||||
}
|
||||
if ($id <= 0) {
|
||||
throw new ApiException('存在无效的 DiceReward id');
|
||||
throw new ApiException('Invalid DiceReward id exists');
|
||||
}
|
||||
$weight = isset($item['weight']) ? (int) $item['weight'] : self::WEIGHT_MIN;
|
||||
$weight = max(self::WEIGHT_MIN, min(self::WEIGHT_MAX, $weight));
|
||||
@@ -313,7 +313,7 @@ class DiceRewardLogic
|
||||
{
|
||||
$list = DiceRewardConfig::order('id', 'asc')->select()->toArray();
|
||||
if (empty($list)) {
|
||||
throw new ApiException('奖励配置为空,请先维护 dice_reward_config');
|
||||
throw new ApiException('Reward config is empty, please maintain dice_reward_config first');
|
||||
}
|
||||
$configCount = count($list);
|
||||
if ($configCount < self::BOARD_SIZE) {
|
||||
|
||||
@@ -319,7 +319,7 @@ class DiceRewardConfigLogic extends BaseLogic
|
||||
{
|
||||
$allowedCounts = [100, 500, 1000, 5000, 10000];
|
||||
if (!in_array($testCount, $allowedCounts, true)) {
|
||||
throw new ApiException('测试次数仅支持 100、500、1000、5000、10000');
|
||||
throw new ApiException('Test count only supports 100, 500, 1000, 5000, 10000');
|
||||
}
|
||||
|
||||
$grouped = [];
|
||||
|
||||
@@ -81,7 +81,7 @@ class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
{
|
||||
$record = $this->model->find($recordId);
|
||||
if (!$record) {
|
||||
throw new ApiException('测试记录不存在');
|
||||
throw new ApiException('Test record not found');
|
||||
}
|
||||
$record = is_array($record) ? $record : $record->toArray();
|
||||
|
||||
@@ -195,7 +195,7 @@ class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
if (is_array($paidData) && $paidTargetId > 0) {
|
||||
$pool = DiceLotteryPoolConfig::find($paidTargetId);
|
||||
if (!$pool) {
|
||||
throw new ApiException('付费奖池配置不存在');
|
||||
throw new ApiException('Paid pool config not found');
|
||||
}
|
||||
$update = [
|
||||
't1_weight' => (int) ($paidData['T1'] ?? $paidData['t1'] ?? 0),
|
||||
@@ -209,7 +209,7 @@ class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
if (is_array($freeData) && $freeTargetId > 0) {
|
||||
$pool = DiceLotteryPoolConfig::find($freeTargetId);
|
||||
if (!$pool) {
|
||||
throw new ApiException('免费奖池配置不存在');
|
||||
throw new ApiException('Free pool config not found');
|
||||
}
|
||||
$update = [
|
||||
't1_weight' => (int) ($freeData['T1'] ?? $freeData['t1'] ?? 0),
|
||||
@@ -264,12 +264,12 @@ class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
|
||||
foreach ([$paidS, $paidN, $freeS, $freeN] as $c) {
|
||||
if ($c !== 0 && !in_array($c, $allowed, true)) {
|
||||
throw new ApiException('各抽奖次数仅支持 0、100、500、1000、5000');
|
||||
throw new ApiException('Counts only support 0, 100, 500, 1000, 5000');
|
||||
}
|
||||
}
|
||||
$total = $paidS + $paidN + $freeS + $freeN;
|
||||
if ($total <= 0) {
|
||||
throw new ApiException('付费或免费至少一种方向次数之和大于 0');
|
||||
throw new ApiException('Sum of paid/free direction counts must be greater than 0');
|
||||
}
|
||||
|
||||
$snapshot = [];
|
||||
@@ -314,7 +314,7 @@ class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
if ($paidConfigId > 0) {
|
||||
$config = DiceLotteryPoolConfig::find($paidConfigId);
|
||||
if (!$config) {
|
||||
throw new ApiException('付费奖池配置不存在');
|
||||
throw new ApiException('Paid pool config not found');
|
||||
}
|
||||
$tierWeightsSnapshot['paid'] = [
|
||||
'T1' => (int) ($config->t1_weight ?? 0),
|
||||
@@ -326,19 +326,19 @@ class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
} else {
|
||||
$paidTierWeights = $params['paid_tier_weights'] ?? null;
|
||||
if (!is_array($paidTierWeights)) {
|
||||
throw new ApiException('付费未选择奖池配置时,请填写付费自定义档位概率(T1~T5)');
|
||||
throw new ApiException('When paid pool is not selected, please fill paid custom tier probabilities (T1–T5)');
|
||||
}
|
||||
$tiers = ['T1', 'T2', 'T3', 'T4', 'T5'];
|
||||
foreach ($tiers as $t) {
|
||||
$v = (int) ($paidTierWeights[$t] ?? 0);
|
||||
if ($v < 0 || $v > 100) {
|
||||
throw new ApiException('付费档位概率每档只能 0-100%');
|
||||
throw new ApiException('Paid tier probability must be between 0 and 100%');
|
||||
}
|
||||
$paidTierWeights[$t] = $v;
|
||||
}
|
||||
$paidSum = array_sum(array_intersect_key($paidTierWeights, array_flip($tiers)));
|
||||
if ($paidSum > 100) {
|
||||
throw new ApiException('付费档位概率 T1~T5 之和不能超过 100%');
|
||||
throw new ApiException('Paid tier probabilities (T1–T5) sum cannot exceed 100%');
|
||||
}
|
||||
$tierWeightsSnapshot['paid'] = $paidTierWeights;
|
||||
}
|
||||
@@ -346,7 +346,7 @@ class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
if ($freeConfigId > 0) {
|
||||
$config = DiceLotteryPoolConfig::find($freeConfigId);
|
||||
if (!$config) {
|
||||
throw new ApiException('免费奖池配置不存在');
|
||||
throw new ApiException('Free pool config not found');
|
||||
}
|
||||
$tierWeightsSnapshot['free'] = [
|
||||
'T1' => (int) ($config->t1_weight ?? 0),
|
||||
@@ -358,19 +358,19 @@ class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
} else {
|
||||
$freeTierWeights = $params['free_tier_weights'] ?? null;
|
||||
if (!is_array($freeTierWeights)) {
|
||||
throw new ApiException('免费未选择奖池配置时,请填写免费自定义档位概率(T1~T5)');
|
||||
throw new ApiException('When free pool is not selected, please fill free custom tier probabilities (T1–T5)');
|
||||
}
|
||||
$tiers = ['T1', 'T2', 'T3', 'T4', 'T5'];
|
||||
foreach ($tiers as $t) {
|
||||
$v = (int) ($freeTierWeights[$t] ?? 0);
|
||||
if ($v < 0 || $v > 100) {
|
||||
throw new ApiException('免费档位概率每档只能 0-100%');
|
||||
throw new ApiException('Free tier probability must be between 0 and 100%');
|
||||
}
|
||||
$freeTierWeights[$t] = $v;
|
||||
}
|
||||
$freeSum = array_sum(array_intersect_key($freeTierWeights, array_flip($tiers)));
|
||||
if ($freeSum > 100) {
|
||||
throw new ApiException('免费档位概率 T1~T5 之和不能超过 100%');
|
||||
throw new ApiException('Free tier probabilities (T1–T5) sum cannot exceed 100%');
|
||||
}
|
||||
$tierWeightsSnapshot['free'] = $freeTierWeights;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user