From 416dbe7ec62481846421228e68a48d37ba44c241 Mon Sep 17 00:00:00 2001 From: gongfuxiang Date: Tue, 7 Jun 2022 00:49:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A8=E9=87=8F=E5=88=86=E7=B1=BB=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E6=96=B0=E5=A2=9E=E6=8C=87=E5=AE=9A=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/index/controller/Index.php | 2 +- app/service/GoodsService.php | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/index/controller/Index.php b/app/index/controller/Index.php index d0a543495..89350bd15 100755 --- a/app/index/controller/Index.php +++ b/app/index/controller/Index.php @@ -94,7 +94,7 @@ class Index extends Common MyViewAssign('pages_list', $pages_list); // 商品分类 - $goods_category = GoodsService::GoodsCategoryAll(); + $goods_category = GoodsService::GoodsCategory(['is_all'=>1]); MyViewAssign('goods_category_list', $goods_category); // 商品搜索分类(分类) diff --git a/app/service/GoodsService.php b/app/service/GoodsService.php index e8cc89929..e3476d8c5 100755 --- a/app/service/GoodsService.php +++ b/app/service/GoodsService.php @@ -95,19 +95,17 @@ class GoodsService // 获取分类 if(empty($params['where'])) { - $where = [ + $params['where'] = [ ['pid', '=', 0], ['is_enable', '=', 1], ]; - } else { - $where = $params['where']; } - $data = self::GoodsCategoryList(['where'=>$where]); + $data = self::GoodsCategoryList($params); if(!empty($data)) { // 基础条件、去除pid - $where_base = $where; - $temp_column = array_column($where, 0); + $where_base = $params['where']; + $temp_column = array_column($where_base, 0); if(in_array('pid', $temp_column)) { unset($where_base[array_search('pid', $temp_column)]); @@ -115,11 +113,13 @@ class GoodsService } foreach($data as &$v) { - $v['items'] = self::GoodsCategoryList(['where'=>array_merge($where_base, [['pid', '=', $v['id']]])]); + $params['where'] = array_merge($where_base, [['pid', '=', $v['id']]]); + $v['items'] = self::GoodsCategoryList($params); if(!empty($v['items'])) { // 一次性查出所有二级下的三级、再做归类、避免sql连接超多 - $itemss = self::GoodsCategoryList(['where'=>array_merge($where_base, [['pid', 'in', array_column($v['items'], 'id')]])]); + $params['where'] = array_merge($where_base, [['pid', 'in', array_column($v['items'], 'id')]]); + $itemss = self::GoodsCategoryList($params); if(!empty($itemss)) { foreach($v['items'] as &$vs)