6
0
Fork 0
jiqu-library-server/app/Admin/Renderable/DealerUserProductLogSimpleT...

36 lines
1.2 KiB
PHP

<?php
namespace App\Admin\Renderable;
use App\Models\DealerUserProductLog;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;
class DealerUserProductLogSimpleTable extends LazyRenderable
{
public function grid(): Grid
{
$userId = $this->payload['id'] ?? 0;
$productId = $this->payload['product_id'] ?? 0;
$builder = DealerUserProductLog::query();
$builder->with(['product'])->where(['user_id'=>$userId, 'product_id'=>$productId]);
return Grid::make($builder, function (Grid $grid) {
$grid->column('product.name', '商品名称');
$grid->column('remark', '备注');
$grid->column('qty', '变动数量')->display(function () {
return (in_array($this->type, [
DealerUserProductLog::TYPE_ORDER_IN,
DealerUserProductLog::TYPE_ADMIN_IN,
]) ? '+' : '-').$this->qty.$this->product?->unit;
});
$grid->column('created_at', '创建时间');
// $grid->withBorder();
$grid->model()->orderBy('created_at', 'desc');
$grid->disableRefreshButton();
$grid->disableActions();
});
}
}