|
@@ -146,8 +146,18 @@ class PageService extends BaseService
|
|
|
|
|
|
public function search($params)
|
|
|
{
|
|
|
+ $attrId = [];
|
|
|
+ if ($attrs = Arr::get($params, "attrs", [])) {
|
|
|
+ $attrId = json_decode($attrs, true);
|
|
|
+ }
|
|
|
$pageSize = Arr::get($params, "page_size", 10);
|
|
|
- $p = Goods::where("status", Goods::STATUS_OK)->when($params['keyword'], function (Builder $query) use ($params) {
|
|
|
+ $p = Goods::where("status", Goods::STATUS_OK)->when($attrId, function (Builder $query) use ($attrId) {
|
|
|
+ $d = SpecAttr::whereIn("id", $attrId)->groupBy("spec_id")->get(['spec_id']);
|
|
|
+ $specIdArr = $d->pluck("spec_id")->toArray();
|
|
|
+ foreach ($specIdArr as $specId) {
|
|
|
+ $query->whereJsonContains("spec", $specId);
|
|
|
+ }
|
|
|
+ })->when($params['keyword'], function (Builder $query) use ($params) {
|
|
|
$query->where("name", "like", "%" . $params['keyword'] . "%");
|
|
|
})->orderByDesc("weight")->paginate($pageSize);
|
|
|
|