ChestNewManageAction.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. namespace App\Module\GameItems\AdminControllers\Actions;
  3. use App\Module\GameItems\Enums\ITEM_TYPE;
  4. use App\Module\GameItems\Models\Item;
  5. use App\Module\GameItems\Models\ItemChestConfig;
  6. use Illuminate\Http\Request;
  7. use UCore\DcatAdmin\RowActionHandler;
  8. /**
  9. * 宝箱新系统管理操作
  10. *
  11. * 为宝箱类型物品提供新系统(消耗组/奖励组)的快捷管理入口
  12. *
  13. * @property-read Item $row
  14. */
  15. class ChestNewManageAction extends RowActionHandler
  16. {
  17. /**
  18. * 操作按钮标题
  19. *
  20. * @var string
  21. */
  22. public $title = '宝箱配置';
  23. /**
  24. * 检查是否允许显示此操作
  25. *
  26. * @return bool
  27. */
  28. public function allowed()
  29. {
  30. return $this->row->type === ITEM_TYPE::CHEST;
  31. }
  32. /**
  33. * 处理请求
  34. *
  35. * @param Request $request
  36. * @return mixed
  37. */
  38. public function handle(Request $request)
  39. {
  40. $id = $this->getKey();
  41. $item = Item::find($id);
  42. if (!$item) {
  43. return $this->response()->error('宝箱不存在');
  44. }
  45. // 获取宝箱配置
  46. $chestConfig = ItemChestConfig::with(['consumeGroup', 'rewardGroup', 'conditionGroup'])
  47. ->where('item_id', $id)
  48. ->first();
  49. // 构建配置信息
  50. $config = [
  51. 'chest_id' => $id,
  52. 'chest_name' => $item->name,
  53. 'has_config' => $chestConfig !== null,
  54. 'is_active' => $chestConfig ? $chestConfig->is_active : false,
  55. 'consume_group' => $chestConfig && $chestConfig->consumeGroup ? [
  56. 'id' => $chestConfig->consumeGroup->id,
  57. 'name' => $chestConfig->consumeGroup->name,
  58. 'code' => $chestConfig->consumeGroup->code,
  59. ] : null,
  60. 'reward_group' => $chestConfig && $chestConfig->rewardGroup ? [
  61. 'id' => $chestConfig->rewardGroup->id,
  62. 'name' => $chestConfig->rewardGroup->name,
  63. 'code' => $chestConfig->rewardGroup->code,
  64. ] : null,
  65. 'condition_group' => $chestConfig && $chestConfig->conditionGroup ? [
  66. 'id' => $chestConfig->conditionGroup->id,
  67. 'name' => $chestConfig->conditionGroup->name,
  68. 'code' => $chestConfig->conditionGroup->code,
  69. ] : null,
  70. ];
  71. // 构建HTML内容
  72. $html = $this->buildConfigHtml($config);
  73. return $this->response()->success('宝箱V2配置信息')->detail($html);
  74. }
  75. /**
  76. * 构建配置信息HTML
  77. *
  78. * @param array $config
  79. * @return string
  80. */
  81. private function buildConfigHtml(array $config): string
  82. {
  83. $html = '<div class="card">';
  84. $html .= '<div class="card-header"><h5>宝箱配置信息</h5></div>';
  85. $html .= '<div class="card-body">';
  86. $html .= '<h6>基本信息</h6>';
  87. $html .= '<p><strong>宝箱ID:</strong> ' . $config['chest_id'] . '</p>';
  88. $html .= '<p><strong>宝箱名称:</strong> ' . $config['chest_name'] . '</p>';
  89. if (!$config['has_config']) {
  90. $html .= '<div class="alert alert-warning">';
  91. $html .= '<h6>未配置新系统</h6>';
  92. $html .= '<p>该宝箱尚未配置新系统,请先创建配置。</p>';
  93. $html .= '<a href="' . admin_url('game-items/chest-configs/create?item_id=' . $config['chest_id']) . '" class="btn btn-primary">创建配置</a>';
  94. $html .= '</div>';
  95. } else {
  96. $html .= '<p><strong>配置状态:</strong> ' . ($config['is_active'] ? '<span class="text-success">激活</span>' : '<span class="text-warning">未激活</span>') . '</p>';
  97. $html .= '<hr>';
  98. $html .= '<h6>消耗组配置</h6>';
  99. if ($config['consume_group']) {
  100. $html .= '<p><strong>消耗组ID:</strong> ' . $config['consume_group']['id'] . '</p>';
  101. $html .= '<p><strong>消耗组名称:</strong> ' . $config['consume_group']['name'] . '</p>';
  102. $html .= '<p><strong>消耗组编码:</strong> ' . $config['consume_group']['code'] . '</p>';
  103. $html .= '<a href="' . admin_url('game/consume-groups/' . $config['consume_group']['id']) . '" class="btn btn-sm btn-primary" target="_blank">查看消耗组详情</a>';
  104. } else {
  105. $html .= '<p class="text-muted">未配置消耗组(无额外消耗)</p>';
  106. }
  107. $html .= '<hr>';
  108. $html .= '<h6>奖励组配置</h6>';
  109. if ($config['reward_group']) {
  110. $html .= '<p><strong>奖励组ID:</strong> ' . $config['reward_group']['id'] . '</p>';
  111. $html .= '<p><strong>奖励组名称:</strong> ' . $config['reward_group']['name'] . '</p>';
  112. $html .= '<p><strong>奖励组编码:</strong> ' . $config['reward_group']['code'] . '</p>';
  113. $html .= '<a href="' . admin_url('game/reward-groups/' . $config['reward_group']['id']) . '" class="btn btn-sm btn-success" target="_blank">查看奖励组详情</a>';
  114. } else {
  115. $html .= '<p class="text-danger">未配置奖励组(无法开启宝箱)</p>';
  116. }
  117. $html .= '<hr>';
  118. $html .= '<h6>条件组配置</h6>';
  119. if ($config['condition_group']) {
  120. $html .= '<p><strong>条件组ID:</strong> ' . $config['condition_group']['id'] . '</p>';
  121. $html .= '<p><strong>条件组名称:</strong> ' . $config['condition_group']['name'] . '</p>';
  122. $html .= '<p><strong>条件组编码:</strong> ' . $config['condition_group']['code'] . '</p>';
  123. $html .= '<a href="' . admin_url('game/condition-groups/' . $config['condition_group']['id']) . '" class="btn btn-sm btn-info" target="_blank">查看条件组详情</a>';
  124. } else {
  125. $html .= '<p class="text-muted">未配置条件组(无条件限制)</p>';
  126. }
  127. }
  128. $html .= '<hr>';
  129. $html .= '<div class="text-center">';
  130. if ($config['has_config']) {
  131. $html .= '<a href="' . admin_url('game-items/chest-configs') . '" class="btn btn-primary">管理配置</a> ';
  132. }
  133. $html .= '<a href="' . admin_url('game-items/' . $config['chest_id'] . '/edit') . '" class="btn btn-warning">编辑宝箱基本信息</a>';
  134. $html .= '</div>';
  135. $html .= '</div>';
  136. $html .= '</div>';
  137. return $html;
  138. }
  139. }