|
@@ -122,11 +122,18 @@ class PageService extends BaseService
|
|
|
$cidArr = $this->childCategoryIdArr($id);
|
|
|
|
|
|
$gidArr = GoodsCategoryMap::where("category_id", $cidArr)->get(['goods_id'])->pluck("goods_id")->unique()->toArray();
|
|
|
- if ($attrs = Arr::get($params, "attr", [])) {
|
|
|
-
|
|
|
+ $attrIdArr = [];
|
|
|
+ if ($attrs = Arr::get($params, "attrs", [])) {
|
|
|
+ $attrIdArr = json_decode($attrs, true);
|
|
|
}
|
|
|
$p = Goods::where("status", Goods::STATUS_OK)->when($params['keyword'], function (Builder $query) use ($params) {
|
|
|
$query->where("name", "like", "%" . $params['keyword'] . "%");
|
|
|
+ })->when($attrIdArr, function (Builder $query) use ($attrIdArr) {
|
|
|
+ $d = SpecAttr::whereIn("id", $attrIdArr)->groupBy("spec_id")->get(['spec_id']);
|
|
|
+ $specIdArr = $d->pluck("spec_id")->toArray();
|
|
|
+ foreach ($specIdArr as $specId) {
|
|
|
+ $query->whereJsonContains("spec", $specId);
|
|
|
+ }
|
|
|
})->orderByDesc("weight")->whereIn("id", $gidArr)->paginate($pageSize);
|
|
|
|
|
|
return [
|