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.
97 lines
2.9 KiB
97 lines
2.9 KiB
<?php
|
|
|
|
namespace App\Admin\Controllers\v3;
|
|
|
|
use App\Admin\Repositories\v3\GoodsCategory;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Show;
|
|
use Dcat\Admin\Controllers\AdminController;
|
|
use App\Models\v3\Category as CategoryModel;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use App\Models\v3\GoodsCategory as GoodsCategoryModel;
|
|
class GoodsCategoryController extends AdminController
|
|
{
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
return Grid::make(new GoodsCategory(), function (Grid $grid) {
|
|
$grid->column('id')->sortable();
|
|
$grid->column('category_id')->display(function($categoryId){
|
|
$item = CategoryModel::getInfo($categoryId,'title');
|
|
return empty($item) ? '' : $item->title;
|
|
});
|
|
$grid->column('title');
|
|
$grid->column('cover_img')->image('',50);
|
|
$grid->column('sort');
|
|
|
|
$grid->model()->orderBy('id','desc');
|
|
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
$filter->equal('id');
|
|
|
|
});
|
|
$grid->disableBatchDelete();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
*
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
return Show::make($id, new GoodsCategory(), function (Show $show) {
|
|
$show->field('id');
|
|
$show->field('category_id')->as(function($categoryId){
|
|
$item = CategoryModel::getInfo($categoryId,'title');
|
|
return empty($item) ? '' : $item->title;
|
|
});
|
|
$show->field('title');
|
|
$show->field('cover_img')->image('',50);
|
|
$show->field('sort');
|
|
$show->field('created_at');
|
|
$show->field('updated_at');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
return Form::make(new GoodsCategory(), function (Form $form) {
|
|
$form->hidden('id');
|
|
$category = CategoryModel::getArray([['parent_id','>',0]]);
|
|
$form->select('category_id')->width(4)->required()->options($category);
|
|
$form->text('title')->width(4)->required();
|
|
$form->image('cover_img')->autoUpload()->width(2)->uniqueName();
|
|
$form->number('sort');
|
|
|
|
$form->disableResetButton();
|
|
$form->disableViewCheck();
|
|
$form->disableEditingCheck();
|
|
$form->disableCreatingCheck();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 获取商品类目列表
|
|
*/
|
|
public function getList(Request $request)
|
|
{
|
|
$categoryId = $request->get('q');
|
|
$list = GoodsCategoryModel::where('category_id',$categoryId)->get(['id',DB::raw('title as text')]);
|
|
return $list;
|
|
}
|
|
}
|