store-product-spus
parent
9214b97f52
commit
23d75ebba8
|
|
@ -7,7 +7,7 @@ use App\Models\Store\Store;
|
|||
use App\Models\{ProductSku, ProductSpu};
|
||||
use App\Helpers\Paginator;
|
||||
use App\Models\Store\ProductSku as StoreProductSku;
|
||||
use App\Endpoint\Api\Http\Resources\{StoreResource, StoreProductSkuResource, StoreProductSpuResource};
|
||||
use App\Endpoint\Api\Http\Resources\{StoreResource, StoreProductSkuResource, StoreProductSpuResource, ProductSpuResource};
|
||||
use App\Endpoint\Api\Http\Resources\ProductFeatureResource;
|
||||
use App\Events\ProductSkuViewed;
|
||||
|
||||
|
|
@ -42,16 +42,17 @@ class StoreController extends Controller
|
|||
$input['sort'] = '-id';
|
||||
}
|
||||
|
||||
// $spuIds = StoreProductSku::where('store_id', $store->id)->where('status', 1)->pluck('product_spu_id')->toArray();
|
||||
// $spuIds = array_unique($spuIds);
|
||||
// $spuIds = array_values($spuIds);
|
||||
$spuIds = StoreProductSku::where('store_id', $store->id)->where('status', 1)->pluck('product_spu_id')->toArray();
|
||||
$spuIds = array_unique($spuIds);
|
||||
$spuIds = array_values($spuIds);
|
||||
$list = ProductSpu::with(['specs'])->whereIn('id', $spuIds)->filter($input)->simplePaginate(Paginator::resolvePerPage('per_page', 20, 50));
|
||||
return ProductSpuResource::collection($list);
|
||||
|
||||
$list = $store->productSpus()
|
||||
->with(['specs'])
|
||||
->filter($input)
|
||||
->wherePivot('status', 1)
|
||||
->distinct('product_spus.id')
|
||||
->simplePaginate(Paginator::resolvePerPage('per_page', 20, 50));
|
||||
// $list = $store->productSpus()
|
||||
// ->with(['specs'])
|
||||
// ->filter($input)
|
||||
// ->wherePivot('status', 1)
|
||||
// ->simplePaginate(Paginator::resolvePerPage('per_page', 20, 50));
|
||||
|
||||
return StoreProductSpuResource::collection($list);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace App\Endpoint\Api\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ProductSpuResource extends JsonResource
|
||||
{
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'cover' => (string) $this->cover,
|
||||
'sell_price' => (string) $this->sell_price_format,
|
||||
'vip_price' => (string) $this->vip_price_format,
|
||||
'market_price' => (string) $this->market_price_format,
|
||||
'stock' => (int) $this->stock,
|
||||
'specs' => $this->whenLoaded('specs'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue