| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <?php
- namespace App\Module\GameItems\AdminControllers;
- use App\Module\GameItems\Repositorys\ItemPityTimeRepository;
- 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 UCore\DcatAdmin\FilterHelper;
- use UCore\DcatAdmin\GridHelper;
- use UCore\DcatAdmin\ShowHelper;
- #[Resource('game-items-pity-times', names: 'dcat.admin.game-items-pity-times')]
- class PityTimeController extends AdminController
- {
- /**
- * 标题
- *
- * @var string
- */
- protected $title = '用户宝箱保底计数';
- /**
- * 禁用创建按钮
- *
- * @var bool
- */
- protected $showCreateButton = false;
- /**
- * 列表页
- *
- * @return Grid
- */
- protected function grid()
- {
- return Grid::make(new ItemPityTimeRepository(), function (Grid $grid) {
- // 禁用创建、编辑和删除按钮
- $grid->disableCreateButton();
- $grid->disableActions();
- $grid->disableBatchDelete();
- $grid->disableDeleteButton();
- $grid->disableEditButton();
- // 只保留详情按钮
- $grid->actions(function (Grid\Displayers\Actions $actions) {
- $actions->disableDelete();
- $actions->disableEdit();
- $actions->disableQuickEdit();
- });
- $helper = new GridHelper($grid, $this);
- $helper->columnId();
- $grid->column('user_id', '用户ID');
- $grid->column('chest.name', '宝箱名称');
- $grid->column('chest_content_id', '宝箱内容ID');
- $grid->column('current_count', '当前计数');
- $grid->column('created_at', '创建时间');
- $grid->column('updated_at', '更新时间');
- // 筛选
- $grid->filter(function ($filter) {
- $helper = new FilterHelper($filter, $this);
- $helper->equal('id', 'ID');
- $helper->equal('user_id', '用户ID');
- $filter->equal('chest_id', '宝箱')->select(
- (new ItemRepository())->where('type', 5)->pluck('name', 'id')
- );
- $helper->equal('chest_content_id', '宝箱内容ID');
- $helper->between('current_count', '当前计数');
- });
- });
- }
- /**
- * 详情页
- *
- * @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)
- {
- return Show::make((new ItemPityTimeRepository())->findOrFail($id), function (Show $show) {
- // 禁用编辑和删除按钮
- $show->panel()->tools(function ($tools) {
- $tools->disableEdit();
- $tools->disableDelete();
- });
- $helper = new ShowHelper($show, $this);
- $helper->field('id', 'ID');
- $show->field('user_id', '用户ID');
- $show->field('chest.name', '宝箱名称');
- // 显示宝箱内容信息
- $show->field('chest_content_id', '宝箱内容ID');
- $show->field('chestContent.item.name', '内容物品名称');
- $show->field('chestContent.group.name', '内容物品组名称');
- $show->field('chestContent.pity_count', '保底次数');
- $show->field('chestContent.pity_weight_factor', '保底权重因子');
- $show->field('current_count', '当前计数');
- // 计算距离保底还需次数
- $show->field('remaining_count', '距离保底还需次数')->as(function () {
- if (!$this->chestContent || !$this->chestContent->pity_count) {
- return '无保底机制';
- }
- $remaining = max(0, $this->chestContent->pity_count - $this->current_count);
- return $remaining;
- });
- $helper->field('created_at', '创建时间');
- $helper->field('updated_at', '更新时间');
- });
- }
- }
|