提交 2360fc51 编写于 作者: G gongfuxiang

分类ids优化

上级 d4e76fe7
...@@ -106,7 +106,7 @@ class BrandService ...@@ -106,7 +106,7 @@ class BrandService
if(!empty($params['category_id'])) if(!empty($params['category_id']))
{ {
// 根据分类获取品牌id // 根据分类获取品牌id
$category_ids = GoodsService::GoodsCategoryItemsIds([$params['category_id']]); $category_ids = GoodsService::GoodsCategoryItemsIds([$params['category_id']], 1);
$where = ['g.is_delete_time'=>0, 'g.is_shelves'=>1, 'gci.id'=>$category_ids]; $where = ['g.is_delete_time'=>0, 'g.is_shelves'=>1, 'gci.id'=>$category_ids];
$brand_where['id'] = db('Goods')->alias('g')->join(['__GOODS_CATEGORY_JOIN__'=>'gci'], 'g.id=gci.goods_id')->field('g.brand_id')->where($where)->group('g.brand_id')->column('brand_id'); $brand_where['id'] = db('Goods')->alias('g')->join(['__GOODS_CATEGORY_JOIN__'=>'gci'], 'g.id=gci.goods_id')->field('g.brand_id')->where($where)->group('g.brand_id')->column('brand_id');
} }
......
...@@ -144,7 +144,7 @@ class GoodsService ...@@ -144,7 +144,7 @@ class GoodsService
{ {
foreach($goods_category as &$v) foreach($goods_category as &$v)
{ {
$category_ids = self::GoodsCategoryItemsIds([$v['id']]); $category_ids = self::GoodsCategoryItemsIds([$v['id']], 1);
$v['goods'] = self::CategoryGoodsList(['where'=>['gci.category_id'=>$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']); $v['goods'] = self::CategoryGoodsList(['where'=>['gci.category_id'=>$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']);
} }
} }
...@@ -159,11 +159,16 @@ class GoodsService ...@@ -159,11 +159,16 @@ class GoodsService
* @date 2018-08-29 * @date 2018-08-29
* @desc description * @desc description
* @param [array] $ids [分类id数组] * @param [array] $ids [分类id数组]
* @param [int] $is_enable [是否启用 0否, 1是] * @param [int] $is_enable [是否启用 null, 0否, 1是]
*/ */
public static function GoodsCategoryItemsIds($ids = [], $is_enable = 1) public static function GoodsCategoryItemsIds($ids = [], $is_enable = null)
{ {
$data = db('GoodsCategory')->where(['pid'=>$ids, 'is_enable'=>$is_enable])->column('id'); $where = ['pid'=>$ids];
if($is_enable !== null)
{
$where['is_enable'] = $is_enable;
}
$data = db('GoodsCategory')->where($where)->column('id');
if(!empty($data)) if(!empty($data))
{ {
$temp = self::GoodsCategoryItemsIds($data, $is_enable); $temp = self::GoodsCategoryItemsIds($data, $is_enable);
......
...@@ -78,7 +78,7 @@ class SearchService ...@@ -78,7 +78,7 @@ class SearchService
// 分类id // 分类id
if(!empty($params['category_id'])) if(!empty($params['category_id']))
{ {
$category_ids = GoodsService::GoodsCategoryItemsIds([$params['category_id']]); $category_ids = GoodsService::GoodsCategoryItemsIds([$params['category_id']], 1);
$category_ids[] = $params['category_id']; $category_ids[] = $params['category_id'];
$where[] = ['gci.category_id', 'in', $category_ids]; $where[] = ['gci.category_id', 'in', $category_ids];
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册