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.
162 lines
5.7 KiB
162 lines
5.7 KiB
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Admin\Repositories\Goods;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Show;
|
|
use Dcat\Admin\Controllers\AdminController;
|
|
use App\Models\Category as CategoryModel;
|
|
use App\Models\Store as StoreModel;
|
|
use Dcat\Admin\Form\NestedForm;
|
|
use App\Models\Goods as GoodsModel;
|
|
use App\Models\ImsCjdcMarket as MarketModel;
|
|
|
|
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->category_id->display(function ($categoryId){
|
|
$category = CategoryModel::getCategoryInfo($categoryId,'title');
|
|
return empty($category) ? '' : $category->title;
|
|
});
|
|
$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');
|
|
});
|
|
|
|
$grid->model()->orderBy('id', 'desc');
|
|
// 每页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()
|
|
{
|
|
$builder = GoodsModel::with(['ImageBanners','VideoBanners']);
|
|
|
|
return Form::make($builder, function (Form $form) {
|
|
$form->hidden('id');
|
|
|
|
// 二级分类
|
|
$categoryList = CategoryModel::getCategoryArray([['parent_id','>',0]]);
|
|
// 店铺
|
|
$storeList = StoreModel::getStoreArray();
|
|
//市场
|
|
$marketList = MarketModel::getMarket();
|
|
|
|
$form->column(6, function (Form $form) use($marketList,$storeList,$categoryList ){
|
|
$form->select('market_id')->required()->options($marketList);
|
|
$form->select('category_id')->required()->options($categoryList);
|
|
$form->select('store_id')->required()->options($storeList);
|
|
$form->text('name')->required()->maxLength(20);
|
|
$form->image('cover_img')->required();
|
|
$form->number('sort');
|
|
});
|
|
$form->column(6, function (Form $form) {
|
|
$form->currency('price')->required()->floatTwo()->symbol('¥');
|
|
$form->currency('original_price')->required()->floatTwo()->symbol('¥');
|
|
$form->currency('vip_price')->required()->floatTwo()->symbol('¥');
|
|
$form->text('good_unit')->help('如:斤,个,盒,500克,1000克,1500克等');
|
|
$form->radio('is_infinite')->options([1=>'开启',2=>'关闭'])->default(1);
|
|
$form->number('inventory')->required()->attribute('min', 1)->default(1);
|
|
$form->number('restrict_num')->attribute('min', 0)->default(0)->help('0表示不限购');
|
|
$form->number('start_num')->attribute('min', 1)->default(1);
|
|
});
|
|
$form->column(12, function (Form $form) {
|
|
$form->hasMany('image_banners', function (Form\NestedForm $form) {
|
|
$form->image('path')->width(2);
|
|
$form->number('sort')->width(2)->default(0);
|
|
$form->hidden('type')->value(1)->default(1);
|
|
})->required();
|
|
$form->divider();
|
|
$form->hasMany('video_banners', function (Form\NestedForm $form) {
|
|
$form->file('path')->width(2);
|
|
$form->number('sort')->width(2)->default(0);
|
|
$form->hidden('type')->value(2)->default(2);
|
|
});
|
|
$form->divider();
|
|
|
|
$form->multipleImage('details_imgs')->help('按图片顺序上传');
|
|
$form->text('content')->maxLength(50);
|
|
$form->text('remark')->maxLength(50);
|
|
|
|
$form->tags('tags','标签')->options(['新品','热销','新鲜']);
|
|
$form->table('spec', function (NestedForm $table) {
|
|
$table->text('spec_key')->help('如:净含量:500克,保质期:120天,包装:12个/盒等');
|
|
$table->text('spec_value');
|
|
});
|
|
$form->switch('on_sale')
|
|
->customFormat(function ($v) {
|
|
return $v == '上架' ? 1 : 0;
|
|
})
|
|
->saving(function ($v) {
|
|
return $v;
|
|
});
|
|
|
|
$form->disableResetButton();
|
|
$form->disableViewCheck();
|
|
$form->disableEditingCheck();
|
|
$form->disableCreatingCheck();
|
|
});
|
|
});
|
|
}
|
|
}
|