ChestOpenLogController.php 5.5 KB

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