Browse Source

商户详情页的分类信息、商品搜索加入store_id筛选

master
weigang 5 years ago
parent
commit
d4c9eacdf1
  1. 18
      app/Service/v3/Implementations/CategoryService.php
  2. 4
      app/Service/v3/Implementations/SearchService.php

18
app/Service/v3/Implementations/CategoryService.php

@ -50,16 +50,26 @@ class CategoryService implements CategoryServiceInterface
public function allForStore($storeId)
{
$goodsTypeIds = Goods::query()->select('id','category_id')
$goodsTypeIds = Goods::query()
->where(['store_id' => $storeId])
->groupBy('category_id', 'id')
->get()->toArray();
->pluck('category_id');
return Category::query()
->whereIn('id', array_values(array_column($goodsTypeIds, 'category_id')))
$categories = Category::query()
->with(['goodsCategory'])
->whereIn('id', $goodsTypeIds)
->orderBy('sort', 'DESC')
->orderBy('id', 'DESC')
->get()->toArray();
foreach ($categories as $key => &$item) {
$item['goods_category_ids'] = '';
if (isset($item['goods_category']) && $item['goods_category']) {
$item['goods_category_ids'] = implode(',', array_values(array_column($item['goods_category'], 'id')));
}
}
return $categories;
}
public function allForAppletIndex()

4
app/Service/v3/Implementations/SearchService.php

@ -26,6 +26,10 @@ class SearchService implements SearchServiceInterface
$query->where('inventory', '>', 0)->orWhere('is_infinite', '=', 1);
});;
if (isset($params['store_id']) && $params['store_id']) {
$builder->where(['store_id' => $params['store_id']]);
}
if (isset($params['type_id']) && $params['type_id']) {
$typeIds = explode(',', $params['type_id']);
$builder->whereIn('category_id', $typeIds);

Loading…
Cancel
Save