| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- <?php
- namespace App\Module\GameItems\AdminControllers\Actions;
- use App\Module\GameItems\Enums\ITEM_TYPE;
- use App\Module\GameItems\Models\Item;
- use App\Module\GameItems\Models\ItemChestConfig;
- use Illuminate\Http\Request;
- use UCore\DcatAdmin\RowActionHandler;
- /**
- * 宝箱新系统管理操作
- *
- * 为宝箱类型物品提供新系统(消耗组/奖励组)的快捷管理入口
- *
- * @property-read Item $row
- */
- class ChestNewManageAction extends RowActionHandler
- {
- /**
- * 操作按钮标题
- *
- * @var string
- */
- public $title = '宝箱配置';
- /**
- * 检查是否允许显示此操作
- *
- * @return bool
- */
- public function allowed()
- {
- return $this->row->type === ITEM_TYPE::CHEST;
- }
- /**
- * 处理请求
- *
- * @param Request $request
- * @return mixed
- */
- public function handle(Request $request)
- {
- $id = $this->getKey();
- $item = Item::find($id);
- if (!$item) {
- return $this->response()->error('宝箱不存在');
- }
- // 获取宝箱配置
- $chestConfig = ItemChestConfig::with(['consumeGroup', 'rewardGroup', 'conditionGroup'])
- ->where('item_id', $id)
- ->first();
- // 构建配置信息
- $config = [
- 'chest_id' => $id,
- 'chest_name' => $item->name,
- 'has_config' => $chestConfig !== null,
- 'is_active' => $chestConfig ? $chestConfig->is_active : false,
- 'consume_group' => $chestConfig && $chestConfig->consumeGroup ? [
- 'id' => $chestConfig->consumeGroup->id,
- 'name' => $chestConfig->consumeGroup->name,
- 'code' => $chestConfig->consumeGroup->code,
- ] : null,
- 'reward_group' => $chestConfig && $chestConfig->rewardGroup ? [
- 'id' => $chestConfig->rewardGroup->id,
- 'name' => $chestConfig->rewardGroup->name,
- 'code' => $chestConfig->rewardGroup->code,
- ] : null,
- 'condition_group' => $chestConfig && $chestConfig->conditionGroup ? [
- 'id' => $chestConfig->conditionGroup->id,
- 'name' => $chestConfig->conditionGroup->name,
- 'code' => $chestConfig->conditionGroup->code,
- ] : null,
- ];
- // 构建HTML内容
- $html = $this->buildConfigHtml($config);
- return $this->response()->success('宝箱V2配置信息')->detail($html);
- }
- /**
- * 构建配置信息HTML
- *
- * @param array $config
- * @return string
- */
- private function buildConfigHtml(array $config): string
- {
- $html = '<div class="card">';
- $html .= '<div class="card-header"><h5>宝箱配置信息</h5></div>';
- $html .= '<div class="card-body">';
- $html .= '<h6>基本信息</h6>';
- $html .= '<p><strong>宝箱ID:</strong> ' . $config['chest_id'] . '</p>';
- $html .= '<p><strong>宝箱名称:</strong> ' . $config['chest_name'] . '</p>';
- if (!$config['has_config']) {
- $html .= '<div class="alert alert-warning">';
- $html .= '<h6>未配置新系统</h6>';
- $html .= '<p>该宝箱尚未配置新系统,请先创建配置。</p>';
- $html .= '<a href="' . admin_url('game-items/chest-configs/create?item_id=' . $config['chest_id']) . '" class="btn btn-primary">创建配置</a>';
- $html .= '</div>';
- } else {
- $html .= '<p><strong>配置状态:</strong> ' . ($config['is_active'] ? '<span class="text-success">激活</span>' : '<span class="text-warning">未激活</span>') . '</p>';
- $html .= '<hr>';
- $html .= '<h6>消耗组配置</h6>';
- if ($config['consume_group']) {
- $html .= '<p><strong>消耗组ID:</strong> ' . $config['consume_group']['id'] . '</p>';
- $html .= '<p><strong>消耗组名称:</strong> ' . $config['consume_group']['name'] . '</p>';
- $html .= '<p><strong>消耗组编码:</strong> ' . $config['consume_group']['code'] . '</p>';
- $html .= '<a href="' . admin_url('game/consume-groups/' . $config['consume_group']['id']) . '" class="btn btn-sm btn-primary" target="_blank">查看消耗组详情</a>';
- } else {
- $html .= '<p class="text-muted">未配置消耗组(无额外消耗)</p>';
- }
- $html .= '<hr>';
- $html .= '<h6>奖励组配置</h6>';
- if ($config['reward_group']) {
- $html .= '<p><strong>奖励组ID:</strong> ' . $config['reward_group']['id'] . '</p>';
- $html .= '<p><strong>奖励组名称:</strong> ' . $config['reward_group']['name'] . '</p>';
- $html .= '<p><strong>奖励组编码:</strong> ' . $config['reward_group']['code'] . '</p>';
- $html .= '<a href="' . admin_url('game/reward-groups/' . $config['reward_group']['id']) . '" class="btn btn-sm btn-success" target="_blank">查看奖励组详情</a>';
- } else {
- $html .= '<p class="text-danger">未配置奖励组(无法开启宝箱)</p>';
- }
- $html .= '<hr>';
- $html .= '<h6>条件组配置</h6>';
- if ($config['condition_group']) {
- $html .= '<p><strong>条件组ID:</strong> ' . $config['condition_group']['id'] . '</p>';
- $html .= '<p><strong>条件组名称:</strong> ' . $config['condition_group']['name'] . '</p>';
- $html .= '<p><strong>条件组编码:</strong> ' . $config['condition_group']['code'] . '</p>';
- $html .= '<a href="' . admin_url('game/condition-groups/' . $config['condition_group']['id']) . '" class="btn btn-sm btn-info" target="_blank">查看条件组详情</a>';
- } else {
- $html .= '<p class="text-muted">未配置条件组(无条件限制)</p>';
- }
- }
- $html .= '<hr>';
- $html .= '<div class="text-center">';
- if ($config['has_config']) {
- $html .= '<a href="' . admin_url('game-items/chest-configs') . '" class="btn btn-primary">管理配置</a> ';
- }
- $html .= '<a href="' . admin_url('game-items/' . $config['chest_id'] . '/edit') . '" class="btn btn-warning">编辑宝箱基本信息</a>';
- $html .= '</div>';
- $html .= '</div>';
- $html .= '</div>';
- return $html;
- }
- }
|