添加商品规格管理
parent
b6ea3a126d
commit
37d19470a9
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Admin\Repositories\ProductSpec;
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Form;
|
||||
use Dcat\Admin\Grid;
|
||||
use Dcat\Admin\Http\Controllers\AdminController;
|
||||
use Dcat\Admin\Show;
|
||||
|
||||
class ProductSpecController extends AdminController
|
||||
{
|
||||
/**
|
||||
* Make a grid builder.
|
||||
*
|
||||
* @return Grid
|
||||
*/
|
||||
protected function grid()
|
||||
{
|
||||
return Grid::make(new ProductSpec(), function (Grid $grid) {
|
||||
$grid->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');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Repositories;
|
||||
|
||||
use App\Models\ProductSpec as Model;
|
||||
use Dcat\Admin\Repositories\EloquentRepository;
|
||||
|
||||
class ProductSpec extends EloquentRepository
|
||||
{
|
||||
/**
|
||||
* Model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $eloquentClass = Model::class;
|
||||
}
|
||||
|
|
@ -34,4 +34,8 @@ Route::group([
|
|||
$router->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');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -15,6 +15,11 @@ class ArticleCategory extends Model
|
|||
|
||||
protected $table = 'article_categories';
|
||||
|
||||
protected $casts = [
|
||||
'is_show' => 'boolean',
|
||||
'is_recommend' => 'boolean',
|
||||
];
|
||||
|
||||
// 排序字段名称,默认值为 order
|
||||
protected $orderColumn = 'sort';
|
||||
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ProductSpec extends Model
|
||||
{
|
||||
use HasDateTimeFormatter;
|
||||
protected $table = 'product_specs';
|
||||
|
||||
protected $casts = [
|
||||
'items' => 'array',
|
||||
];
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
return [
|
||||
'labels' => [
|
||||
'ProductCategory' => '商品分类',
|
||||
'product-category' => '商品分类',
|
||||
'product-categories' => '商品分类',
|
||||
],
|
||||
'fields' => [
|
||||
'name' => '名称',
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'labels' => [
|
||||
'ProductSpec' => '商品规格',
|
||||
'product-specs' => '商品规格',
|
||||
],
|
||||
'fields' => [
|
||||
'name' => '规格名称',
|
||||
'items' => '规格可选值',
|
||||
],
|
||||
'options' => [
|
||||
],
|
||||
];
|
||||
Loading…
Reference in New Issue