优化-实例化奖励列表到缓存中

This commit is contained in:
2026-03-06 14:16:01 +08:00
parent f7d9b18f02
commit 931af70c36
3 changed files with 89 additions and 13 deletions

View File

@@ -48,7 +48,7 @@ class PlayStartLogic
throw new ApiException('用户不存在');
}
$minEv = (float) DiceRewardConfig::min('real_ev');
$minEv = DiceRewardConfig::getCachedMinRealEv();
$minCoin = abs($minEv + self::MIN_COIN_EXTRA);
$coin = (float) $player->coin;
if ($coin < $minCoin) {
@@ -80,18 +80,14 @@ class PlayStartLogic
// 索引范围为 0~25 共 26 个格子
$boardSize = 26;
// 1. 根据抽到的档位,在 tier 相等的数据中任选一条,其 id 为结束索引 target_index
$tierRewards = DiceRewardConfig::where('tier', $tier)->select()->toArray();
// 1. 根据抽到的档位,在 tier 相等的数据中任选一条,其 id 为结束索引 target_index(从缓存读取)
$tierRewards = DiceRewardConfig::getCachedByTier($tier);
if (empty($tierRewards)) {
Log::error("档位 {$tier} 无任何奖励配置");
throw new ApiException('该档位暂无奖励配置');
}
$chosen = $tierRewards[array_rand($tierRewards)];
$reward = DiceRewardConfig::find($chosen['id']);
if (!$reward) {
throw new ApiException('奖励配置不存在');
}
$targetIndex = (int) $reward->id;
$targetIndex = (int) ($chosen['id'] ?? 0);
$targetIndex = (($targetIndex % $boardSize) + $boardSize) % $boardSize;
// 2. 根据结果反推起始点 start_index由 target_index 与方向反算)
@@ -111,14 +107,14 @@ class PlayStartLogic
$startIndex,
$targetIndex
));
$realEv = (float) $reward->real_ev;
$realEv = (float) ($chosen['real_ev'] ?? 0);
$winCoin = 100 + $realEv; // 赢取平台币 = 100 + DiceRewardConfig.real_ev
$record = null;
$configId = (int) $config->id;
$rewardId = (int) $reward->id;
$rewardId = (int) ($chosen['id'] ?? 0);
$configName = (string) ($config->name ?? '');
$isTierT5 = (string) ($reward->tier ?? '') === 'T5';
$isTierT5 = (string) ($chosen['tier'] ?? '') === 'T5';
try {
Db::transaction(function () use (
$playerId,