PityTimeController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. namespace App\Module\GameItems\AdminControllers;
  3. use App\Module\GameItems\Models\ItemPityTime;
  4. use App\Module\GameItems\Models\ItemItem;
  5. use App\Module\GameItems\Models\ItemChestContent;
  6. use Dcat\Admin\Grid;
  7. use Dcat\Admin\Show;
  8. use UCore\DcatAdmin\AdminController;
  9. use Dcat\Admin\Layout\Content;
  10. use Spatie\RouteAttributes\Attributes\Resource;
  11. use UCore\DcatAdmin\FilterHelper;
  12. use UCore\DcatAdmin\FormHelper;
  13. use UCore\DcatAdmin\GridHelper;
  14. use UCore\DcatAdmin\ShowHelper;
  15. #[Resource('game-items-pity-times', names: 'dcat.admin.game-items-pity-times')]
  16. class PityTimeController extends AdminController
  17. {
  18. /**
  19. * 标题
  20. *
  21. * @var string
  22. */
  23. protected $title = '用户宝箱保底计数';
  24. /**
  25. * 禁用创建按钮
  26. *
  27. * @var bool
  28. */
  29. protected $showCreateButton = false;
  30. /**
  31. * 列表页
  32. *
  33. * @return Grid
  34. */
  35. protected function grid()
  36. {
  37. return Grid::make(new ItemPityTime(), function (Grid $grid) {
  38. $helper = new GridHelper($grid, $this);
  39. // 禁用创建、编辑和删除按钮
  40. $grid->disableCreateButton();
  41. $grid->disableActions();
  42. $grid->disableBatchDelete();
  43. $grid->disableDeleteButton();
  44. $grid->disableEditButton();
  45. // 只保留详情按钮
  46. $grid->actions(function (Grid\Displayers\Actions $actions) {
  47. $actions->disableDelete();
  48. $actions->disableEdit();
  49. $actions->disableQuickEdit();
  50. });
  51. $grid->column('id', 'ID')->sortable();
  52. $grid->column('user_id', '用户ID');
  53. $grid->column('chest.name', '宝箱名称');
  54. $grid->column('chest_content_id', '宝箱内容ID');
  55. $grid->column('current_count', '当前计数');
  56. $grid->column('created_at', '创建时间');
  57. $grid->column('updated_at', '更新时间');
  58. // 筛选
  59. $grid->filter(function ($filter) {
  60. $helper = new FilterHelper($filter, $this);
  61. $helper->equal('id','ID');
  62. $filter->equal('user_id', '用户ID');
  63. $filter->equal('chest_id', '宝箱')->select(
  64. ItemItem::where('type', 5)->pluck('name', 'id')
  65. );
  66. $filter->equal('chest_content_id', '宝箱内容ID');
  67. $filter->between('current_count', '当前计数');
  68. });
  69. return $grid;
  70. });
  71. }
  72. /**
  73. * 详情页
  74. *
  75. * @param mixed $id
  76. * @param Content $content
  77. * @return Content
  78. */
  79. public function show($id, Content $content)
  80. {
  81. return $content
  82. ->header($this->title)
  83. ->description('详情')
  84. ->body($this->detail($id));
  85. }
  86. /**
  87. * 详情页
  88. *
  89. * @param mixed $id
  90. * @return Show
  91. */
  92. protected function detail($id)
  93. {
  94. return Show::make($id, new ItemPityTime(), function (Show $show) {
  95. $helper = new ShowHelper($show, $this);
  96. // 禁用编辑和删除按钮
  97. $show->panel()->tools(function ($tools) {
  98. $tools->disableEdit();
  99. $tools->disableDelete();
  100. });
  101. $helper->field('id','ID');
  102. $show->field('user_id', '用户ID');
  103. $show->field('chest.name', '宝箱名称');
  104. // 显示宝箱内容信息
  105. $show->field('chest_content_id', '宝箱内容ID');
  106. $show->field('chestContent.item.name', '内容物品名称');
  107. $show->field('chestContent.group.name', '内容物品组名称');
  108. $show->field('chestContent.pity_count', '保底次数');
  109. $show->field('chestContent.pity_weight_factor', '保底权重因子');
  110. $show->field('current_count', '当前计数');
  111. // 计算距离保底还需次数
  112. $show->field('remaining_count', '距离保底还需次数')->as(function () {
  113. if (!$this->chestContent || !$this->chestContent->pity_count) {
  114. return '无保底机制';
  115. }
  116. $remaining = max(0, $this->chestContent->pity_count - $this->current_count);
  117. return $remaining;
  118. });
  119. $show->field('created_at', '创建时间');
  120. $show->field('updated_at', '更新时间');
  121. return $show;
  122. });
  123. }
  124. }