diff --git a/application/admin/controller/Goods.php b/application/admin/controller/Goods.php index 803bafcf3945e86f13398de3e4158096601ede83..7a3468202eef6d5f0070c92904332f4e49e3d241 100755 --- a/application/admin/controller/Goods.php +++ b/application/admin/controller/Goods.php @@ -135,7 +135,7 @@ class Goods extends Common $this->assign('region_province_list', RegionService::RegionItems(['pid'=>0])); // 商品分类 - $this->assign('category_list', GoodsService::GoodsCategory()); + $this->assign('category_list', GoodsService::GoodsCategoryAll()); // 品牌分类 $this->assign('brand_list', BrandService::CategoryBrand()); diff --git a/application/admin/controller/Goodscategory.php b/application/admin/controller/Goodscategory.php index 83fdf6aa4bcef43aa98c5b8e4bd7ee7889503fcc..ca46d6a6e24f4f562c4ecc887fcc582ccc0137a4 100755 --- a/application/admin/controller/Goodscategory.php +++ b/application/admin/controller/Goodscategory.php @@ -56,7 +56,7 @@ class GoodsCategory extends Common $this->assign('common_is_text_list', lang('common_is_text_list')); // 商品分类 - $this->assign('goods_category_list', GoodsService::GoodsCategory()); + $this->assign('goods_category_list', GoodsService::GoodsCategoryAll()); // 编辑器文件存放地址 $this->assign('editor_path_type', 'goods_category'); diff --git a/application/admin/controller/Navigation.php b/application/admin/controller/Navigation.php index 44af82010424dbaa04832fe3e56a61d505b6e180..424f7beb10c01e4cea0d99823f91ebfde17937e8 100755 --- a/application/admin/controller/Navigation.php +++ b/application/admin/controller/Navigation.php @@ -67,7 +67,7 @@ class Navigation extends Common $this->assign('article_list', $article_category_content['data']); // 商品分类 - $this->assign('goods_category_list', GoodsService::GoodsCategory()); + $this->assign('goods_category_list', GoodsService::GoodsCategoryAll()); // 自定义页面 $this->assign('customview_list', db('CustomView')->field(array('id', 'title'))->where(array('is_enable'=>1))->select()); diff --git a/application/index/controller/Common.php b/application/index/controller/Common.php index 67a1a8d2036adb54c7a8cf9e776af37e66ac5bc5..5bdd7b8267ff5291f701237ce10e0e4cafcae75c 100755 --- a/application/index/controller/Common.php +++ b/application/index/controller/Common.php @@ -247,7 +247,7 @@ class Common extends Controller $this->assign('user_left_menu', NavigationService::UsersCenterLeftList()); // 商品大分类 - $this->assign('goods_category_list', GoodsService::GoodsCategory()); + $this->assign('goods_category_list', GoodsService::GoodsCategoryAll()); // 搜索框下热门关键字 $home_search_keywords = []; diff --git a/application/plugins/answers/Admin.php b/application/plugins/answers/Admin.php index 9d00a5d7cb1987c8f94047d019b4e246365d6bb2..f5298c523c028c9b3484a01a5464c3f0d473b171 100644 --- a/application/plugins/answers/Admin.php +++ b/application/plugins/answers/Admin.php @@ -223,7 +223,7 @@ class Admin extends Controller $this->assign('goods', $goods['data']); // 商品分类 - $this->assign('goods_category_list', GoodsService::GoodsCategory()); + $this->assign('goods_category_list', GoodsService::GoodsCategoryAll()); return $this->fetch('../../../plugins/view/answers/admin/goodsinfo'); } diff --git a/application/service/GoodsService.php b/application/service/GoodsService.php index 455d11e0217458eb21c1f76923a8088ba7dc0d45..76d38bf62999a50bae1aab0a7981614ba75c9081 100755 --- a/application/service/GoodsService.php +++ b/application/service/GoodsService.php @@ -46,7 +46,7 @@ class GoodsService } /** - * 获取大分类 + * 获取所有分类 * @author Devil * @blog http://gong.gg/ * @version 1.0.0 @@ -54,7 +54,7 @@ class GoodsService * @desc description * @param [array] $params [输入参数] */ - public static function GoodsCategory($params = []) + public static function GoodsCategoryAll($params = []) { // 从缓存获取 $key = config('shopxo.cache_goods_category_key'); @@ -64,6 +64,27 @@ class GoodsService return $data; } + // 获取分类 + $params['where'] = ['pid'=>0, 'is_enable'=>1]; + $data = self::GoodsCategory($params); + + // 存储缓存 + cache($key, $data); + + return $data; + } + + /** + * 获取分类 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2018-08-29 + * @desc description + * @param [array] $params [输入参数] + */ + public static function GoodsCategory($params = []) + { // 获取分类 $where = empty($params['where']) ? ['pid'=>0, 'is_enable'=>1] : $params['where']; $data = self::GoodsCategoryList($where); @@ -71,11 +92,13 @@ class GoodsService { foreach($data as &$v) { - $v['items'] = self::GoodsCategoryList(['pid'=>$v['id'], 'is_enable'=>1]); + $where['pid'] = $v['id']; + $v['items'] = self::GoodsCategoryList($where); if(!empty($v['items'])) { // 一次性查出所有二级下的三级、再做归类、避免sql连接超多 - $items = self::GoodsCategoryList(['pid'=>array_column($v['items'], 'id'), 'is_enable'=>1]); + $where['pid'] = array_column($v['items'], 'id'); + $items = self::GoodsCategoryList($where); if(!empty($items)) { foreach($v['items'] as &$vs) @@ -92,10 +115,6 @@ class GoodsService } } } - - // 存储缓存 - cache($key, $data); - return $data; } @@ -160,7 +179,7 @@ class GoodsService public static function HomeFloorList($params = []) { // 商品大分类 - $params['where'] = ['pid'=>0, 'is_home_recommended'=>1]; + $params['where'] = ['pid'=>0, 'is_home_recommended'=>1, 'is_enable'=>1]; $goods_category = self::GoodsCategory($params); if(!empty($goods_category)) {