DismantleLogController.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. namespace App\Module\GameItems\AdminControllers;
  3. use App\Module\GameItems\Models\ItemDismantleLog;
  4. use App\Module\GameItems\Models\ItemItem;
  5. use App\Module\GameItems\Models\ItemDismantleRule;
  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-dismantle-logs', names: 'dcat.admin.game-items-dismantle-logs')]
  12. class DismantleLogController 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 ItemDismantleLog(), 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('item.name', '物品名称');
  49. $grid->column('instance_id', '实例ID');
  50. $grid->column('quantity', '数量');
  51. $grid->column('rule_id', '规则ID');
  52. $grid->column('coin_returned', '返还金币');
  53. $grid->column('dismantle_time', '分解时间')->sortable();
  54. $grid->column('ip_address', 'IP地址');
  55. $grid->column('created_at', '创建时间');
  56. // 筛选
  57. $grid->filter(function ($filter) {
  58. $filter->equal('id', 'ID');
  59. $filter->equal('user_id', '用户ID');
  60. $filter->equal('item_id', '物品')->select(
  61. ItemItem::pluck('name', 'id')
  62. );
  63. $filter->equal('instance_id', '实例ID');
  64. $filter->equal('rule_id', '规则ID')->select(
  65. ItemDismantleRule::pluck('id', 'id')
  66. );
  67. $filter->between('dismantle_time', '分解时间')->datetime();
  68. });
  69. });
  70. }
  71. /**
  72. * 详情页
  73. *
  74. * @param mixed $id
  75. * @param Content $content
  76. * @return Content
  77. */
  78. public function show($id, Content $content)
  79. {
  80. return $content
  81. ->header($this->title)
  82. ->description('详情')
  83. ->body($this->detail($id));
  84. }
  85. /**
  86. * 详情页
  87. *
  88. * @param mixed $id
  89. * @return Show
  90. */
  91. protected function detail($id)
  92. {
  93. return Show::make(ItemDismantleLog::findOrFail($id), function (Show $show) {
  94. // 禁用编辑和删除按钮
  95. $show->panel()->tools(function ($tools) {
  96. $tools->disableEdit();
  97. $tools->disableDelete();
  98. });
  99. $show->field('id', 'ID');
  100. $show->field('user_id', '用户ID');
  101. $show->field('item.name', '物品名称');
  102. $show->field('instance_id', '实例ID');
  103. $show->field('quantity', '数量');
  104. $show->field('rule_id', '规则ID');
  105. // 显示分解结果
  106. $show->field('results', '分解结果')->as(function ($results) {
  107. if (empty($results)) {
  108. return '无';
  109. }
  110. if (is_string($results)) {
  111. $results = json_decode($results, true);
  112. }
  113. if (is_array($results)) {
  114. $html = '<table class="table table-bordered">';
  115. $html .= '<thead><tr><th>物品ID</th><th>物品名称</th><th>数量</th></tr></thead>';
  116. $html .= '<tbody>';
  117. foreach ($results as $result) {
  118. $itemInfo = ItemItem::find($result['item_id']);
  119. $itemName = $itemInfo ? $itemInfo->name : '未知物品';
  120. $html .= '<tr>';
  121. $html .= '<td>' . $result['item_id'] . '</td>';
  122. $html .= '<td>' . $itemName . '</td>';
  123. $html .= '<td>' . $result['quantity'] . '</td>';
  124. $html .= '</tr>';
  125. }
  126. $html .= '</tbody></table>';
  127. return $html;
  128. }
  129. return $results;
  130. })->unescape();
  131. $show->field('coin_returned', '返还金币');
  132. $show->field('dismantle_time', '分解时间');
  133. $show->field('ip_address', 'IP地址');
  134. $show->field('device_info', '设备信息');
  135. $show->field('created_at', '创建时间');
  136. });
  137. }
  138. }