You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
136 lines
4.2 KiB
136 lines
4.2 KiB
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Admin\Repositories\Goods;
|
|
use App\Models\Store;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Show;
|
|
use Dcat\Admin\Controllers\AdminController;
|
|
use App\Models\GoodsType as GoodsTypeModel;
|
|
use App\Models\Store as StoreModel;
|
|
use Dcat\Admin\Form\NestedForm;
|
|
|
|
class GoodsController extends AdminController
|
|
{
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
return Grid::make(new Goods(), function (Grid $grid) {
|
|
$grid->id->sortable();
|
|
$grid->cover_img_url->image('',50);
|
|
$grid->name;
|
|
$grid->goods_type_id->display(function ($goodsTypeId){
|
|
$goodsType = GoodsTypeModel::getGoodsInfo($goodsTypeId,'type_name');
|
|
return empty($goodsType) ? '' : $goodsType->type_name;
|
|
});
|
|
$grid->store_id->display(function ($storeId){
|
|
$store = StoreModel::getStoreInfo($storeId,'name');
|
|
return empty($store) ? '' : $store->name;
|
|
});
|
|
|
|
$grid->price;
|
|
|
|
$grid->sort->sortable();
|
|
$grid->on_sale->switch();
|
|
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
$filter->equal('id');
|
|
|
|
});
|
|
|
|
// 每页10条
|
|
$grid->paginate(10);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
*
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
return Show::make($id, new Goods(), function (Show $show) {
|
|
$show->id;
|
|
$show->name;
|
|
$show->type_id;
|
|
$show->store_id;
|
|
$show->cover_img;
|
|
$show->price;
|
|
$show->original_price;
|
|
$show->vip_price;
|
|
$show->on_sale;
|
|
$show->inventory;
|
|
$show->content;
|
|
$show->sort;
|
|
$show->restrict_num;
|
|
$show->start_num;
|
|
$show->is_infinite;
|
|
$show->good_unit;
|
|
$show->tags;
|
|
$show->details_imgs;
|
|
$show->spec;
|
|
$show->created_at;
|
|
$show->updated_at;
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
return Form::make(new Goods(), function (Form $form) {
|
|
$form->hidden('id');
|
|
|
|
// 二级分类(商品分类)
|
|
$goodsTypeList = GoodsTypeModel::getGoodsTypeArray();
|
|
// 店铺
|
|
$store = StoreModel::getStoreArray();
|
|
|
|
$form->select('goods_type_id')->width(4)->required()->options($goodsTypeList);
|
|
$form->select('store_id')->width(4)->required()->options($store);
|
|
|
|
$form->text('name')->width(4)->required()->maxLength(20);
|
|
$form->image('cover_img')->width(2)->required();
|
|
|
|
$form->currency('price')->width(4)->required()->floatTwo()->symbol('¥');
|
|
$form->currency('original_price')->width(4)->required()->floatTwo()->symbol('¥');
|
|
$form->currency('vip_price')->width(4)->required()->floatTwo()->symbol('¥');
|
|
|
|
$form->text('good_unit')->width(4)->help('如:斤,个,盒,500克,1000克,1500克等')->saveAsJson();
|
|
|
|
$form->switch('is_infinite');
|
|
$form->number('inventory')->width(2)->required()->attribute('min', 1)->default(1);
|
|
$form->number('restrict_num')->width(2)->attribute('min', 0)->default(0)->help('0表示不限购');
|
|
$form->number('start_num')->width(2)->attribute('min', 1)->default(1);
|
|
|
|
$form->multipleImage('details_imgs');
|
|
$form->textarea('content');
|
|
$form->number('sort')->width(2);
|
|
|
|
$form->tags('tags')->options(['新品','热销','新鲜'])->saveAsJson();
|
|
$form->table('spec', function (NestedForm $table) {
|
|
$table->text('规格名称')->help('如:净含量:500克,包装:12个/盒,保质期:120天等');
|
|
$table->text('值');
|
|
});
|
|
|
|
$form->saving(function (Form $form){
|
|
$tage = $form->input('tags');
|
|
var_dump($tage);
|
|
$data = $form->input('spec');
|
|
dd($data);
|
|
});
|
|
});
|
|
}
|
|
}
|