where('status', 1); })->where('status', 1)->where('stock', '>', 0)->where('score', '>', 0)->whereRaw('price > score')->select('goods_id', DB::raw('any_value(stock) as stock'), DB::raw('any_value(status) as status'), DB::raw('any_value(price) as price'), DB::raw('any_value(score) as score'), DB::raw('any_value(id) as id')) ->groupBy('goods_id') ->orderBy('price', 'asc') ->paginate(10); $page = $request->page ?? 1; //获取当前页码 if ($page > 1) { //页码大于1,AJAX调用分页 if ($goodsLists->count() > 0) { return [ 'data' => [ 'goodsLists' => GoodsParamsListResource::collection($goodsLists), ], 'status' => 'SUCCESS', 'status_code' => 200, ]; } else { //无内容提示到最后一页 return $this->failed('已经到最后一页'); } }else{ $sellers = Seller::with(['storage'])->orderBy('sort', 'desc')->limit(12)->get(); $recommendSellerGoods = GoodsParams::whereHas('goods', function ($query) { return $query->where('status', 1)->where('seller_id', 1); })->where('status', 1)->where('stock', '>', 0)->where('score', '>', 0)->whereRaw('price > score')->select('goods_id', DB::raw('any_value(stock) as stock'), DB::raw('any_value(status) as status'), DB::raw('any_value(price) as price'), DB::raw('any_value(score) as score'), DB::raw('any_value(id) as id')) ->groupBy('goods_id') ->orderBy('price', 'asc') ->limit(8)->get(); return [ 'data' => [ 'goodsLists' => GoodsParamsListResource::collection($goodsLists), 'sellers' => SellerListResource::collection($sellers), 'recommendSellerGoods' => GoodsParamsListResource::collection($recommendSellerGoods) ], 'status' => 'SUCCESS', 'status_code' => 200, ]; } } }