ShopPurchaseLogController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace App\Module\Shop\AdminControllers;
  3. use App\Module\Fund\Models\FundCurrencyModel;
  4. use App\Module\GameItems\Models\Item;
  5. use App\Module\Shop\Models\ShopItem;
  6. use App\Module\Shop\Repositorys\ShopPurchaseLogRepository;
  7. use App\Module\User\Models\User;
  8. use Dcat\Admin\Form;
  9. use Dcat\Admin\Grid;
  10. use Dcat\Admin\Show;
  11. use Dcat\Admin\Http\Controllers\AdminController;
  12. use Spatie\RouteAttributes\Attributes\Resource;
  13. /**
  14. * 商店购买记录管理控制器
  15. */
  16. #[Resource('shop-purchase-logs', names: 'dcat.admin.shop.purchase-logs')]
  17. class ShopPurchaseLogController extends AdminController
  18. {
  19. /**
  20. * 页面标题
  21. *
  22. * @var string
  23. */
  24. protected $title = '购买记录';
  25. /**
  26. * 创建表格
  27. *
  28. * @return Grid
  29. */
  30. protected function grid()
  31. {
  32. return Grid::make(new ShopPurchaseLogRepository(), function (Grid $grid) {
  33. $grid->column('id', 'ID')->sortable();
  34. $grid->column('user_id', '用户ID')->sortable();
  35. $grid->column('shopItem.name', '商品名称');
  36. $grid->column('item.name', '物品名称');
  37. $grid->column('quantity', '购买数量');
  38. $grid->column('price', '单价');
  39. $grid->column('total_price', '总价');
  40. $grid->column('currency_id', '货币类型')->display(function ($currencyId) {
  41. $currency = FundCurrencyModel::find($currencyId);
  42. return $currency ? $currency->name : '未知';
  43. });
  44. $grid->column('purchase_time', '购买时间')->sortable();
  45. $grid->column('ip_address', 'IP地址');
  46. $grid->column('created_at', '创建时间')->sortable();
  47. // 过滤器
  48. $grid->filter(function (Grid\Filter $filter) {
  49. $filter->equal('id', 'ID');
  50. $filter->equal('user_id', '用户ID');
  51. $filter->equal('shop_item_id', '商品')->select(
  52. ShopItem::pluck('name', 'id')
  53. );
  54. $filter->equal('item_id', '物品')->select(
  55. Item::pluck('name', 'id')
  56. );
  57. $filter->equal('currency_id', '货币类型')->select(
  58. FundCurrencyModel::pluck('name', 'id')
  59. );
  60. $filter->between('purchase_time', '购买时间')->datetime();
  61. $filter->like('ip_address', 'IP地址');
  62. });
  63. // 工具栏
  64. $grid->disableCreateButton();
  65. $grid->disableEditButton();
  66. $grid->disableDeleteButton();
  67. $grid->toolsWithOutline(false);
  68. $grid->showQuickEditButton(false);
  69. });
  70. }
  71. /**
  72. * 创建详情页
  73. *
  74. * @param mixed $id
  75. * @return Show
  76. */
  77. protected function detail($id)
  78. {
  79. return Show::make($id, new ShopPurchaseLogRepository(), function (Show $show) {
  80. $show->field('id', 'ID');
  81. $show->field('user_id', '用户ID');
  82. $show->field('shopItem.name', '商品名称');
  83. $show->field('item.name', '物品名称');
  84. $show->field('quantity', '购买数量');
  85. $show->field('price', '单价');
  86. $show->field('total_price', '总价');
  87. $show->field('currency_id', '货币类型')->as(function ($currencyId) {
  88. $currency = FundCurrencyModel::find($currencyId);
  89. return $currency ? $currency->name : '未知';
  90. });
  91. $show->field('purchase_time', '购买时间');
  92. $show->field('ip_address', 'IP地址');
  93. $show->field('device_info', '设备信息');
  94. $show->field('created_at', '创建时间');
  95. $show->field('updated_at', '更新时间');
  96. $show->disableEditButton();
  97. $show->disableDeleteButton();
  98. });
  99. }
  100. }