ChestOpenLogController.php 5.8 KB

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