131 lines
4.4 KiB
PHP
131 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Admin\Repositories\ProductSpu;
|
|
use App\Models\ProductGroup;
|
|
use Carbon\Carbon;
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Http\Controllers\AdminController;
|
|
use Dcat\Admin\Show;
|
|
|
|
class ProductSpuController extends AdminController
|
|
{
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
return Grid::make(new ProductSpu(), function (Grid $grid) {
|
|
$grid->column('id')->sortable();
|
|
$grid->column('name');
|
|
$grid->column('subtitle');
|
|
$grid->column('cover')->image(80, 80);
|
|
$grid->column('sell_price');
|
|
$grid->column('market_price');
|
|
$grid->column('cost_price');
|
|
$grid->column('vip_price');
|
|
$grid->column('weight');
|
|
$grid->column('created_at')->sortable();
|
|
|
|
//排序
|
|
$grid->model()->orderBy('created_at', 'desc');
|
|
|
|
/** 操作 **/
|
|
//新增
|
|
if (Admin::user()->can('dcat.admin.product_spus.create')) {
|
|
$grid->disableCreateButton(false);
|
|
}
|
|
//修改
|
|
// $grid->showQuickEditButton(Admin::user()->can('dcat.admin.product_spus.edit'));
|
|
//删除以及自定义操作
|
|
$grid->actions(function (Grid\Displayers\Actions $actions) {
|
|
$actions->disableEdit(Admin::user()->cannot('dcat.admin.product_spus.edit'));
|
|
$actions->disableDelete(Admin::user()->cannot('dcat.admin.product_spus.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 ProductSpu(), function (Show $show) {
|
|
$show->field('id');
|
|
$show->field('name');
|
|
$show->field('subtitle');
|
|
$show->field('cover');
|
|
$show->field('images');
|
|
$show->field('description');
|
|
$show->field('sell_price');
|
|
$show->field('market_price');
|
|
$show->field('cost_price');
|
|
$show->field('vip_price');
|
|
$show->field('media');
|
|
$show->field('weight');
|
|
$show->field('attrs');
|
|
$show->field('created_at');
|
|
$show->field('updated_at');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
return Form::make(new ProductSpu(), function (Form $form) {
|
|
$form->display('id');
|
|
|
|
|
|
if ($form->isCreating()) {
|
|
$form->select('one_category')->options(admin_route('api.product_categories'))->load('two_category', admin_route('api.product_categories'));
|
|
$form->select('two_category')->load('category_id', admin_route('api.product_categories'));
|
|
$form->select('category_id')->required();
|
|
}
|
|
$form->text('name')->required();
|
|
$form->text('subtitle');
|
|
$form->image('cover')
|
|
->move('product-spus/cover/'.Carbon::now()->toDateString())
|
|
->saveFullUrl()
|
|
->removable(false)
|
|
->autoUpload();
|
|
$form->multipleImage('images')
|
|
->move('product-spus/'.Carbon::now()->toDateString())
|
|
->saveFullUrl()
|
|
->removable(false)
|
|
->autoUpload();
|
|
$form->editor('description');
|
|
$form->number('weight');
|
|
|
|
$form->currency('sell_price')->symbol('¥')->default(0);
|
|
$form->currency('market_price')->symbol('¥')->default(0);
|
|
$form->currency('cost_price')->symbol('¥')->default(0);
|
|
$form->currency('vip_price')->symbol('¥');
|
|
$form->select('attr_group')->options(ProductGroup::all()->pluck('name', 'id'));
|
|
$form->selectAttr('attrs')->listen('attr_group');
|
|
|
|
$form->ignore(['one_category', 'two_category', 'attr_group']);
|
|
$form->display('created_at');
|
|
$form->display('updated_at');
|
|
});
|
|
}
|
|
}
|