优化一键测试权重

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

@@ -30,20 +30,22 @@ class DiceLotteryPoolConfigController extends BaseController
}
/**
* 获取 DiceLotteryPoolConfig 列表数据,用于 lottery_config_id 下拉(值为 id显示为 name并附带 T1-T5 档位权重
* 获取 DiceLotteryPoolConfig 列表数据,用于 lottery_config_id 下拉(值为 id显示为 name并附带 type、T1-T5 档位权重
* type0=付费抽奖券1=免费抽奖券;一键测试权重中付费默认选 type=0免费默认选 type=1
* @param Request $request
* @return Response 返回 [ ['id' => int, 'name' => string, 't1_weight' => int, ... 't5_weight' => int], ... ]
* @return Response 返回 [ ['id' => int, 'name' => string, 'type' => int, 't1_weight' => int, ... 't5_weight' => int], ... ]
*/
#[Permission('色子奖池配置列表', 'dice:lottery_pool_config:index:index')]
public function getOptions(Request $request): Response
{
$list = DiceLotteryPoolConfig::field('id,name,t1_weight,t2_weight,t3_weight,t4_weight,t5_weight')
$list = DiceLotteryPoolConfig::field('id,name,type,t1_weight,t2_weight,t3_weight,t4_weight,t5_weight')
->order('id', 'asc')
->select();
$data = $list->map(function ($item) {
return [
'id' => (int) $item['id'],
'name' => (string) ($item['name'] ?? ''),
'type' => (int) ($item['type'] ?? 0),
't1_weight' => (int) ($item['t1_weight'] ?? 0),
't2_weight' => (int) ($item['t2_weight'] ?? 0),
't3_weight' => (int) ($item['t3_weight'] ?? 0),

View File

@@ -30,7 +30,7 @@ class DicePlayRecordTestController extends BaseController
}
/**
* 数据列表,并在结果中附带当前筛选条件下所有测试数据的玩家总收益 total_win_coinDicePlayRecordTest.win_coin 求和
* 数据列表,并在结果中附带当前筛选条件下测试数据的平台总盈利 total_win_coin付费抽奖次数×100 - 玩家总收益
* @param Request $request
* @return Response
*/
@@ -44,13 +44,17 @@ class DicePlayRecordTestController extends BaseController
['win_coin_min', ''],
['win_coin_max', ''],
['reward_tier', ''],
['roll_number', ''],
]);
$query = $this->logic->search($where);
$query->with(['diceLotteryPoolConfig', 'diceRewardConfig']);
// 按当前筛选条件统计所有测试数据的总收益(游戏总亏损)
// 按当前筛选条件统计:平台总盈利 = 付费抽奖(lottery_type=0)次数×100 - 玩家总收益(win_coin 求和)
$sumQuery = clone $query;
$totalWinCoin = $sumQuery->sum('win_coin');
$playerTotalWin = (float) $sumQuery->sum('win_coin');
$paidCountQuery = clone $query;
$paidCount = (int) $paidCountQuery->where('lottery_type', 0)->count();
$totalWinCoin = $paidCount * 100 - $playerTotalWin;
$data = $this->logic->getList($query);
$data['total_win_coin'] = $totalWinCoin;

View File

@@ -79,20 +79,31 @@ class DiceRewardController extends BaseController
}
/**
* 一键测试权重:创建测试记录并启动单进程后台执行,实时写入 dice_play_record_test,更新 dice_reward_config_record 进度
* 参数lottery_config_id 奖池配置s_count 顺时针次数 100/500/1000/5000n_count 逆时针次数 100/500/1000/5000
* 一键测试权重:创建测试记录并启动单进程后台执行,按付费/免费、顺逆方向交替写入 dice_play_record_test
* 参数lottery_config_id 可选,不选则传 paid_tier_weights / free_tier_weights 自定义档位;
* paid_s_count, paid_n_count, free_s_count, free_n_count或兼容旧版 s_count, n_count
*/
#[Permission('奖励对照列表', 'dice:reward:index:index')]
public function startWeightTest(Request $request): Response
{
$lotteryConfigId = (int) $request->post('lottery_config_id', 0);
$sCount = (int) $request->post('s_count', 100);
$nCount = (int) $request->post('n_count', 100);
$post = is_array($request->post()) ? $request->post() : [];
$params = [
'lottery_config_id' => $post['lottery_config_id'] ?? null,
'paid_lottery_config_id' => $post['paid_lottery_config_id'] ?? null,
'free_lottery_config_id' => $post['free_lottery_config_id'] ?? null,
's_count' => $post['s_count'] ?? null,
'n_count' => $post['n_count'] ?? null,
'paid_s_count' => $post['paid_s_count'] ?? null,
'paid_n_count' => $post['paid_n_count'] ?? null,
'free_s_count' => $post['free_s_count'] ?? null,
'free_n_count' => $post['free_n_count'] ?? null,
'paid_tier_weights' => $post['paid_tier_weights'] ?? null,
'free_tier_weights' => $post['free_tier_weights'] ?? null,
];
$adminId = isset($this->adminInfo['id']) ? (int) $this->adminInfo['id'] : null;
try {
$logic = new DiceRewardConfigRecordLogic();
$recordId = $logic->createWeightTestRecord($lotteryConfigId, $sCount, $nCount, $adminId);
// 由独立进程 WeightTestProcess 定时轮询 status=0 并执行,不占用 HTTP 资源
$recordId = $logic->createWeightTestRecord($params, $adminId);
return $this->success(['record_id' => $recordId]);
} catch (\plugin\saiadmin\exception\ApiException $e) {
return $this->fail($e->getMessage());

View File

@@ -141,26 +141,25 @@ class DiceRewardConfigRecordController extends BaseController
}
/**
* 导入:测试记录的权重写入 DiceRewardConfig 与 DiceLotteryPoolConfig,并重新实例化缓存
* @param Request $request record_id: 测试记录ID, lottery_config_id: 可选导入档位权重到的奖池配置ID不传则用记录内的 lottery_config_id
* @return Response
* 导入:测试记录 DiceReward、DiceRewardConfig(BIGWIN)、DiceLotteryPoolConfig(付费/免费 T1-T5)
* @param Request $request record_id, paid_lottery_config_id(可选), free_lottery_config_id(可选), lottery_config_id(兼容旧版)
*/
#[Permission('奖励配置权重测试记录列表', 'dice:reward_config_record:index:index')]
public function importFromRecord(Request $request): Response
{
$recordId = (int) $request->post('record_id', 0);
$lotteryConfigId = $request->post('lottery_config_id', null);
if ($recordId <= 0) {
return $this->fail('请指定测试记录');
}
if ($lotteryConfigId !== null && $lotteryConfigId !== '') {
$lotteryConfigId = (int) $lotteryConfigId;
} else {
$lotteryConfigId = null;
}
$paidId = $request->post('paid_lottery_config_id', null);
$freeId = $request->post('free_lottery_config_id', null);
$legacyId = $request->post('lottery_config_id', null);
$paidLotteryConfigId = $paidId !== null && $paidId !== '' ? (int) $paidId : null;
$freeLotteryConfigId = $freeId !== null && $freeId !== '' ? (int) $freeId : null;
$lotteryConfigId = $legacyId !== null && $legacyId !== '' ? (int) $legacyId : null;
try {
$this->logic->importFromRecord($recordId, $lotteryConfigId);
return $this->success('导入成功,已刷新奖励配置与奖池配置');
$this->logic->importFromRecord($recordId, $paidLotteryConfigId, $freeLotteryConfigId, $lotteryConfigId);
return $this->success('导入成功,已刷新 DiceReward、DiceRewardConfig(BIGWIN)、奖池配置');
} catch (\plugin\saiadmin\exception\ApiException $e) {
return $this->fail($e->getMessage());
}