PityTimeController.php 4.3 KB

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