优化临时插入用户接口/api/user/Login和抽奖接口/api/game/playStart
This commit is contained in:
@@ -26,9 +26,13 @@ class UserController extends BaseController
|
||||
*/
|
||||
public function Login(Request $request): Response
|
||||
{
|
||||
$username = trim((string) ($request->post('username', '')));
|
||||
$password = trim((string) ($request->post('password', '')));
|
||||
$lang = trim((string) ($request->post('lang', 'chs')));
|
||||
$usernameRaw = $request->post('username', '');
|
||||
$passwordRaw = $request->post('password', '');
|
||||
$langRaw = $request->post('lang', 'zh');
|
||||
|
||||
$username = is_string($usernameRaw) ? trim($usernameRaw) : '';
|
||||
$password = is_string($passwordRaw) ? trim($passwordRaw) : '';
|
||||
$lang = is_string($langRaw) ? trim($langRaw) : 'zh';
|
||||
$coin = $request->post('coin');
|
||||
$coin = $coin !== null && $coin !== '' ? (float) $coin : 0.0;
|
||||
$time = $request->post('time');
|
||||
|
||||
@@ -58,7 +58,7 @@ class GameController extends BaseController
|
||||
|
||||
try {
|
||||
$logic = new UserLogic();
|
||||
$result = $logic->loginByUsername($username, $password, $lang === 'en' ? 'en' : 'chs', 0.0, $time, $adminId, $adminIdsInTopDept);
|
||||
$result = $logic->loginByUsername($username, $password, $lang, 0.0, $time, $adminId, $adminIdsInTopDept);
|
||||
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
||||
return $this->fail($e->getMessage(), ReturnCode::PARAMS_ERROR);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ return [
|
||||
'账号已被禁用,无法登录' => 'Account is disabled and cannot log in',
|
||||
'购买抽奖券错误' => 'Invalid lottery ticket purchase',
|
||||
'平台币不足' => 'Insufficient balance',
|
||||
'余额不足' => 'Insufficient balance',
|
||||
'direction 必须为 0 或 1' => 'direction must be 0 or 1',
|
||||
'当前玩家余额%s小于%s无法继续游戏' => 'Balance %s is less than %s, cannot continue',
|
||||
'服务超时,' => 'Service timeout: ',
|
||||
|
||||
@@ -115,16 +115,29 @@ class PlayStartLogic
|
||||
throw new ApiException('Lottery pool config not found (name=default required)');
|
||||
}
|
||||
|
||||
// 余额校验:统一校验 ante * min(real_ev)
|
||||
$minEv = DiceRewardConfig::getCachedMinRealEv();
|
||||
$needMinBalance = abs((float) $minEv) * $ante;
|
||||
if ($coin < $needMinBalance) {
|
||||
throw new ApiException('未达抽奖余额 ' . $needMinBalance . ',无法开始游戏');
|
||||
}
|
||||
|
||||
// 付费抽奖:开始前扣除费用 ante * UNIT_COST,不足则提示余额不足
|
||||
// 付费抽奖:开始前扣除费用 ante * UNIT_COST
|
||||
$paidAmount = $ticketType === self::LOTTERY_TYPE_PAID ? round($ante * self::UNIT_COST, 2) : 0.0;
|
||||
if ($ticketType === self::LOTTERY_TYPE_PAID && $coin < $paidAmount) {
|
||||
|
||||
// 游玩前余额校验(按 T4 惩罚最大值兜底):
|
||||
// 门槛 = paidAmount(压注*1) + abs(T4最小real_ev)*ante
|
||||
$t4List = DiceRewardConfig::getCachedByTier('T4');
|
||||
$t4MinRealEv = null;
|
||||
foreach ($t4List as $row) {
|
||||
$ev = $row['real_ev'] ?? null;
|
||||
if ($ev === null || $ev === '') {
|
||||
continue;
|
||||
}
|
||||
$evFloat = filter_var($ev, FILTER_VALIDATE_FLOAT);
|
||||
if ($evFloat === false) {
|
||||
continue;
|
||||
}
|
||||
if ($t4MinRealEv === null || $evFloat < $t4MinRealEv) {
|
||||
$t4MinRealEv = $evFloat;
|
||||
}
|
||||
}
|
||||
$t4PenaltyAbs = $t4MinRealEv === null ? 0.0 : abs($t4MinRealEv) * $ante;
|
||||
$needMinBalance = round($paidAmount + $t4PenaltyAbs, 2);
|
||||
if ($coin < $needMinBalance) {
|
||||
throw new ApiException('余额不足');
|
||||
}
|
||||
|
||||
@@ -303,6 +316,10 @@ class PlayStartLogic
|
||||
$coinBefore = (float) $p->coin;
|
||||
// 开始前先扣付费金额,再加中奖金额(免费抽奖 paid_amount=0)
|
||||
$coinAfter = round($coinBefore - $paidAmount + $winCoin, 2);
|
||||
// T4 惩罚兜底:扣完购券费用后若余额不足以承受本次惩罚(导致为负),统一按“余额不足”提示
|
||||
if ($rewardTier === 'T4' && $coinAfter < 0) {
|
||||
throw new ApiException('余额不足');
|
||||
}
|
||||
$p->coin = $coinAfter;
|
||||
// 免费抽奖消耗:优先消耗 free_ticket.count,耗尽则清空 free_ticket;否则兼容旧 free_ticket_count
|
||||
if ($ticketType === self::LOTTERY_TYPE_FREE) {
|
||||
|
||||
@@ -174,7 +174,10 @@ class UserLogic
|
||||
UserCache::setPlayerByUsername($username, $userArr);
|
||||
|
||||
$baseUrl = rtrim(config('api.login_url_base', 'https://127.0.0.1:6777'), '/');
|
||||
$lang = in_array($lang, ['chs', 'en'], true) ? $lang : 'chs';
|
||||
$lang = strtolower(trim($lang));
|
||||
if ($lang !== 'en') {
|
||||
$lang = 'zh';
|
||||
}
|
||||
$tokenInUrl = str_replace('%3D', '=', urlencode($token));
|
||||
$url = $baseUrl . '?token=' . $tokenInUrl . '&lang=' . $lang;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user