|
@@ -34,7 +34,7 @@ class PageService extends BaseService
|
|
|
|
|
|
public function categoryTree()
|
|
|
{
|
|
|
- $categoryS = Category::with("childS")->where("parent_id", 0)->where("index_weight", ">", 0)->get(["id", "name", "thumb", "parent_id", "level", "weight"]);
|
|
|
+ $categoryS = Category::with("childS")->where("parent_id", 0)->where("index_weight", ">", 0)->orderByDesc("category_weight")->get(["id", "name", "thumb", "parent_id", "level", "weight"]);
|
|
|
return $categoryS->map(function (Category $category) {
|
|
|
return [
|
|
|
"id" => $category->id,
|
|
@@ -127,18 +127,21 @@ class PageService extends BaseService
|
|
|
$cidArr = $this->childCategoryIdArr($id);
|
|
|
|
|
|
$gidArr = GoodsCategoryMap::where("category_id", $cidArr)->get(['goods_id'])->pluck("goods_id")->unique()->toArray();
|
|
|
- $attrIdArr = [];
|
|
|
+ $attrMap = [];
|
|
|
if ($attrs = Arr::get($params, "attrs", [])) {
|
|
|
- $attrIdArr = json_decode($attrs, true);
|
|
|
+ $attrMap = 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);
|
|
|
+ })->when($attrMap, function (Builder $query) use ($attrMap) {
|
|
|
+ $mapQuery = GoodsSpecMap::query();
|
|
|
+ foreach ($attrMap as $attr) {
|
|
|
+ $mapQuery->orWhere(function (Builder $query) use ($attr) {
|
|
|
+ $query->where("spec_id", $attr['spec_id'])->Where("value", $attr['value']);
|
|
|
+ });
|
|
|
}
|
|
|
+ $goodsIdArr = $mapQuery->groupBy("goods_id")->having(DB::raw("count(`goods_id`)"), count($attrMap))->get("goods_id")->pluck("goods_id")->toArray();
|
|
|
+ $query->whereIn("id", $goodsIdArr);
|
|
|
})->orderByDesc("weight")->whereIn("id", $gidArr)->paginate($pageSize);
|
|
|
|
|
|
return [
|
|
@@ -194,7 +197,7 @@ class PageService extends BaseService
|
|
|
|
|
|
private function searchCategory($keyword)
|
|
|
{
|
|
|
- $c = Category::where("name", "like", "%$keyword%")->get();
|
|
|
+ $c = Category::where("name", "like", "%$keyword%")->orderByDesc("search_weight")->get();
|
|
|
|
|
|
return $c->map(function (Category $model) {
|
|
|
return [
|