菜单按钮权限设置-后台可以设置新增的按钮权限

This commit is contained in:
2026-03-17 20:30:37 +08:00
parent bdf50e61f5
commit f63616e735
15 changed files with 125 additions and 113 deletions

View File

@@ -14,6 +14,7 @@ use support\think\Db;
/**
* 一键测试权重:单进程后台执行模拟摇色子,写入 dice_play_record_test 并更新 dice_reward_config_record 进度
* 抽奖逻辑与 PlayStartLogic 一致:使用 name=default 的安全线、杀分开关;盈利<安全线时付费用玩家权重、免费用 killScore盈利>=安全线且杀分开启时付费/免费均用 killScore
*/
class WeightTestRunner
{
@@ -21,7 +22,7 @@ class WeightTestRunner
/**
* 执行指定测试记录:按付费/免费、顺/逆方向交替模拟(付费顺→付费逆→免费顺→免费逆),每 10 条写入一次测试表并更新进度
* 支持1lottery_config_id 有值时用奖池配置档位权重2无值时用记录中的 paid_tier_weights / free_tier_weights
* 使用与 playStart 相同的彩金池逻辑name=default 的安全线/kill_enabled付费用 paid_tier_weights玩家权重或 killScore免费用 killScore
* @param int $recordId dice_reward_config_record.id
*/
public function run(int $recordId): void
@@ -50,48 +51,37 @@ class WeightTestRunner
$total = $paidS + $paidN + $freeS + $freeN;
}
$paidConfigId = (int) ($record->paid_lottery_config_id ?? 0);
$freeConfigId = (int) ($record->free_lottery_config_id ?? 0);
if ($paidConfigId <= 0) {
$paidConfigId = (int) ($record->lottery_config_id ?? 0);
}
if ($freeConfigId <= 0) {
$freeConfigId = (int) ($record->lottery_config_id ?? 0);
}
$paidConfig = $paidConfigId > 0 ? DiceLotteryPoolConfig::find($paidConfigId) : null;
$freeConfig = $freeConfigId > 0 ? DiceLotteryPoolConfig::find($freeConfigId) : null;
if ($paidConfigId > 0 && !$paidConfig) {
$this->markFailed($recordId, '付费奖池配置不存在');
return;
}
if ($freeConfigId > 0 && !$freeConfig) {
$this->markFailed($recordId, '免费奖池配置不存在');
$configType0 = DiceLotteryPoolConfig::where('name', 'default')->find();
$configType1 = DiceLotteryPoolConfig::where('name', 'killScore')->find();
if (!$configType0) {
$this->markFailed($recordId, '彩金池配置 name=default 不存在');
return;
}
$safetyLine = (int) ($configType0->safety_line ?? 0);
$killEnabled = ((int) ($configType0->kill_enabled ?? 1)) === 1;
$paidTierWeights = (is_array($record->paid_tier_weights ?? null) && $record->paid_tier_weights !== [])
? $record->paid_tier_weights
: null;
$freeTierWeights = (is_array($record->free_tier_weights ?? null) && $record->free_tier_weights !== [])
? $record->free_tier_weights
: null;
if ($paidConfig === null && $paidTierWeights === null) {
$this->markFailed($recordId, '付费未选奖池时需提供 paid_tier_weights');
return;
}
if ($freeConfig === null && $freeTierWeights === null) {
$this->markFailed($recordId, '免费未选奖池时需提供 free_tier_weights');
: [
'T1' => (int) ($configType0->t1_weight ?? 0),
'T2' => (int) ($configType0->t2_weight ?? 0),
'T3' => (int) ($configType0->t3_weight ?? 0),
'T4' => (int) ($configType0->t4_weight ?? 0),
'T5' => (int) ($configType0->t5_weight ?? 0),
];
if (array_sum($paidTierWeights) <= 0) {
$this->markFailed($recordId, '需提供 paid_tier_weights(玩家权重,盈利未达安全线时付费抽奖使用)或选择 default 奖池');
return;
}
$freeConfig = $configType1 !== null ? $configType1 : $configType0;
// 每次测试开始前清空进程内静态缓存,强制从共享缓存读取最新 BIGWIN/奖励配置,与数据库一致
DiceRewardConfig::clearRequestInstance();
DiceReward::clearRequestInstance();
// 测试时按“单个虚拟玩家”累计中奖金额来判断是否触发杀分:达到 safety_line 前用自定义档位(玩家权重),达到后用奖池权重
$paidSafetyLine = $paidConfig !== null ? (int) ($paidConfig->safety_line ?? 0) : 0;
$freeSafetyLine = $freeConfig !== null ? (int) ($freeConfig->safety_line ?? 0) : 0;
$paidPlayerWinTotal = 0.0;
$freePlayerWinTotal = 0.0;
//“玩家”盈利: 玩家累计盈利:仅统计 lottery_config_id=default 的成功对局win_coin - 100与 PlayStartLogic 一致
$playerProfitTotal = 0.0;
$playLogic = new PlayStartLogic();
$resultCounts = [];
@@ -101,40 +91,36 @@ class WeightTestRunner
try {
for ($i = 0; $i < $paidS; $i++) {
$usePoolWeights = $paidConfig !== null && $paidPlayerWinTotal >= $paidSafetyLine && $paidSafetyLine > 0;
$usePoolWeights = $killEnabled && $playerProfitTotal >= $safetyLine && $configType1 !== null;
$paidConfig = $usePoolWeights ? $configType1 : $configType0;
$customWeights = $usePoolWeights ? null : $paidTierWeights;
$row = $playLogic->simulateOnePlay($paidConfig, 0, 0, $customWeights);
$this->accumulatePlayerWin($row, $paidPlayerWinTotal);
$this->accumulateProfitForDefault($row, 0, $paidConfig, $configType0, $playerProfitTotal);
$this->aggregate($row, $resultCounts, $tierCounts);
$buffer[] = $this->rowForInsert($row, $recordId);
$done++;
$this->flushIfNeeded($buffer, $recordId, $done, $total, $resultCounts, $tierCounts);
}
for ($i = 0; $i < $paidN; $i++) {
$usePoolWeights = $paidConfig !== null && $paidPlayerWinTotal >= $paidSafetyLine && $paidSafetyLine > 0;
$usePoolWeights = $killEnabled && $playerProfitTotal >= $safetyLine && $configType1 !== null;
$paidConfig = $usePoolWeights ? $configType1 : $configType0;
$customWeights = $usePoolWeights ? null : $paidTierWeights;
$row = $playLogic->simulateOnePlay($paidConfig, 1, 0, $customWeights);
$this->accumulatePlayerWin($row, $paidPlayerWinTotal);
$this->accumulateProfitForDefault($row, 0, $paidConfig, $configType0, $playerProfitTotal);
$this->aggregate($row, $resultCounts, $tierCounts);
$buffer[] = $this->rowForInsert($row, $recordId);
$done++;
$this->flushIfNeeded($buffer, $recordId, $done, $total, $resultCounts, $tierCounts);
}
for ($i = 0; $i < $freeS; $i++) {
$usePoolWeights = $freeConfig !== null && $freePlayerWinTotal >= $freeSafetyLine && $freeSafetyLine > 0;
$customWeights = $usePoolWeights ? null : $freeTierWeights;
$row = $playLogic->simulateOnePlay($freeConfig, 0, 1, $customWeights);
$this->accumulatePlayerWin($row, $freePlayerWinTotal);
$row = $playLogic->simulateOnePlay($freeConfig, 0, 1, null);
$this->aggregate($row, $resultCounts, $tierCounts);
$buffer[] = $this->rowForInsert($row, $recordId);
$done++;
$this->flushIfNeeded($buffer, $recordId, $done, $total, $resultCounts, $tierCounts);
}
for ($i = 0; $i < $freeN; $i++) {
$usePoolWeights = $freeConfig !== null && $freePlayerWinTotal >= $freeSafetyLine && $freeSafetyLine > 0;
$customWeights = $usePoolWeights ? null : $freeTierWeights;
$row = $playLogic->simulateOnePlay($freeConfig, 1, 1, $customWeights);
$this->accumulatePlayerWin($row, $freePlayerWinTotal);
$row = $playLogic->simulateOnePlay($freeConfig, 1, 1, null);
$this->aggregate($row, $resultCounts, $tierCounts);
$buffer[] = $this->rowForInsert($row, $recordId);
$done++;
@@ -152,13 +138,19 @@ class WeightTestRunner
}
}
/** 累加单个虚拟玩家在测试过程中的中奖金额win_coin */
private function accumulatePlayerWin(array $row, float &$runningWinTotal): void
/**
* 仅当付费抽奖且使用 default 池时累加玩家盈利win_coin - 100与 PlayStartLogic 一致
* @param object $usedConfig 本次使用的奖池配置
* @param object $configType0 name=default 的彩金池
*/
private function accumulateProfitForDefault(array $row, int $lotteryType, $usedConfig, $configType0, float &$playerProfitTotal): void
{
if (!isset($row['win_coin'])) {
if ($lotteryType !== 0 || $usedConfig === null || $configType0 === null || !isset($row['win_coin'])) {
return;
}
$runningWinTotal += (float) $row['win_coin'];
if ((int) $usedConfig->id === (int) $configType0->id) {
$playerProfitTotal += (float) $row['win_coin'] - 100.0;
}
}
private function aggregate(array $row, array &$resultCounts, array &$tierCounts): void