Browse Source

商品列表添加搜索

master
liangyuyan 5 years ago
parent
commit
f59b36631e
  1. 41
      app/Admin/Controllers/v3/GoodsController.php

41
app/Admin/Controllers/v3/GoodsController.php

@ -25,34 +25,47 @@ class GoodsController extends AdminController
protected function grid()
{
return Grid::make(new Goods(), function (Grid $grid) {
// 二级分类
$categoryList = CategoryModel::getArray([['parent_id','>',0]],['选择分类'=>0]);
// 店铺
$storeList = StoreModel::getStoreArray();
// 商品类目
$goodsCategoryList = GoodsCategoryModel::getArray([],['选择类目'=>0]);
//市场
$marketList = MarketModel::getMarketArray();
$grid->id->sortable();
$grid->cover_img_url->image('',50);
$grid->name;
$grid->price;
$grid->column('market_id')->display(function($marketId){
$item = MarketModel::getMarketInfo($marketId,'name');
return empty($item) ? '' : $item->name;
$grid->column('market_id')->display(function($marketId) use($marketList){
return isset($marketList[$marketId]) ? $marketList[$marketId] : '';
});
$grid->store_id->display(function ($storeId){
$store = StoreModel::getStoreInfo($storeId,'name');
return empty($store) ? '' : $store->name;
$grid->store_id->display(function ($storeId) use($storeList){
return isset($storeList[$storeId]) ? $storeList[$storeId] : '';
});
$grid->category_id->display(function ($categoryId){
$item = CategoryModel::getInfo($categoryId,'title');
return empty($item) ? '' : $item->title;
$grid->category_id->display(function ($categoryId) use($categoryList){
return isset($categoryList[$categoryId]) ? $categoryList[$categoryId] : '';
});
$grid->goods_category_id->display(function ($goodsCategoryId){
$item = GoodsCategoryModel::getInfo($goodsCategoryId,'title');
return empty($item) ? '' : $item->title;
$grid->goods_category_id->display(function ($goodsCategoryId) use($goodsCategoryList){
return isset($goodsCategoryList[$goodsCategoryId]) ? $goodsCategoryList[$goodsCategoryId] : '';
});
$grid->sort->sortable();
$grid->on_sale->switch();
$grid->actions([new GoodsCopy()]);
$grid->filter(function (Grid\Filter $filter) {
$grid->filter(function (Grid\Filter $filter) use($storeList, $categoryList, $goodsCategoryList, $marketList){
$filter->like('name');
$filter->equal('id');
$filter->like('name');
$filter->equal('store_id')->select($storeList);
$filter->equal('category_id')->select($categoryList);
$filter->equal('goods_category_id')->select($goodsCategoryList);
$filter->equal('market_id')->select($marketList);
$filter->equal('on_sale')->select(GoodsModel::$_ONSALE);
$filter->equal('price');
$filter->equal('goods_unit');
});
$grid->model()->orderBy('id', 'desc');

Loading…
Cancel
Save