From 5fa361def390ecc5d8febe0565e75ac184d9f6ab Mon Sep 17 00:00:00 2001 From: gongfuxiang <2499232802@qq.com> Date: Fri, 5 Apr 2019 00:35:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=86=E7=B1=BB=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Goods.php | 2 +- .../admin/controller/Goodscategory.php | 2 +- application/admin/controller/Navigation.php | 2 +- application/index/controller/Common.php | 2 +- application/plugins/answers/Admin.php | 2 +- application/service/GoodsService.php | 37 ++++++++++++++----- 6 files changed, 33 insertions(+), 14 deletions(-) diff --git a/application/admin/controller/Goods.php b/application/admin/controller/Goods.php index 803bafcf3..7a3468202 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 83fdf6aa4..ca46d6a6e 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 44af82010..424f7beb1 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 67a1a8d20..5bdd7b826 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 9d00a5d7c..f5298c523 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 455d11e02..76d38bf62 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)) {