diff --git a/application/admin/controller/Site.php b/application/admin/controller/Site.php index ff4bc163b15d7c942dfc443d6103fa081f3b1c29..b5505d305caa1e67d30e2f76ae757e72fd1b17da 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 158ceb9444996679bc17238f47e626ac3364e54f..742199d358ef5bef901a1693c2ed5d8b483142e4 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 6b2905da351d523cda3b6c414f019813f09fb731..faf241e49529954c7f4417367beeb3cc6d6c9654 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; }