From 4e1af35b37af6e879d33b9da0d3c7125e707985b Mon Sep 17 00:00:00 2001 From: Devil Date: Fri, 11 Jun 2021 16:18:21 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BB=E5=8F=96=E5=95=86=E5=93=81=E5=88=86?= =?UTF-8?q?=E7=B1=BB=E6=9D=A1=E4=BB=B6=E4=B8=80=E7=BB=B4=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E4=BA=8C=E7=BB=B4=E6=95=B0=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Site.php | 12 ++++++-- application/service/GoodsService.php | 41 +++++++++++++++++++++------ application/service/SearchService.php | 5 +++- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/application/admin/controller/Site.php b/application/admin/controller/Site.php index ff4bc163b..b5505d305 100755 --- a/application/admin/controller/Site.php +++ b/application/admin/controller/Site.php @@ -92,7 +92,11 @@ class Site extends Common // 网站设置 case 'siteset' : // 获取商品一级分类 - $where = ['pid'=>0, 'is_home_recommended'=>1, 'is_enable'=>1]; + $where = [ + ['pid', '=', 0], + ['is_home_recommended', '=', 1], + ['is_enable', '=', 1], + ]; $category = GoodsService::GoodsCategoryList(['where'=>$where]); if(!empty($category)) { @@ -103,7 +107,11 @@ class Site extends Common foreach($category as &$c) { // 获取二级分类 - $c['items'] = GoodsService::GoodsCategoryList(['where'=>['pid'=>$c['id'], 'is_enable'=>1]]); + $where = [ + ['pid', '=', $c['id']], + ['is_enable', '=', 1], + ]; + $c['items'] = GoodsService::GoodsCategoryList(['where'=>$where]); // 配置的关键字 $c['config_keywords'] = array_key_exists($c['id'], $floor_keywords) ? $floor_keywords[$c['id']] : ''; diff --git a/application/service/GoodsService.php b/application/service/GoodsService.php index 158ceb944..742199d35 100755 --- a/application/service/GoodsService.php +++ b/application/service/GoodsService.php @@ -69,7 +69,10 @@ class GoodsService if(empty($data) || config('app_debug')) { // 获取分类 - $params['where'] = ['pid'=>0, 'is_enable'=>1]; + $params['where'] = [ + ['pid', '=', 0], + ['is_enable', '=', 1], + ]; $data = self::GoodsCategory($params); // 存储缓存 @@ -90,19 +93,33 @@ class GoodsService public static function GoodsCategory($params = []) { // 获取分类 - $where = empty($params['where']) ? ['pid'=>0, 'is_enable'=>1] : $params['where']; + if(empty($params['where'])) + { + $where = [ + ['pid', '=', 0], + ['is_enable', '=', 1], + ]; + } else { + $where = $params['where']; + } $data = self::GoodsCategoryList(['where'=>$where]); if(!empty($data)) { + // 基础条件、去除pid + $where_base = $where; + $temp_column = array_column($where, 0); + if(in_array('pid', $temp_column)) + { + unset($where_base[array_search('pid', $temp_column)]); + sort($where_base); + } foreach($data as &$v) { - $where['pid'] = $v['id']; - $v['items'] = self::GoodsCategoryList(['where'=>$where]); + $v['items'] = self::GoodsCategoryList(['where'=>array_merge($where_base, [['pid', '=', $v['id']]])]); if(!empty($v['items'])) { // 一次性查出所有二级下的三级、再做归类、避免sql连接超多 - $where['pid'] = array_column($v['items'], 'id'); - $itemss = self::GoodsCategoryList(['where'=>$where]); + $itemss = self::GoodsCategoryList(['where'=>array_merge($where_base, [['pid', 'in', array_column($v['items'], 'id')]])]); if(!empty($itemss)) { foreach($v['items'] as &$vs) @@ -135,7 +152,9 @@ class GoodsService { // 条件、附加必须启用状态 $where = empty($params['where']) ? [] : $params['where']; - $where['is_enable'] = 1; + + // 增加启用条件 + $where[] = ['is_enable', '=', 1]; // 数量、默认0,0则全部 $m = isset($params['m']) ? intval($params['m']) : 0; @@ -197,7 +216,11 @@ class GoodsService if(empty($data) || config('app_debug')) { // 商品大分类 - $where = ['pid'=>0, 'is_home_recommended'=>1, 'is_enable'=>1]; + $where = [ + ['pid', '=', 0], + ['is_home_recommended', '=', 1], + ['is_enable', '=', 1], + ]; $data = self::GoodsCategoryList(['where'=>$where]); if(!empty($data)) { @@ -287,7 +310,7 @@ class GoodsService // 楼层左侧分类 if(!empty($floor_left_top_category) && !empty($floor_left_top_category[$v['id']])) { - $v['items'] = self::GoodsCategoryList(['where'=>['id'=>explode(',', $floor_left_top_category[$v['id']])], 'm'=>0, 'n'=>0]); + $v['items'] = self::GoodsCategoryList(['where'=>[['id', 'in', explode(',', $floor_left_top_category[$v['id']])]], 'm'=>0, 'n'=>0]); } else { $v['items'] = []; } diff --git a/application/service/SearchService.php b/application/service/SearchService.php index 6b2905da3..faf241e49 100755 --- a/application/service/SearchService.php +++ b/application/service/SearchService.php @@ -466,7 +466,10 @@ class SearchService if(MyC('home_search_is_category', 0) == 1) { $pid = empty($params['category_id']) ? 0 : intval($params['category_id']); - $data = GoodsService::GoodsCategoryList(['where'=>['pid'=>$pid], 'field'=>'id,name']); + $where = [ + ['pid', '=', $pid], + ]; + $data = GoodsService::GoodsCategoryList(['where'=>$where, 'field'=>'id,name']); } return $data; }