分类ids优化

feat/task1-c-wallet
gongfuxiang 2018-12-17 03:26:45 +08:00
parent d4e76fe7e7
commit 2360fc51ee
3 changed files with 11 additions and 6 deletions

View File

@ -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');
} }

View File

@ -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
* @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);

View File

@ -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];
} }