[色子游戏]抽奖记录(测试权重)-优化

[API]记录抽奖券DicePlayerTicketRecord
This commit is contained in:
2026-03-25 18:51:29 +08:00
parent f8cf85dd01
commit d793a511ee
27 changed files with 256 additions and 47 deletions

View File

@@ -284,6 +284,21 @@ class PlayStartLogic
$p->free_ticket_count = max(0, (int) $p->free_ticket_count - 1);
}
// 记录每次游玩:写入抽奖券记录(用于后台“抽奖券记录”追踪付费/免费游玩与消耗)
$isPaidPlay = $ticketType === self::LOTTERY_TYPE_PAID;
$paidCnt = $isPaidPlay ? 1 : 0;
$freeCnt = $isPaidPlay ? 0 : 1;
DicePlayerTicketRecord::create([
'player_id' => $playerId,
'admin_id' => $adminId,
'use_coins' => $paidAmount,
'ante' => $ante,
'total_ticket_count' => $paidCnt + $freeCnt,
'paid_ticket_count' => $paidCnt,
'free_ticket_count' => $freeCnt,
'remark' => ($isPaidPlay ? '付费游玩' : '免费游玩') . '|play_record_id=' . $record->id,
]);
// 若本局中奖档位为 T5则额外赠送 1 次免费抽奖次数(总次数也 +1并记录抽奖券获取记录
if ($isTierT5) {
$p->free_ticket_count = (int) $p->free_ticket_count + 1;
@@ -509,10 +524,11 @@ class PlayStartLogic
* @param \app\dice\model\lottery_pool_config\DiceLotteryPoolConfig|null $config 奖池配置,自定义档位时可为 null
* @param int $direction 0=顺时针 1=逆时针
* @param int $lotteryType 0=付费 1=免费
* @param int $ante 底注/注数dice_ante_config.mult
* @param array|null $customTierWeights 自定义档位权重 ['T1'=>x, 'T2'=>x, ...],非空时忽略 config 的档位权重
* @return array 可直接用于 DicePlayRecordTest::create 的字段 + tier用于统计档位概率
*/
public function simulateOnePlay($config, int $direction, int $lotteryType = 0, ?array $customTierWeights = null): array
public function simulateOnePlay($config, int $direction, int $lotteryType = 0, int $ante = 1, ?array $customTierWeights = null): array
{
$rewardInstance = DiceReward::getCachedInstance();
$byTierDirection = $rewardInstance['by_tier_direction'] ?? [];
@@ -558,8 +574,8 @@ class PlayStartLogic
$targetIndex = (int) ($chosen['end_index'] ?? 0);
$rollNumber = (int) ($chosen['grid_number'] ?? 0);
$realEv = (float) ($chosen['real_ev'] ?? 0);
$isTierT5 = (string) ($chosen['tier'] ?? '') === 'T5';
$rewardWinCoin = $isTierT5 ? $realEv : (100 + $realEv);
// 玩家始终增加:(100 + real_ev) * ante
$rewardWinCoin = (self::UNIT_COST + $realEv) * $ante;
$superWinCoin = 0;
$isWin = 0;
@@ -588,8 +604,11 @@ class PlayStartLogic
if ($doSuperWin) {
$rollArray = $this->getSuperWinRollArray($rollNumber);
$isWin = 1;
$superWinCoin = $bigWinRealEv > 0 ? $bigWinRealEv : self::SUPER_WIN_BONUS;
$bigWinEv = $bigWinRealEv > 0 ? $bigWinRealEv : self::SUPER_WIN_BONUS;
$superWinCoin = (self::UNIT_COST + $bigWinEv) * $ante;
$rewardWinCoin = 0;
// 中豹子时不走原奖励流程
$realEv = 0.0;
} else {
$rollArray = $this->generateNonSuperWinRollArrayWithSum($rollNumber);
}
@@ -603,6 +622,7 @@ class PlayStartLogic
$rewardId = ($isWin === 1 && $superWinCoin > 0) ? 0 : $targetIndex;
$configName = $config !== null ? (string) ($config->name ?? '') : '自定义';
$costRealEv = $realEv + ($isWin === 1 ? $bigWinRealEv : 0.0);
$paidAmount = $lotteryType === 0 ? ($ante * self::UNIT_COST) : 0;
return [
'player_id' => 0,
@@ -611,9 +631,11 @@ class PlayStartLogic
'lottery_type' => $lotteryType,
'is_win' => $isWin,
'win_coin' => $winCoin,
'ante' => $ante,
'paid_amount' => $paidAmount,
'super_win_coin' => $superWinCoin,
'reward_win_coin' => $rewardWinCoin,
'use_coins' => 0,
'use_coins' => $paidAmount,
'direction' => $direction,
'reward_config_id' => $rewardId,
'start_index' => $startIndex,