| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace App\Module\GameItems\AdminControllers\Actions;
- use App\Module\GameItems\Models\ItemChestContent;
- use Illuminate\Http\Request;
- use UCore\DcatAdmin\RowActionHandler;
- /**
- * 查看物品详情
- *
- * 在宝箱内容管理行中添加查看物品详情的快捷操作
- */
- class ViewItemDetailAction extends RowActionHandler
- {
- /**
- * 操作按钮标题
- *
- * @var string
- */
- public $title = '物品详情';
- /**
- * 判断是否允许显示此操作
- *
- * @return bool
- */
- public function allowed()
- {
- // 只有当内容是物品而不是物品组时才显示此操作
- return !empty($this->row->item_id) && empty($this->row->group_id);
- }
- /**
- * 处理请求
- *
- * @param Request $request
- * @return mixed
- */
- public function handle(Request $request)
- {
- $id = $this->getKey();
- $content = ItemChestContent::with('item')->find($id);
-
- if (!$content || !$content->item_id) {
- return $this->response()->error('物品不存在或此内容为物品组');
- }
-
- // 跳转到物品详情页面
- return $this->response()->redirect(
- admin_url("game-items/{$content->item_id}")
- );
- }
- }
|