ShopPurchaseLogController.php 4.0 KB

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