优化彩金池安全线触发方式
This commit is contained in:
@@ -73,7 +73,7 @@ class PlayStartLogic
|
||||
$config = $ticketType === self::LOTTERY_TYPE_PAID
|
||||
? ($lotteryService->getConfigType0Id() ? DiceLotteryPoolConfig::find($lotteryService->getConfigType0Id()) : null)
|
||||
: ($lotteryService->getConfigType1Id() ? DiceLotteryPoolConfig::find($lotteryService->getConfigType1Id()) : null);
|
||||
// 未找到付费/免费对应配置时,统一回退到 type=0 的彩金池,保证所有玩家累加同一彩金池
|
||||
// 未找到付费/免费对应配置时,统一回退到 type=0 的彩金池
|
||||
if (!$config) {
|
||||
$config = DiceLotteryPoolConfig::where('type', 0)->find();
|
||||
}
|
||||
@@ -81,10 +81,16 @@ class PlayStartLogic
|
||||
throw new ApiException('奖池配置不存在');
|
||||
}
|
||||
|
||||
// 彩金池盈利低于安全线时按玩家权重抽档,高于或等于安全线时按奖池权重抽档
|
||||
$poolProfit = (float) ($config->profit_amount ?? $config->ev ?? 0);
|
||||
// 计算当前玩家在该彩金池中的累计盈利金额:当前中奖金额(含 BIGWIN)减去抽奖券费用 100
|
||||
$playerQuery = DicePlayRecord::where('player_id', $playerId)
|
||||
->where('lottery_config_id', $config->id)
|
||||
->where('status', self::RECORD_STATUS_SUCCESS);
|
||||
$playerWinSum = (float) $playerQuery->sum('win_coin');
|
||||
$playerPlayCount = (int) $playerQuery->count();
|
||||
$playerProfitTotal = $playerWinSum - 100.0 * $playerPlayCount;
|
||||
$safetyLine = (int) ($config->safety_line ?? 0);
|
||||
$usePoolWeights = $poolProfit >= $safetyLine;
|
||||
// 玩家累计盈利金额达到或超过安全线时,按奖池 T*_weight 杀分;否则按玩家 T*_weight 抽档位
|
||||
$usePoolWeights = $playerProfitTotal >= $safetyLine;
|
||||
|
||||
// 按档位 T1-T5 抽取后,从 DiceReward 表按当前方向取该档位数据,再按 weight 抽取一条得到 grid_number
|
||||
$rewardInstance = DiceReward::getCachedInstance();
|
||||
@@ -244,10 +250,10 @@ class PlayStartLogic
|
||||
|
||||
$p->save();
|
||||
|
||||
// 彩金池盈利:每局扣除本局发放的真实成本(普通档位 real_ev + BIGWIN.real_ev 如触发),不额外加 100
|
||||
// 玩家累计盈利底层仍使用 profit_amount 字段存储:每局按“当前中奖金额(含 BIGWIN) - 抽奖券费用 100”累加
|
||||
// 需确保表有 profit_amount 字段(见 db/dice_lottery_config_add_profit_amount.sql)
|
||||
$totalRealEv = $realEv + $bigWinRealEv;
|
||||
$addProfit = -$totalRealEv;
|
||||
$perPlayProfit = $winCoin - 100.0;
|
||||
$addProfit = $perPlayProfit;
|
||||
try {
|
||||
DiceLotteryPoolConfig::where('id', $configId)->update([
|
||||
'profit_amount' => Db::raw('IFNULL(profit_amount,0) + ' . (float) $addProfit),
|
||||
@@ -479,6 +485,7 @@ class PlayStartLogic
|
||||
|
||||
$superWinCoin = 0;
|
||||
$isWin = 0;
|
||||
$bigWinRealEv = 0.0;
|
||||
if (in_array($rollNumber, self::SUPER_WIN_GRID_NUMBERS, true)) {
|
||||
$bigWinConfig = DiceRewardConfig::getCachedByTierAndGridNumber('BIGWIN', $rollNumber);
|
||||
$alwaysSuperWin = in_array($rollNumber, self::SUPER_WIN_ALWAYS_GRID_NUMBERS, true);
|
||||
@@ -491,10 +498,13 @@ class PlayStartLogic
|
||||
$roll = (random_int(0, PHP_INT_MAX - 1) / (float) PHP_INT_MAX);
|
||||
$doSuperWin = $bigWinWeight > 0 && $roll < ($bigWinWeight / 10000.0);
|
||||
}
|
||||
if ($bigWinConfig !== null && isset($bigWinConfig['real_ev'])) {
|
||||
$bigWinRealEv = (float) $bigWinConfig['real_ev'];
|
||||
}
|
||||
if ($doSuperWin) {
|
||||
$rollArray = $this->getSuperWinRollArray($rollNumber);
|
||||
$isWin = 1;
|
||||
$superWinCoin = ($bigWinConfig['real_ev'] ?? 0) > 0 ? (float) ($bigWinConfig['real_ev'] ?? 0) : self::SUPER_WIN_BONUS;
|
||||
$superWinCoin = $bigWinRealEv > 0 ? $bigWinRealEv : self::SUPER_WIN_BONUS;
|
||||
$rewardWinCoin = 0;
|
||||
} else {
|
||||
$rollArray = $this->generateNonSuperWinRollArrayWithSum($rollNumber);
|
||||
@@ -507,6 +517,7 @@ class PlayStartLogic
|
||||
$configId = $config !== null ? (int) $config->id : 0;
|
||||
$rewardId = ($isWin === 1 && $superWinCoin > 0) ? 0 : $targetIndex;
|
||||
$configName = $config !== null ? (string) ($config->name ?? '') : '自定义';
|
||||
$costRealEv = $realEv + ($isWin === 1 ? $bigWinRealEv : 0.0);
|
||||
|
||||
return [
|
||||
'player_id' => 0,
|
||||
@@ -528,6 +539,9 @@ class PlayStartLogic
|
||||
'status' => self::RECORD_STATUS_SUCCESS,
|
||||
'tier' => $tier,
|
||||
'roll_number_for_count' => $rollNumber,
|
||||
'real_ev' => $realEv,
|
||||
'bigwin_real_ev' => $isWin === 1 ? $bigWinRealEv : 0.0,
|
||||
'cost_ev' => $costRealEv,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user