|
|
@@ -0,0 +1,210 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Module\GameItems\AdminControllers;
|
|
|
+
|
|
|
+use App\Module\GameItems\Enums\FREEZE_ACTION_TYPE;
|
|
|
+use App\Module\GameItems\Repositorys\ItemFreezeLogRepository;
|
|
|
+use App\Module\GameItems\Repositorys\ItemRepository;
|
|
|
+use Dcat\Admin\Grid;
|
|
|
+use Dcat\Admin\Show;
|
|
|
+use UCore\DcatAdmin\AdminController;
|
|
|
+use Dcat\Admin\Layout\Content;
|
|
|
+use Spatie\RouteAttributes\Attributes\Resource;
|
|
|
+use App\Module\GameItems\AdminControllers\Helper\FilterHelper;
|
|
|
+use App\Module\GameItems\AdminControllers\Helper\GridHelper;
|
|
|
+use App\Module\GameItems\AdminControllers\Helper\ShowHelper;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 物品冻结日志管理控制器
|
|
|
+ *
|
|
|
+ * 路由: /admin/game-items-freeze-logs
|
|
|
+ * 菜单: 游戏管理 -> 游戏物品管理 -> 物品冻结日志
|
|
|
+ *
|
|
|
+ * @package App\Module\GameItems\AdminControllers
|
|
|
+ */
|
|
|
+#[Resource('game-items-freeze-logs', names: 'dcat.admin.game-items-freeze-logs')]
|
|
|
+class FreezeLogController extends AdminController
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * 标题
|
|
|
+ *
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
+ protected $title = '物品冻结日志';
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 禁用创建按钮
|
|
|
+ *
|
|
|
+ * @var bool
|
|
|
+ */
|
|
|
+ protected $showCreateButton = false;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 禁用编辑按钮
|
|
|
+ *
|
|
|
+ * @var bool
|
|
|
+ */
|
|
|
+ protected $showEditButton = false;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 禁用删除按钮
|
|
|
+ *
|
|
|
+ * @var bool
|
|
|
+ */
|
|
|
+ protected $showDeleteButton = false;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取数据仓库
|
|
|
+ *
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ protected function repository(): string
|
|
|
+ {
|
|
|
+ return ItemFreezeLogRepository::class;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 列表页
|
|
|
+ *
|
|
|
+ * @param Content $content
|
|
|
+ * @return Content
|
|
|
+ */
|
|
|
+ public function index(Content $content)
|
|
|
+ {
|
|
|
+ return $content
|
|
|
+ ->header($this->title)
|
|
|
+ ->description('列表')
|
|
|
+ ->body($this->grid());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建数据表格
|
|
|
+ *
|
|
|
+ * @return Grid
|
|
|
+ */
|
|
|
+ protected function grid(): Grid
|
|
|
+ {
|
|
|
+ return Grid::make(new ItemFreezeLogRepository(), function (Grid $grid) {
|
|
|
+ new GridHelper($grid, $this);
|
|
|
+
|
|
|
+ // 基础字段
|
|
|
+ $grid->column('id', 'ID')->sortable();
|
|
|
+ $grid->column('user_id', '用户ID')->sortable();
|
|
|
+
|
|
|
+ // 物品信息
|
|
|
+ $grid->column('item.name', '物品名称')->display(function ($name) {
|
|
|
+ return $name ?: '未知物品';
|
|
|
+ });
|
|
|
+ $grid->column('item_id', '物品ID')->sortable();
|
|
|
+ $grid->column('instance_id', '实例ID')->display(function ($value) {
|
|
|
+ return $value ?: '-';
|
|
|
+ });
|
|
|
+
|
|
|
+ // 操作信息
|
|
|
+ $grid->column('quantity', '数量')->sortable();
|
|
|
+ $grid->column('action_type', '操作类型')->display(function ($value) {
|
|
|
+ return $value === FREEZE_ACTION_TYPE::FREEZE ?
|
|
|
+ '<span class="badge badge-danger">冻结</span>' :
|
|
|
+ '<span class="badge badge-success">解冻</span>';
|
|
|
+ });
|
|
|
+ $grid->column('reason', '操作原因')->limit(30);
|
|
|
+
|
|
|
+ // 来源信息
|
|
|
+ $grid->column('source_type', '来源类型');
|
|
|
+ $grid->column('source_id', '来源ID');
|
|
|
+ $grid->column('operator_id', '操作员ID')->display(function ($value) {
|
|
|
+ return $value ?: '系统';
|
|
|
+ });
|
|
|
+
|
|
|
+ // 时间信息
|
|
|
+ $grid->column('created_at', '操作时间')->sortable();
|
|
|
+
|
|
|
+ // 默认排序
|
|
|
+ $grid->model()->orderBy('id', 'desc');
|
|
|
+
|
|
|
+ // 禁用操作按钮(日志表只读)
|
|
|
+ $grid->disableCreateButton();
|
|
|
+ $grid->disableEditButton();
|
|
|
+ $grid->disableDeleteButton();
|
|
|
+ $grid->disableBatchActions();
|
|
|
+
|
|
|
+ // 筛选
|
|
|
+ $grid->filter(function ($filter) {
|
|
|
+ $helper = new FilterHelper($filter, $this);
|
|
|
+ $helper->equal('id', 'ID');
|
|
|
+ $helper->equal('user_id', '用户ID');
|
|
|
+ $filter->equal('item_id', '物品')->select(
|
|
|
+ \App\Module\GameItems\Models\Item::pluck('name', 'id')
|
|
|
+ );
|
|
|
+ $helper->equal('instance_id', '实例ID');
|
|
|
+ $filter->equal('action_type', '操作类型')->select([
|
|
|
+ FREEZE_ACTION_TYPE::FREEZE->value => '冻结',
|
|
|
+ FREEZE_ACTION_TYPE::UNFREEZE->value => '解冻'
|
|
|
+ ]);
|
|
|
+ $filter->like('reason', '操作原因');
|
|
|
+ $helper->equal('source_type', '来源类型');
|
|
|
+ $helper->equal('source_id', '来源ID');
|
|
|
+ $helper->equal('operator_id', '操作员ID');
|
|
|
+ $filter->between('created_at', '操作时间')->datetime();
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 详情页
|
|
|
+ *
|
|
|
+ * @param mixed $id
|
|
|
+ * @param Content $content
|
|
|
+ * @return Content
|
|
|
+ */
|
|
|
+ public function show($id, Content $content)
|
|
|
+ {
|
|
|
+ return $content
|
|
|
+ ->header($this->title)
|
|
|
+ ->description('详情')
|
|
|
+ ->body($this->detail($id));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建详情页
|
|
|
+ *
|
|
|
+ * @param mixed $id
|
|
|
+ * @return Show
|
|
|
+ */
|
|
|
+ protected function detail($id): Show
|
|
|
+ {
|
|
|
+ return Show::make($id, new ItemFreezeLogRepository(), function (Show $show) {
|
|
|
+ $helper = new ShowHelper($show, $this);
|
|
|
+
|
|
|
+ // 基础信息
|
|
|
+ $helper->field('id', 'ID');
|
|
|
+ $helper->field('user_id', '用户ID');
|
|
|
+
|
|
|
+ // 物品信息
|
|
|
+ $helper->field('item.name', '物品名称');
|
|
|
+ $helper->field('item_id', '物品ID');
|
|
|
+ $helper->field('instance_id', '实例ID');
|
|
|
+
|
|
|
+ // 操作信息
|
|
|
+ $helper->field('quantity', '数量');
|
|
|
+ $helper->field('action_type', '操作类型')->as(function ($value) {
|
|
|
+ if ($value instanceof FREEZE_ACTION_TYPE) {
|
|
|
+ return $value === FREEZE_ACTION_TYPE::FREEZE ? '冻结' : '解冻';
|
|
|
+ }
|
|
|
+ return FREEZE_ACTION_TYPE::getName($value);
|
|
|
+ });
|
|
|
+ $helper->field('reason', '操作原因');
|
|
|
+
|
|
|
+ // 来源信息
|
|
|
+ $helper->field('source_type', '来源类型');
|
|
|
+ $helper->field('source_id', '来源ID');
|
|
|
+ $helper->field('operator_id', '操作员ID')->as(function ($value) {
|
|
|
+ return $value ?: '系统';
|
|
|
+ });
|
|
|
+
|
|
|
+ // 时间信息
|
|
|
+ $helper->field('created_at', '操作时间');
|
|
|
+ $helper->field('updated_at', '更新时间');
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|