From 194bd33cdc98cbccef9e301509747594f864d8d7 Mon Sep 17 00:00:00 2001 From: Anyon Date: Tue, 15 Sep 2020 16:23:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=95=86=E5=93=81=E5=88=86?= =?UTF-8?q?=E7=B1=BB=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/data/controller/ShopGoods.php | 18 +++++++++++++++--- app/data/service/GoodsService.php | 6 +++++- app/data/view/shop_goods/form.html | 7 +++---- app/data/view/shop_goods/index_search.html | 4 ++-- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/app/data/controller/ShopGoods.php b/app/data/controller/ShopGoods.php index 15de95a99..eb9110616 100644 --- a/app/data/controller/ShopGoods.php +++ b/app/data/controller/ShopGoods.php @@ -5,7 +5,6 @@ namespace app\data\controller; use app\data\service\GoodsService; use think\admin\Controller; use think\admin\extend\CodeExtend; -use think\admin\extend\DataExtend; /** * 商品数据管理 @@ -20,6 +19,20 @@ class ShopGoods extends Controller */ private $table = 'ShopGoods'; + /** + * 最大分类级别 + * @var integer + */ + protected $cateLevel; + + /** + * 控制器初始化 + */ + protected function initialize() + { + $this->cateLevel = GoodsService::instance()->getCateLevel(); + } + /** * 商品数据管理 * @auth true @@ -65,8 +78,7 @@ class ShopGoods extends Controller protected function _page_filter(&$data) { $this->marks = GoodsService::instance()->getMarkList(); - $query = $this->app->db->name('ShopGoodsCate')->where(['deleted' => 0, 'status' => 1]); - $this->clist = DataExtend::arr2table($query->order('sort desc,id desc')->select()->toArray()); + $this->clist = GoodsService::instance()->getCateList('arr2table'); $clist = $this->app->db->name('ShopGoodsCate')->whereIn('id', array_column($data, 'cate'))->column('pid,name,status', 'id'); foreach ($data as &$vo) { $vo['cate'] = $clist[$vo['cate']] ?? $vo['cate']; diff --git a/app/data/service/GoodsService.php b/app/data/service/GoodsService.php index 25fb5f847..796a00b75 100644 --- a/app/data/service/GoodsService.php +++ b/app/data/service/GoodsService.php @@ -67,7 +67,11 @@ class GoodsService extends Service { $map = ['deleted' => 0, 'status' => 1]; $query = $this->app->db->name('ShopGoodsCate')->where($map)->order('sort desc,id desc'); - return DataExtend::$type($query->withoutField('sort,status,deleted,create_at')->select()->toArray()); + $cates = DataExtend::$type($query->withoutField('sort,status,deleted,create_at')->select()->toArray()); + if ($type === 'arr2table') foreach ($cates as &$vo) { + $vo['sat'] = $vo['spt'] !== $this->getCateLevel() - 1 ? 'disabled' : ''; + } + return $cates; } /** diff --git a/app/data/view/shop_goods/form.html b/app/data/view/shop_goods/form.html index 8c41dffbf..c646b8da4 100644 --- a/app/data/view/shop_goods/form.html +++ b/app/data/view/shop_goods/form.html @@ -19,11 +19,10 @@ 所属分类 Category Name diff --git a/app/data/view/shop_goods/index_search.html b/app/data/view/shop_goods/index_search.html index 3fefc1d54..b99859988 100644 --- a/app/data/view/shop_goods/index_search.html +++ b/app/data/view/shop_goods/index_search.html @@ -32,9 +32,9 @@