优化一键测试权重

This commit is contained in:
2026-03-13 15:47:12 +08:00
parent f5eaf8da30
commit 0b26afde70
19 changed files with 991 additions and 274 deletions

View File

@@ -430,11 +430,13 @@ class PlayStartLogic
/**
* 模拟一局抽奖(不写库、不扣玩家),用于权重测试写入 dice_play_record_test
* @param \app\dice\model\lottery_pool_config\DiceLotteryPoolConfig $config 奖池配置
* @param \app\dice\model\lottery_pool_config\DiceLotteryPoolConfig|null $config 奖池配置,自定义档位时可为 null
* @param int $direction 0=顺时针 1=逆时针
* @param int $lotteryType 0=付费 1=免费
* @param array|null $customTierWeights 自定义档位权重 ['T1'=>x, 'T2'=>x, ...],非空时忽略 config 的档位权重
* @return array 可直接用于 DicePlayRecordTest::create 的字段 + tier用于统计档位概率
*/
public function simulateOnePlay($config, int $direction): array
public function simulateOnePlay($config, int $direction, int $lotteryType = 0, ?array $customTierWeights = null): array
{
$rewardInstance = DiceReward::getCachedInstance();
$byTierDirection = $rewardInstance['by_tier_direction'] ?? [];
@@ -442,7 +444,14 @@ class PlayStartLogic
$chosen = null;
$tier = null;
for ($tierAttempt = 0; $tierAttempt < $maxTierRetry; $tierAttempt++) {
$tier = LotteryService::drawTierByWeights($config);
if ($customTierWeights !== null && $customTierWeights !== []) {
$tier = LotteryService::drawTierByWeightsFromArray($customTierWeights);
} else {
if ($config === null) {
throw new \RuntimeException('模拟抽奖:未提供奖池配置或自定义档位权重');
}
$tier = LotteryService::drawTierByWeights($config);
}
$tierRewards = $byTierDirection[$tier][$direction] ?? [];
if (empty($tierRewards)) {
continue;
@@ -495,15 +504,15 @@ class PlayStartLogic
}
$winCoin = $superWinCoin + $rewardWinCoin;
$configId = (int) $config->id;
$configId = $config !== null ? (int) $config->id : 0;
$rewardId = ($isWin === 1 && $superWinCoin > 0) ? 0 : $targetIndex;
$configName = (string) ($config->name ?? '');
$configName = $config !== null ? (string) ($config->name ?? '') : '自定义';
return [
'player_id' => 0,
'admin_id' => 0,
'lottery_config_id' => $configId,
'lottery_type' => self::LOTTERY_TYPE_PAID,
'lottery_type' => $lotteryType,
'is_win' => $isWin,
'win_coin' => $winCoin,
'super_win_coin' => $superWinCoin,