MexMatchLogController.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php
  2. namespace App\Module\Mex\AdminControllers;
  3. use App\Module\Mex\Repositories\MexMatchLogRepository;
  4. use App\Module\Mex\Models\MexMatchLog;
  5. use App\Module\Mex\Enums\MatchType;
  6. use App\Module\Mex\AdminControllers\Helper\GridHelper;
  7. use App\Module\Mex\AdminControllers\Helper\ShowHelper;
  8. use App\Module\Mex\AdminControllers\Helper\FilterHelper;
  9. use Spatie\RouteAttributes\Attributes\Resource;
  10. use UCore\DcatAdmin\AdminController;
  11. use Dcat\Admin\Grid;
  12. use Dcat\Admin\Show;
  13. /**
  14. * 农贸市场撮合日志管理
  15. *
  16. * 路由:/admin/mex-match-logs
  17. * 菜单:游戏运营管理 -> 农贸市场管理 -> 📊 撮合日志
  18. */
  19. #[Resource('mex-match-logs', names: 'dcat.admin.mex-match-logs')]
  20. class MexMatchLogController 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. * @var bool
  38. */
  39. protected $showEditButton = false;
  40. /**
  41. * 禁用删除按钮
  42. *
  43. * @var bool
  44. */
  45. protected $showDeleteButton = false;
  46. /**
  47. * 获取数据仓库
  48. *
  49. * @return string
  50. */
  51. protected function repository(): string
  52. {
  53. return MexMatchLogRepository::class;
  54. }
  55. /**
  56. * 列表页面
  57. *
  58. * @return Grid
  59. */
  60. protected function grid()
  61. {
  62. return Grid::make(new MexMatchLogRepository(), function (Grid $grid) {
  63. $helper = new GridHelper($grid, $this);
  64. // 基础字段
  65. $grid->column('id', 'ID')->sortable();
  66. // 撮合类型
  67. $grid->column('match_type', '撮合类型')->display(function ($value) {
  68. $labels = [
  69. MatchType::USER_BUY->value => '<span class="badge badge-primary">用户买入</span>',
  70. MatchType::USER_SELL->value => '<span class="badge badge-success">用户卖出</span>',
  71. ];
  72. $valueKey = $value instanceof MatchType ? $value->value : $value;
  73. return $labels[$valueKey] ?? $valueKey;
  74. });
  75. // 商品信息
  76. $grid->column('item_id', '商品ID')->link(function ($value) {
  77. return admin_url("game-items/{$value}");
  78. });
  79. $grid->column('item.name', '商品名称');
  80. // 撮合参数
  81. $grid->column('batch_size', '批处理大小');
  82. $grid->column('matched_orders', '撮合订单数');
  83. $grid->column('total_amount', '撮合金额')->display(function ($value) {
  84. return number_format($value, 5);
  85. });
  86. // 执行结果
  87. $grid->column('success', '执行结果')->display(function ($value) {
  88. return $value
  89. ? '<span class="badge badge-success">成功</span>'
  90. : '<span class="badge badge-danger">失败</span>';
  91. });
  92. $grid->column('execution_time_ms', '执行时间')->display(function ($value) {
  93. return $value ? $value . 'ms' : '-';
  94. });
  95. // 消息
  96. $grid->column('message', '结果消息')->display(function ($value) {
  97. return \Illuminate\Support\Str::limit($value, 50);
  98. });
  99. // 错误消息
  100. $grid->column('error_message', '错误消息')->display(function ($value) {
  101. return $value ? '<span class="text-danger">' . \Illuminate\Support\Str::limit($value, 30) . '</span>' : '-';
  102. });
  103. // 创建时间
  104. $helper->columnDatetime('created_at', '创建时间');
  105. // 排序
  106. $grid->model()->orderBy('id', 'desc');
  107. // 筛选器
  108. $grid->filter(function (Grid\Filter $filter) {
  109. $helper = new FilterHelper($filter);
  110. $filter->equal('match_type', '撮合类型')->select([
  111. MatchType::USER_BUY->value => '用户买入',
  112. MatchType::USER_SELL->value => '用户卖出',
  113. ]);
  114. $filter->equal('item_id', '商品ID');
  115. $filter->like('item.name', '商品名称');
  116. $filter->equal('success', '执行结果')->select([
  117. 1 => '成功',
  118. 0 => '失败',
  119. ]);
  120. $helper->betweenCreatedAt();
  121. });
  122. // 禁用新增、编辑、删除和批量操作
  123. $grid->disableCreateButton();
  124. $grid->disableEditButton();
  125. $grid->disableDeleteButton();
  126. $grid->disableBatchActions();
  127. // 禁用行选择器
  128. $grid->disableRowSelector();
  129. // 设置每页显示数量
  130. $grid->paginate(20);
  131. });
  132. }
  133. /**
  134. * 详情页面
  135. *
  136. * @param mixed $id
  137. * @return Show
  138. */
  139. protected function detail($id)
  140. {
  141. return Show::make($id, new MexMatchLogRepository(), function (Show $show) {
  142. $helper = new ShowHelper($show, $this);
  143. $show->field('id', 'ID');
  144. // 撮合信息
  145. $show->field('match_type', '撮合类型')->as(function ($value) {
  146. $labels = [
  147. MatchType::USER_BUY->value => '用户买入撮合',
  148. MatchType::USER_SELL->value => '用户卖出撮合',
  149. ];
  150. $valueKey = $value instanceof MatchType ? $value->value : $value;
  151. return $labels[$valueKey] ?? $valueKey;
  152. });
  153. $show->field('item_id', '商品ID');
  154. $show->field('item.name', '商品名称');
  155. // 撮合参数
  156. $show->field('batch_size', '批处理大小');
  157. // 撮合结果
  158. $show->field('matched_orders', '撮合订单数');
  159. $show->field('total_amount', '撮合金额')->as(function ($value) {
  160. return number_format($value, 5);
  161. });
  162. $show->field('success', '执行结果')->as(function ($value) {
  163. return $value ? '成功' : '失败';
  164. });
  165. $show->field('execution_time_ms', '执行时间')->as(function ($value) {
  166. return $value ? $value . ' 毫秒' : '未记录';
  167. });
  168. // 消息信息
  169. $show->field('message', '结果消息');
  170. $show->field('error_message', '错误消息')->as(function ($value) {
  171. return $value ?: '无';
  172. });
  173. // 时间信息
  174. $show->field('created_at', '创建时间');
  175. // 禁用编辑和删除按钮
  176. $show->disableEditButton();
  177. $show->disableDeleteButton();
  178. });
  179. }
  180. }