97 lines
4.0 KiB
PHP
97 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Renderable;
|
|
|
|
use App\Admin\Actions\Grid\ReleaseCancel;
|
|
use App\Admin\Actions\Grid\ReleaseDown;
|
|
use App\Admin\Actions\Grid\ReleaseUp;
|
|
use App\Admin\Actions\Grid\SkuSyncSpu;
|
|
use App\Admin\Extensions\Grid\Tools\Product\BatchReleaseCancel;
|
|
use App\Admin\Extensions\Grid\Tools\Product\BatchReleaseDown;
|
|
use App\Admin\Extensions\Grid\Tools\Product\BatchReleaseUp;
|
|
use App\Models\ProductSku;
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Grid;
|
|
|
|
class ProductSkuTable extends Grid
|
|
{
|
|
public static function grid(int $spuId = null)
|
|
{
|
|
$builder = ProductSku::with('category');
|
|
if ($spuId) {
|
|
$builder->where('spu_id', $spuId);
|
|
}
|
|
$grid = parent::make($builder, function (Grid $grid) {
|
|
$grid->setResource('product-skus');
|
|
$grid->showRowSelector();
|
|
$grid->batchActions(function ($batch) {
|
|
//批量下架
|
|
if (Admin::user()->can('dcat.admin.product_skus.batch_release_down')) {
|
|
$batch->add(new BatchReleaseDown());
|
|
}
|
|
//批量上架
|
|
if (Admin::user()->can('dcat.admin.product_skus.batch_release_up')) {
|
|
$batch->add(new BatchReleaseUp());
|
|
}
|
|
//批量取消审核
|
|
if (Admin::user()->can('dcat.admin.product_skus.batch_release_cancel')) {
|
|
$batch->add(new BatchReleaseCancel());
|
|
}
|
|
});
|
|
$grid->column('id')->sortable();
|
|
// $grid->column('spu_id');
|
|
$grid->column('name');
|
|
$grid->column('subtitle');
|
|
$grid->column('category.name');
|
|
$grid->column('specs')->label();
|
|
$grid->column('sell_price')->prepend('¥');
|
|
$grid->column('market_price')->prepend('¥');
|
|
$grid->column('cost_price')->prepend('¥');
|
|
$grid->column('vip_price')->prepend('¥');
|
|
$grid->column('weight');
|
|
$grid->column('stock');
|
|
$grid->column('sales');
|
|
$grid->column('verify_state')
|
|
->using([0=>'正常', 1=>'审核中', 2=>'审核失败'])
|
|
->dot([
|
|
0 => 'success',
|
|
1 => 'primary',
|
|
2 => 'danger',
|
|
]);
|
|
$grid->column('release_at');
|
|
$grid->model()->orderBy('created_at', 'desc');
|
|
$grid->model()->orderBy('release_at', 'desc');
|
|
$grid->actions(function (Grid\Displayers\Actions $actions) {
|
|
if (is_null($actions->row->release_at) || $actions->row->verify_state == 1) {//未上架或者审核未通过
|
|
$actions->disableEdit(Admin::user()->cannot('dcat.admin.product_skus.edit'));
|
|
$actions->disableDelete(Admin::user()->cannot('dcat.admin.product_skus.destroy'));
|
|
if ($actions->row->verify_state == 0) {
|
|
if (Admin::user()->can('dcat.admin.product_skus.release_up')) {
|
|
$actions->append(new ReleaseUp());
|
|
}
|
|
}
|
|
if ($actions->row->verify_state == 1) {
|
|
if (Admin::user()->can('dcat.admin.product_skus.release_cancel')) {
|
|
$actions->append(new ReleaseCancel());
|
|
}
|
|
}
|
|
if (Admin::user()->can('dcat.admin.product_skus.sku_sync_spu')) {
|
|
$actions->append(new SkuSyncSpu());
|
|
}
|
|
}
|
|
if ($actions->row->release_at) {//已上架
|
|
if (Admin::user()->can('dcat.admin.product_skus.release_down')) {
|
|
$actions->append(new ReleaseDown());
|
|
}
|
|
}
|
|
});
|
|
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
$filter->panel();
|
|
$filter->equal('name')->width(3);
|
|
});
|
|
});
|
|
return $grid;
|
|
}
|
|
}
|