PityTimeController.php 4.1 KB

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