ViewGroupDetailAction.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace App\Module\GameItems\AdminControllers\Actions;
  3. use App\Module\GameItems\Models\ItemChestContent;
  4. use Illuminate\Http\Request;
  5. use UCore\DcatAdmin\RowActionHandler;
  6. /**
  7. * 查看物品组详情
  8. *
  9. * 在宝箱内容管理行中添加查看物品组详情的快捷操作
  10. */
  11. class ViewGroupDetailAction extends RowActionHandler
  12. {
  13. /**
  14. * 操作按钮标题
  15. *
  16. * @var string
  17. */
  18. public $title = '物品组详情';
  19. /**
  20. * 判断是否允许显示此操作
  21. *
  22. * @return bool
  23. */
  24. public function allowed()
  25. {
  26. // 只有当内容是物品组而不是物品时才显示此操作
  27. return !empty($this->row->group_id) && empty($this->row->item_id);
  28. }
  29. /**
  30. * 处理请求
  31. *
  32. * @param Request $request
  33. * @return mixed
  34. */
  35. public function handle(Request $request)
  36. {
  37. $id = $this->getKey();
  38. $content = ItemChestContent::with('group')->find($id);
  39. if (!$content || !$content->group_id) {
  40. return $this->response()->error('物品组不存在或此内容为单个物品');
  41. }
  42. // 跳转到物品组详情页面
  43. return $this->response()->redirect(
  44. admin_url("game-items-groups/{$content->group_id}")
  45. );
  46. }
  47. }