游戏-奖励配置-优化样式,新增创建指定表单btn,新增创建奖励权重配置btn

This commit is contained in:
2026-04-13 16:27:25 +08:00
parent 6c94d03ddf
commit c9d21d8216
8 changed files with 1112 additions and 23 deletions

View File

@@ -7,6 +7,8 @@ namespace app\admin\controller\game;
use Throwable;
use app\common\controller\Backend;
use app\common\library\GameRewardConfigTemplate;
use app\common\library\GameRewardTierBoardGenerator;
use app\common\library\GameRewardWeightSeeder;
use app\common\model\GameRewardConfig;
use app\common\validate\GameRewardConfig as GameRewardConfigValidate;
use support\think\Db;
@@ -117,6 +119,117 @@ class RewardConfig extends Backend
return $this->success(__('Update successful'));
}
/**
* 按条数与结算标准生成 26 格档位奖励并保存(保留当前 bigwin_form
*/
public function generateTierBoard(WebmanRequest $request): Response
{
$response = $this->initializeBackend($request);
if ($response !== null) {
return $response;
}
if ($request->method() !== 'POST') {
return $this->error(__('Parameter error'));
}
$data = $request->post();
if (!$data || !is_array($data)) {
return $this->error(__('Parameter %s can not be empty', ['']));
}
[$channelId, $err] = $this->resolveTargetChannelId($request, true);
if ($err !== null) {
return $err;
}
if (!$this->channelExists($channelId)) {
return $this->error(__('Record not found'));
}
try {
$out = GameRewardTierBoardGenerator::generate($data);
} catch (Throwable $e) {
return $this->error($e->getMessage());
}
$tier = $out['tier_reward_form'];
$existing = GameRewardConfig::where('game_channel_id', $channelId)->find();
if ($existing && is_string($existing->bigwin_form) && trim($existing->bigwin_form) !== '') {
$big = $existing->bigwin_form;
} else {
$defaults = GameRewardConfigTemplate::getDefaultJsonColumns();
$big = $defaults['bigwin_form'];
}
try {
$validate = new GameRewardConfigValidate();
$validate->scene('channel_form')->check([
'tier_reward_form' => $tier,
'bigwin_form' => $big,
]);
} catch (Throwable $e) {
return $this->error($e->getMessage());
}
try {
if ($existing) {
$existing->save([
'tier_reward_form' => $tier,
'bigwin_form' => $big,
]);
} else {
$m = new GameRewardConfig();
$m->save([
'game_channel_id' => $channelId,
'tier_reward_form' => $tier,
'bigwin_form' => $big,
]);
}
} catch (Throwable $e) {
return $this->error($e->getMessage());
}
return $this->success(__('Update successful'));
}
/**
* 根据当前档位奖励 JSON 生成 game_reward_weight先清空该渠道再写入 52 条)
*/
public function generateRewardWeight(WebmanRequest $request): Response
{
$response = $this->initializeBackend($request);
if ($response !== null) {
return $response;
}
if ($request->method() !== 'POST') {
return $this->error(__('Parameter error'));
}
[$channelId, $err] = $this->resolveTargetChannelId($request, true);
if ($err !== null) {
return $err;
}
if (!$this->channelExists($channelId)) {
return $this->error(__('Record not found'));
}
$row = GameRewardConfig::where('game_channel_id', $channelId)->find();
if (!$row || !is_string($row->tier_reward_form) || trim($row->tier_reward_form) === '') {
return $this->error('请先保存档位奖励配置');
}
try {
GameRewardWeightSeeder::syncFromTierRewardForm($channelId, $row->tier_reward_form);
} catch (Throwable $e) {
return $this->error($e->getMessage());
}
return $this->success(__('Update successful'));
}
/**
* @return array{0: int, 1: Response|null}
*/