|
|
|
@ -4,11 +4,14 @@ |
|
|
|
namespace App\Service\v3\Implementations; |
|
|
|
|
|
|
|
|
|
|
|
use App\Model\v3\Category; |
|
|
|
use App\Model\v3\Goods; |
|
|
|
use App\Model\v3\GoodsCategory; |
|
|
|
use App\Model\v3\Store; |
|
|
|
use App\Service\v3\Interfaces\SearchServiceInterface; |
|
|
|
use Hyperf\Paginator\Paginator; |
|
|
|
|
|
|
|
class SearchService implements \App\Service\v3\Interfaces\SearchServiceInterface |
|
|
|
class SearchService implements SearchServiceInterface |
|
|
|
{ |
|
|
|
|
|
|
|
public function doForGoods($params) |
|
|
|
@ -34,7 +37,15 @@ class SearchService implements \App\Service\v3\Interfaces\SearchServiceInterface |
|
|
|
} |
|
|
|
|
|
|
|
if (isset($params['keyword']) && $params['keyword']) { |
|
|
|
$builder->where('name', 'like', '%'.$params['keyword'].'%'); |
|
|
|
// 二级分类
|
|
|
|
$categoryIds = Category::query()->where('title', 'like', '%'.$params['keyword'].'%')->pluck('id'); |
|
|
|
// 三级分类
|
|
|
|
$goodsCategoryIds = GoodsCategory::query()->where('title', 'like', '%'.$params['keyword'].'%')->pluck('id'); |
|
|
|
$builder->where(function ($query) use ($params, $categoryIds, $goodsCategoryIds) { |
|
|
|
$query->where('name', 'like', '%'.$params['keyword'].'%') |
|
|
|
->orWhereIn('category_id', $categoryIds) |
|
|
|
->orWhereIn('goods_category_id', $goodsCategoryIds); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
if (isset($params['order_by']) && $params['order_by']) { |
|
|
|
|