ChestOpenLogController.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. namespace App\Module\GameItems\AdminControllers;
  3. use App\Module\GameItems\Repositorys\ItemChestOpenLogRepository;
  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 App\Module\GameItems\AdminControllers\Helper\FilterHelper;
  11. use App\Module\GameItems\AdminControllers\Helper\FormHelper;
  12. use App\Module\GameItems\AdminControllers\Helper\GridHelper;
  13. use App\Module\GameItems\AdminControllers\Helper\ShowHelper;
  14. /**
  15. * 宝箱开启记录管理控制器
  16. *
  17. * @package App\Module\GameItems\AdminControllers
  18. */
  19. #[Resource('game-items-chest-open-logs', names: 'dcat.admin.game-items-chest-open-logs')]
  20. class ChestOpenLogController extends AdminController
  21. {
  22. /**
  23. * 标题
  24. *
  25. * @var string
  26. */
  27. protected $title = '宝箱开启记录';
  28. /**
  29. * 禁用创建按钮
  30. *
  31. * @var bool
  32. */
  33. protected $showCreateButton = false;
  34. /**
  35. * 列表页
  36. *
  37. * @return Grid
  38. */
  39. protected function grid()
  40. {
  41. return Grid::make(new ItemChestOpenLogRepository(), function (Grid $grid) {
  42. $helper = new GridHelper($grid, $this);
  43. // 禁用创建、编辑和删除按钮
  44. $grid->disableCreateButton();
  45. $grid->disableActions();
  46. $grid->disableBatchDelete();
  47. $grid->disableDeleteButton();
  48. $grid->disableEditButton();
  49. // 只保留详情按钮
  50. $grid->actions(function (Grid\Displayers\Actions $actions) {
  51. $actions->disableDelete();
  52. $actions->disableEdit();
  53. $actions->disableQuickEdit();
  54. });
  55. $helper->columnId();
  56. $grid->column('user_id', '用户ID');
  57. $grid->column('chest.name', '宝箱名称');
  58. $grid->column('quantity', '开启数量');
  59. $grid->column('pity_triggered', '触发保底')->switch();
  60. $grid->column('pity_content_id', '保底内容ID');
  61. $grid->column('open_time', '开启时间')->sortable();
  62. $grid->column('ip_address', 'IP地址');
  63. $grid->column('created_at', '创建时间');
  64. // 筛选
  65. $grid->filter(function ($filter) {
  66. $helper = new FilterHelper($filter, $this);
  67. $helper->equal('id', 'ID');
  68. $helper->equal('user_id', '用户ID');
  69. $filter->equal('chest_id', '宝箱')->select(
  70. (new ItemRepository())->where('type', 5)->pluck('name', 'id')
  71. );
  72. $filter->equal('pity_triggered', '触发保底')->radio([
  73. 1 => '是',
  74. 0 => '否',
  75. ]);
  76. $filter->between('open_time', '开启时间')->datetime();
  77. });
  78. });
  79. }
  80. /**
  81. * 详情页
  82. *
  83. * @param mixed $id
  84. * @param Content $content
  85. * @return Content
  86. */
  87. public function show($id, Content $content)
  88. {
  89. return $content
  90. ->header($this->title)
  91. ->description('详情')
  92. ->body($this->detail($id));
  93. }
  94. /**
  95. * 详情页
  96. *
  97. * @param mixed $id
  98. * @return Show
  99. */
  100. protected function detail($id)
  101. {
  102. return Show::make($id, new ItemChestOpenLogRepository(), function (Show $show) {
  103. $helper = new ShowHelper($show, $this);
  104. // 禁用编辑和删除按钮
  105. $show->panel()->tools(function ($tools) {
  106. $tools->disableEdit();
  107. $tools->disableDelete();
  108. });
  109. $helper->field('id', 'ID');
  110. $helper->field('user_id', '用户ID');
  111. $show->field('chest.name', '宝箱名称');
  112. $helper->field('quantity', '开启数量');
  113. $helper->field('pity_triggered', '触发保底')->as(function ($value) {
  114. return $value ? '是' : '否';
  115. });
  116. $helper->field('pity_content_id', '保底内容ID');
  117. // 显示开箱结果
  118. $show->field('results', '开箱结果')->as(function ($results) {
  119. if (empty($results)) {
  120. return '无';
  121. }
  122. if (is_string($results)) {
  123. $results = json_decode($results, true);
  124. }
  125. if (is_array($results)) {
  126. $html = '';
  127. foreach ($results as $index => $chestResult) {
  128. $html .= '<h4>第' . ($index + 1) . '次开箱</h4>';
  129. $html .= '<table class="table table-bordered">';
  130. $html .= '<thead><tr><th>物品ID</th><th>数量</th><th>是否保底</th></tr></thead>';
  131. $html .= '<tbody>';
  132. foreach ($chestResult as $item) {
  133. $itemInfo = (new ItemRepository())->find($item['item_id']);
  134. $itemName = $itemInfo ? $itemInfo->name : '未知物品';
  135. $html .= '<tr>';
  136. $html .= '<td>' . $item['item_id'] . ' (' . $itemName . ')</td>';
  137. $html .= '<td>' . $item['quantity'] . '</td>';
  138. $html .= '<td>' . (isset($item['is_pity']) && $item['is_pity'] ? '是' : '否') . '</td>';
  139. $html .= '</tr>';
  140. }
  141. $html .= '</tbody></table>';
  142. }
  143. return $html;
  144. }
  145. return $results;
  146. })->unescape();
  147. $helper->field('open_time', '开启时间');
  148. $helper->field('ip_address', 'IP地址');
  149. $helper->field('device_info', '设备信息');
  150. $helper->field('created_at', '创建时间');
  151. });
  152. }
  153. }