优化临时插入用户接口/api/user/Login和抽奖接口/api/game/playStart
This commit is contained in:
@@ -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