| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace App\Module\Shop\AdminControllers;
- use App\Module\Fund\Models\FundCurrencyModel;
- use App\Module\GameItems\Models\Item;
- use App\Module\Shop\Models\ShopItem;
- use App\Module\Shop\Repositorys\ShopPurchaseLogRepository;
- use App\Module\User\Models\User;
- use Dcat\Admin\Form;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Show;
- use Dcat\Admin\Http\Controllers\AdminController;
- use Spatie\RouteAttributes\Attributes\Resource;
- /**
- * 商店购买记录管理控制器
- */
- #[Resource('shop-purchase-logs', names: 'dcat.admin.shop.purchase-logs')]
- class ShopPurchaseLogController extends AdminController
- {
- /**
- * 页面标题
- *
- * @var string
- */
- protected $title = '购买记录';
- /**
- * 创建表格
- *
- * @return Grid
- */
- protected function grid()
- {
- return Grid::make(new ShopPurchaseLogRepository(), function (Grid $grid) {
- $grid->column('id', 'ID')->sortable();
- $grid->column('user_id', '用户ID')->sortable();
- $grid->column('shopItem.name', '商品名称');
- $grid->column('item.name', '物品名称');
- $grid->column('quantity', '购买数量');
- $grid->column('price', '单价');
- $grid->column('total_price', '总价');
- $grid->column('currency_id', '货币类型')->display(function ($currencyId) {
- $currency = FundCurrencyModel::find($currencyId);
- return $currency ? $currency->name : '未知';
- });
- $grid->column('purchase_time', '购买时间')->sortable();
- $grid->column('ip_address', 'IP地址');
- $grid->column('created_at', '创建时间')->sortable();
- // 过滤器
- $grid->filter(function (Grid\Filter $filter) {
- $filter->equal('id', 'ID');
- $filter->equal('user_id', '用户ID');
- $filter->equal('shop_item_id', '商品')->select(
- ShopItem::pluck('name', 'id')
- );
- $filter->equal('item_id', '物品')->select(
- Item::pluck('name', 'id')
- );
- $filter->equal('currency_id', '货币类型')->select(
- FundCurrencyModel::pluck('name', 'id')
- );
- $filter->between('purchase_time', '购买时间')->datetime();
- $filter->like('ip_address', 'IP地址');
- });
- // 工具栏
- $grid->disableCreateButton();
- $grid->disableEditButton();
- $grid->disableDeleteButton();
- $grid->toolsWithOutline(false);
- $grid->showQuickEditButton(false);
- });
- }
- /**
- * 创建详情页
- *
- * @param mixed $id
- * @return Show
- */
- protected function detail($id)
- {
- return Show::make($id, new ShopPurchaseLogRepository(), function (Show $show) {
- $show->field('id', 'ID');
- $show->field('user_id', '用户ID');
- $show->field('shopItem.name', '商品名称');
- $show->field('item.name', '物品名称');
- $show->field('quantity', '购买数量');
- $show->field('price', '单价');
- $show->field('total_price', '总价');
- $show->field('currency_id', '货币类型')->as(function ($currencyId) {
- $currency = FundCurrencyModel::find($currencyId);
- return $currency ? $currency->name : '未知';
- });
- $show->field('purchase_time', '购买时间');
- $show->field('ip_address', 'IP地址');
- $show->field('device_info', '设备信息');
- $show->field('created_at', '创建时间');
- $show->field('updated_at', '更新时间');
- $show->disableEditButton();
- $show->disableDeleteButton();
- });
- }
- }
|