PityTimeController.php 4.3 KB

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