|
|
|
@ -20,6 +20,8 @@ class SearchService implements SearchServiceInterface |
|
|
|
public function doForGoods($params) |
|
|
|
{ |
|
|
|
|
|
|
|
$params['pagesize'] = $params['pagesize'] ?: 10; |
|
|
|
|
|
|
|
$storeTable = ApplicationContext::getContainer()->get(Store::class)->getTable(); |
|
|
|
$goodsTable = ApplicationContext::getContainer()->get(Goods::class)->getTable(); |
|
|
|
|
|
|
|
@ -92,14 +94,29 @@ class SearchService implements SearchServiceInterface |
|
|
|
} |
|
|
|
|
|
|
|
$builder->select(''.$goodsTable.'.*')->addSelect([''.$goodsTable.'.sales as total_sales']); |
|
|
|
|
|
|
|
// Feature/搜索商品也展示出三级分类
|
|
|
|
$allGoodsCategoryIds = $builder->groupBy(''.$goodsTable.'.goods_category_id')->pluck('goods_category_id'); |
|
|
|
$goodsCategories = GoodsCategory::query() |
|
|
|
->whereIn('id', $allGoodsCategoryIds) |
|
|
|
->get() |
|
|
|
->toArray(); |
|
|
|
$goodsCategoryIds = implode(',', array_values(array_column($goodsCategories, 'id'))); |
|
|
|
|
|
|
|
$paginate = $builder->groupBy(''.$goodsTable.'.id')->inRandomOrder()->paginate($params['pagesize']); |
|
|
|
$goods = $paginate->toArray(); |
|
|
|
return ['has_more_pages' => $paginate->hasMorePages(), 'goods' => $goods['data']]; |
|
|
|
return [ |
|
|
|
'has_more_pages' => $paginate->hasMorePages(), |
|
|
|
'goods' => $goods['data'], |
|
|
|
'category' => ['goods_category' => $goodsCategories, 'goods_category_ids' => $goodsCategoryIds] |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
public function doForStores($params) |
|
|
|
{ |
|
|
|
|
|
|
|
$params['pagesize'] = $params['pagesize'] ?: 10; |
|
|
|
|
|
|
|
$storeTable = ApplicationContext::getContainer()->get(Store::class)->getTable(); |
|
|
|
$goodsTable = ApplicationContext::getContainer()->get(Goods::class)->getTable(); |
|
|
|
|
|
|
|
@ -142,7 +159,9 @@ class SearchService implements SearchServiceInterface |
|
|
|
$builder->orderByDefault($sort); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$paginate = $builder->groupBy(''.$storeTable.'.id')->inRandomOrder()->paginate($params['pagesize']); |
|
|
|
$stores = $paginate->map(function ($item, $key) { |
|
|
|
$item->goods; |
|
|
|
|