| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- <?php
- namespace App\Module\Mex\AdminControllers;
- use App\Module\Mex\Repositories\MexMatchLogRepository;
- use App\Module\Mex\Models\MexMatchLog;
- use App\Module\Mex\Enums\MatchType;
- use App\Module\Mex\AdminControllers\Helper\GridHelper;
- use App\Module\Mex\AdminControllers\Helper\ShowHelper;
- use App\Module\Mex\AdminControllers\Helper\FilterHelper;
- use Spatie\RouteAttributes\Attributes\Resource;
- use UCore\DcatAdmin\AdminController;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Show;
- /**
- * 农贸市场撮合日志管理
- *
- * 路由:/admin/mex-match-logs
- * 菜单:游戏运营管理 -> 农贸市场管理 -> 📊 撮合日志
- */
- #[Resource('mex-match-logs', names: 'dcat.admin.mex-match-logs')]
- class MexMatchLogController extends AdminController
- {
- /**
- * 页面标题
- *
- * @var string
- */
- protected $title = '农贸市场撮合日志';
- /**
- * 禁用创建按钮
- *
- * @var bool
- */
- protected $showCreateButton = false;
- /**
- * 禁用编辑按钮
- *
- * @var bool
- */
- protected $showEditButton = false;
- /**
- * 禁用删除按钮
- *
- * @var bool
- */
- protected $showDeleteButton = false;
- /**
- * 获取数据仓库
- *
- * @return string
- */
- protected function repository(): string
- {
- return MexMatchLogRepository::class;
- }
- /**
- * 列表页面
- *
- * @return Grid
- */
- protected function grid()
- {
- return Grid::make(new MexMatchLogRepository(), function (Grid $grid) {
- $helper = new GridHelper($grid, $this);
- // 基础字段
- $grid->column('id', 'ID')->sortable();
-
- // 撮合类型
- $grid->column('match_type', '撮合类型')->display(function ($value) {
- $labels = [
- MatchType::USER_BUY->value => '<span class="badge badge-primary">用户买入</span>',
- MatchType::USER_SELL->value => '<span class="badge badge-success">用户卖出</span>',
- ];
- $valueKey = $value instanceof MatchType ? $value->value : $value;
- return $labels[$valueKey] ?? $valueKey;
- });
- // 商品信息
- $grid->column('item_id', '商品ID')->link(function ($value) {
- return admin_url("game-items/{$value}");
- });
- $grid->column('item.name', '商品名称');
- // 撮合参数
- $grid->column('batch_size', '批处理大小');
- $grid->column('matched_orders', '撮合订单数');
- $grid->column('total_amount', '撮合金额')->display(function ($value) {
- return number_format($value, 5);
- });
- // 执行结果
- $grid->column('success', '执行结果')->display(function ($value) {
- return $value
- ? '<span class="badge badge-success">成功</span>'
- : '<span class="badge badge-danger">失败</span>';
- });
- $grid->column('execution_time_ms', '执行时间')->display(function ($value) {
- return $value ? $value . 'ms' : '-';
- });
- // 消息
- $grid->column('message', '结果消息')->display(function ($value) {
- return \Illuminate\Support\Str::limit($value, 50);
- });
- // 错误消息
- $grid->column('error_message', '错误消息')->display(function ($value) {
- return $value ? '<span class="text-danger">' . \Illuminate\Support\Str::limit($value, 30) . '</span>' : '-';
- });
- // 创建时间
- $helper->columnDatetime('created_at', '创建时间');
- // 排序
- $grid->model()->orderBy('id', 'desc');
- // 筛选器
- $grid->filter(function (Grid\Filter $filter) {
- $helper = new FilterHelper($filter);
- $filter->equal('match_type', '撮合类型')->select([
- MatchType::USER_BUY->value => '用户买入',
- MatchType::USER_SELL->value => '用户卖出',
- ]);
- $filter->equal('item_id', '商品ID');
- $filter->like('item.name', '商品名称');
- $filter->equal('success', '执行结果')->select([
- 1 => '成功',
- 0 => '失败',
- ]);
- $helper->betweenCreatedAt();
- });
- // 禁用新增、编辑、删除和批量操作
- $grid->disableCreateButton();
- $grid->disableEditButton();
- $grid->disableDeleteButton();
- $grid->disableBatchActions();
- // 禁用行选择器
- $grid->disableRowSelector();
- // 设置每页显示数量
- $grid->paginate(20);
- });
- }
- /**
- * 详情页面
- *
- * @param mixed $id
- * @return Show
- */
- protected function detail($id)
- {
- return Show::make($id, new MexMatchLogRepository(), function (Show $show) {
- $helper = new ShowHelper($show, $this);
- $show->field('id', 'ID');
- // 撮合信息
- $show->field('match_type', '撮合类型')->as(function ($value) {
- $labels = [
- MatchType::USER_BUY->value => '用户买入撮合',
- MatchType::USER_SELL->value => '用户卖出撮合',
- ];
- $valueKey = $value instanceof MatchType ? $value->value : $value;
- return $labels[$valueKey] ?? $valueKey;
- });
- $show->field('item_id', '商品ID');
- $show->field('item.name', '商品名称');
- // 撮合参数
- $show->field('batch_size', '批处理大小');
- // 撮合结果
- $show->field('matched_orders', '撮合订单数');
- $show->field('total_amount', '撮合金额')->as(function ($value) {
- return number_format($value, 5);
- });
- $show->field('success', '执行结果')->as(function ($value) {
- return $value ? '成功' : '失败';
- });
- $show->field('execution_time_ms', '执行时间')->as(function ($value) {
- return $value ? $value . ' 毫秒' : '未记录';
- });
- // 消息信息
- $show->field('message', '结果消息');
- $show->field('error_message', '错误消息')->as(function ($value) {
- return $value ?: '无';
- });
- // 时间信息
- $show->field('created_at', '创建时间');
- // 禁用编辑和删除按钮
- $show->disableEditButton();
- $show->disableDeleteButton();
- });
- }
- }
|