ChestOpenLogController.php 5.6 KB

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