[色子游戏]玩家抽奖记录测试数据

This commit is contained in:
2026-03-12 19:21:10 +08:00
parent 7e4ba86afa
commit cc7e2d9a1a
21 changed files with 1712 additions and 4 deletions

View File

@@ -5,8 +5,12 @@
namespace app\dice\controller\reward;
use app\dice\logic\reward\DiceRewardLogic;
use app\dice\logic\reward_config_record\DiceRewardConfigRecordLogic;
use app\dice\model\reward\DiceReward;
use app\dice\model\play_record_test\DicePlayRecordTest;
use app\dice\model\reward_config_record\DiceRewardConfigRecord;
use plugin\saiadmin\basic\BaseController;
use support\think\Db;
use plugin\saiadmin\service\Permission;
use support\Request;
use support\Response;
@@ -74,6 +78,68 @@ class DiceRewardController extends BaseController
return $this->success($data);
}
/**
* 一键测试权重:创建测试记录并启动单进程后台执行,实时写入 dice_play_record_test更新 dice_reward_config_record 进度
* 参数lottery_config_id 奖池配置s_count 顺时针次数 100/500/1000/5000n_count 逆时针次数 100/500/1000/5000
*/
#[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);
$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 资源
return $this->success(['record_id' => $recordId]);
} catch (\plugin\saiadmin\exception\ApiException $e) {
return $this->fail($e->getMessage());
}
}
/**
* 查询一键测试进度total_play_count、over_play_count、status、remark
*/
#[Permission('奖励对照列表', 'dice:reward:index:index')]
public function getTestProgress(Request $request): Response
{
$recordId = (int) $request->input('record_id', 0);
if ($recordId <= 0) {
return $this->fail('请传入 record_id');
}
$record = DiceRewardConfigRecord::find($recordId);
if (!$record) {
return $this->fail('记录不存在');
}
$arr = $record->toArray();
$data = [
'total_play_count' => (int) ($arr['total_play_count'] ?? 0),
'over_play_count' => (int) ($arr['over_play_count'] ?? 0),
'status' => (int) ($arr['status'] ?? 0),
'remark' => $arr['remark'] ?? null,
'result_counts' => $arr['result_counts'] ?? null,
'tier_counts' => $arr['tier_counts'] ?? null,
];
return $this->success($data);
}
/**
* 一键清空测试数据:清空 dice_play_record_test 表
*/
#[Permission('奖励对照列表', 'dice:reward:index:index')]
public function clearPlayRecordTest(Request $request): Response
{
try {
$table = (new DicePlayRecordTest())->getTable();
Db::execute('TRUNCATE TABLE `' . $table . '`');
return $this->success('已清空测试数据');
} catch (\Throwable $e) {
return $this->fail('清空失败:' . $e->getMessage());
}
}
/**
* 权重编辑弹窗:按方向+点数批量更新权重(写入 dice_reward
* 参数items: [{ grid_number, weight_clockwise, weight_counterclockwise }, ...]