76 lines
2.7 KiB
PHP
76 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Renderable;
|
|
|
|
use App\Admin\Repositories\CouponRange;
|
|
use App\Models\Coupon;
|
|
use App\Models\ProductCategory;
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Grid\Column;
|
|
|
|
class CouponRangeTable extends Grid
|
|
{
|
|
public static function grid(int $couponId = null)
|
|
{
|
|
$builder = CouponRange::with('coupon');
|
|
|
|
$grid = parent::make($builder, function (Grid $grid) {
|
|
$grid->setResource('coupon-ranges');
|
|
$grid->column('id')->sortable();
|
|
$grid->column('coupon.name');
|
|
$grid->column('type')->using([
|
|
1=>'商品分类',
|
|
2=>'SKU商品',
|
|
])->label();
|
|
$grid->column('ranges')
|
|
->if(function () {
|
|
return $this->type == 1;
|
|
})->then(function (Column $column) {
|
|
$column->showTreeInDialog(function (Grid\Displayers\DialogTree $tree) {
|
|
$tree->title('商品分类');
|
|
$tree->nodes(ProductCategory::get()->toArray());
|
|
$tree->setTitleColumn('name');
|
|
});
|
|
})
|
|
->else(function (Column $column) {
|
|
$column->display('查看')->modal(function ($modal) {
|
|
$modal->icon('feather icon-align-right');
|
|
$modal->title('SKU商品');
|
|
return CouponRangeSkuTable::make(['id'=>$this->id]);
|
|
});
|
|
});
|
|
$grid->column('created_at');
|
|
$grid->column('updated_at')->sortable();
|
|
$grid->model()->orderBy('created_at', 'desc');
|
|
|
|
/** 操作 **/
|
|
//新增
|
|
if (Admin::user()->can('dcat.admin.coupon_ranges.create')) {
|
|
// $grid->disableCreateButton(false);
|
|
$grid->enableDialogCreate();
|
|
}
|
|
//修改
|
|
$grid->showQuickEditButton(Admin::user()->can('dcat.admin.coupon_ranges.edit'));
|
|
//删除以及自定义操作
|
|
$grid->actions(function (Grid\Displayers\Actions $actions) {
|
|
$actions->disableView();
|
|
$actions->disableEdit();
|
|
$actions->disableDelete(Admin::user()->cannot('dcat.admin.coupon_ranges.destroy'));
|
|
});
|
|
});
|
|
|
|
if ($couponId) {
|
|
$grid->model()->where('coupon_id', $couponId);
|
|
$grid->model()->setConstraints([
|
|
'coupon_id' => $couponId,
|
|
]);
|
|
$coupon = Coupon::findOrFail($couponId);
|
|
if ($coupon->hasReceived()) {
|
|
$grid->disableCreateButton();
|
|
}
|
|
}
|
|
return $grid;
|
|
}
|
|
}
|