diff --git a/app/Admin/Controllers/ProductSpecController.php b/app/Admin/Controllers/ProductSpecController.php new file mode 100644 index 00000000..da80eefd --- /dev/null +++ b/app/Admin/Controllers/ProductSpecController.php @@ -0,0 +1,85 @@ +column('id')->sortable(); + $grid->column('name'); + $grid->column('items')->label(); + $grid->column('created_at')->sortable(); + + //排序 + $grid->model()->orderBy('created_at', 'desc'); + + /** 操作 **/ + //新增 + if (Admin::user()->can('dcat.admin.product_specs.create')) { + $grid->disableCreateButton(false); + $grid->enableDialogCreate(); + } + //修改 + $grid->showQuickEditButton(Admin::user()->can('dcat.admin.product_specs.edit')); + //删除以及自定义操作 + $grid->actions(function (Grid\Displayers\Actions $actions) { + $actions->disableDelete(Admin::user()->cannot('dcat.admin.product_specs.destroy')); + }); + + /** 查询 **/ + $grid->filter(function (Grid\Filter $filter) { + $filter->panel(); + $filter->equal('name')->width(3); + }); + }); + } + + /** + * Make a show builder. + * + * @param mixed $id + * + * @return Show + */ + protected function detail($id) + { + return Show::make($id, new ProductSpec(), function (Show $show) { + $show->field('id'); + $show->field('name'); + $show->field('items'); + $show->field('created_at'); + $show->field('updated_at'); + }); + } + + /** + * Make a form builder. + * + * @return Form + */ + protected function form() + { + return Form::make(new ProductSpec(), function (Form $form) { + $form->display('id'); + $form->text('name')->required(); + $form->list('items'); + + $form->display('created_at'); + $form->display('updated_at'); + }); + } +} diff --git a/app/Admin/Repositories/ProductSpec.php b/app/Admin/Repositories/ProductSpec.php new file mode 100644 index 00000000..405122bc --- /dev/null +++ b/app/Admin/Repositories/ProductSpec.php @@ -0,0 +1,16 @@ +resource('product-categories', 'ProductCategoryController')->only([ 'index', 'create', 'store', 'edit', 'update', 'destroy', ])->names('product_categories'); + + $router->resource('product-specs', 'ProductSpecController')->only([ + 'index', 'create', 'store', 'edit', 'update', 'destroy', + ])->names('product_specs'); }); diff --git a/app/Models/Article.php b/app/Models/Article.php index c9853c4a..4f693a78 100644 --- a/app/Models/Article.php +++ b/app/Models/Article.php @@ -10,6 +10,11 @@ class Article extends Model { use HasDateTimeFormatter; + protected $casts = [ + 'is_show' => 'boolean', + 'is_recommend' => 'boolean', + ]; + public function category() { return $this->belongsTo(ArticleCategory::class, 'category_id'); diff --git a/app/Models/ArticleCategory.php b/app/Models/ArticleCategory.php index 9e7165db..7b5d1a9c 100644 --- a/app/Models/ArticleCategory.php +++ b/app/Models/ArticleCategory.php @@ -15,6 +15,11 @@ class ArticleCategory extends Model protected $table = 'article_categories'; + protected $casts = [ + 'is_show' => 'boolean', + 'is_recommend' => 'boolean', + ]; + // 排序字段名称,默认值为 order protected $orderColumn = 'sort'; diff --git a/app/Models/ProductCategory.php b/app/Models/ProductCategory.php index b6cce773..06c468d5 100644 --- a/app/Models/ProductCategory.php +++ b/app/Models/ProductCategory.php @@ -15,6 +15,11 @@ class ProductCategory extends Model use HasDateTimeFormatter; protected $table = 'product_categories'; + protected $casts = [ + 'is_show' => 'boolean', + 'is_recommend' => 'boolean', + ]; + // 排序字段名称,默认值为 order protected $orderColumn = 'sort'; diff --git a/app/Models/ProductSpec.php b/app/Models/ProductSpec.php new file mode 100644 index 00000000..2c4c5f2f --- /dev/null +++ b/app/Models/ProductSpec.php @@ -0,0 +1,17 @@ + 'array', + ]; +} diff --git a/dcat_admin_ide_helper.php b/dcat_admin_ide_helper.php index 1d76ce25..96b7a2b3 100644 --- a/dcat_admin_ide_helper.php +++ b/dcat_admin_ide_helper.php @@ -74,6 +74,8 @@ namespace Dcat\Admin { * @property Grid\Column|Collection attrs * @property Grid\Column|Collection is_sell * @property Grid\Column|Collection spec_items + * @property Grid\Column|Collection stock + * @property Grid\Column|Collection sells * @property Grid\Column|Collection items * @property Grid\Column|Collection product_spu_id * @property Grid\Column|Collection phone @@ -156,6 +158,8 @@ namespace Dcat\Admin { * @method Grid\Column|Collection attrs(string $label = null) * @method Grid\Column|Collection is_sell(string $label = null) * @method Grid\Column|Collection spec_items(string $label = null) + * @method Grid\Column|Collection stock(string $label = null) + * @method Grid\Column|Collection sells(string $label = null) * @method Grid\Column|Collection items(string $label = null) * @method Grid\Column|Collection product_spu_id(string $label = null) * @method Grid\Column|Collection phone(string $label = null) @@ -243,6 +247,8 @@ namespace Dcat\Admin { * @property Show\Field|Collection attrs * @property Show\Field|Collection is_sell * @property Show\Field|Collection spec_items + * @property Show\Field|Collection stock + * @property Show\Field|Collection sells * @property Show\Field|Collection items * @property Show\Field|Collection product_spu_id * @property Show\Field|Collection phone @@ -325,6 +331,8 @@ namespace Dcat\Admin { * @method Show\Field|Collection attrs(string $label = null) * @method Show\Field|Collection is_sell(string $label = null) * @method Show\Field|Collection spec_items(string $label = null) + * @method Show\Field|Collection stock(string $label = null) + * @method Show\Field|Collection sells(string $label = null) * @method Show\Field|Collection items(string $label = null) * @method Show\Field|Collection product_spu_id(string $label = null) * @method Show\Field|Collection phone(string $label = null) diff --git a/resources/lang/zh_CN/product-category.php b/resources/lang/zh_CN/product-category.php index 6a6bfa1c..35fb50d9 100644 --- a/resources/lang/zh_CN/product-category.php +++ b/resources/lang/zh_CN/product-category.php @@ -3,7 +3,7 @@ return [ 'labels' => [ 'ProductCategory' => '商品分类', - 'product-category' => '商品分类', + 'product-categories' => '商品分类', ], 'fields' => [ 'name' => '名称', diff --git a/resources/lang/zh_CN/product-spec.php b/resources/lang/zh_CN/product-spec.php new file mode 100644 index 00000000..16a2ad30 --- /dev/null +++ b/resources/lang/zh_CN/product-spec.php @@ -0,0 +1,14 @@ + [ + 'ProductSpec' => '商品规格', + 'product-specs' => '商品规格', + ], + 'fields' => [ + 'name' => '规格名称', + 'items' => '规格可选值', + ], + 'options' => [ + ], +];