From 173463d220eef703e9b1ff826ed23be8ef8056ab Mon Sep 17 00:00:00 2001 From: gongfuxiang <2499232802@qq.com> Date: Sat, 1 Dec 2018 02:56:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=B1=BBsql=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Application/Service/GoodsService.class.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Application/Service/GoodsService.class.php b/Application/Service/GoodsService.class.php index 327b5a645..8099e7d04 100755 --- a/Application/Service/GoodsService.class.php +++ b/Application/Service/GoodsService.class.php @@ -131,7 +131,7 @@ class GoodsService { foreach($goods_category as &$v) { - $category_ids = self::GoodsCategoryItemsIds(['category_id'=>$v['id']]); + $category_ids = self::GoodsCategoryItemsIds([$v['id']]); $v['goods'] = self::GoodsList(['where'=>['gci.category_id'=>['in', $category_ids], 'is_home_recommended'=>1], 'm'=>0, 'n'=>6, 'field'=>'g.id,g.title,g.title_color,g.images,g.home_recommended_images,g.original_price,g.price,g.inventory,g.buy_min_number,g.buy_max_number']); } } @@ -145,20 +145,17 @@ class GoodsService * @version 1.0.0 * @date 2018-08-29 * @desc description - * @param [array] $params [输入参数] + * @param [array] $ids [分类id数组] */ - public static function GoodsCategoryItemsIds($params = []) + public static function GoodsCategoryItemsIds($ids = []) { - $data = M('GoodsCategory')->where(['pid'=>$params['category_id'], 'is_enable'=>1])->getField('id', true); + $data = M('GoodsCategory')->where(['pid'=>['in', $ids], 'is_enable'=>1])->getField('id', true); if(!empty($data)) { - foreach($data as $v) + $temp = self::GoodsCategoryItemsIds($data); + if(!empty($temp)) { - $temp = self::GoodsCategoryItemsIds(['category_id'=>$v]); - if(!empty($temp)) - { - $data = array_merge($data, $temp); - } + $data = array_merge($data, $temp); } } return $data; -- GitLab