Files
water_new/modules/Mall/Http/Resources/Api/Goods/GoodsResource.php
2023-03-08 09:16:04 +08:00

51 lines
1.8 KiB
PHP

<?php
namespace Modules\Mall\Http\Resources\Api\Goods;
use Illuminate\Http\Resources\Json\JsonResource;
use Jason\Api\Api;
use Modules\Mall\Http\Resources\Api\Category\CategoryBaseResource;
use Modules\Mall\Http\Resources\Api\Shop\ShopBaseInfoResource;
class GoodsResource extends JsonResource
{
public function toArray($request): array
{
$user = Api::user();
return [
'goods_id' => $this->id,
'shop' => new ShopBaseInfoResource($this->shop),
'brand' => new BrandResource($this->brand),
'category' => new CategoryBaseResource($this->category),
'tags' => TagResource::collection($this->tags),
'type' => $this->type,
'pay_type' => $this->pay_type,
'clicks' => $this->clicks,
'sales' => $this->sales,
'name' => $this->name,
'cover' => $this->cover_url,
'pictures' => $this->pictures_url,
'description' => $this->description ?? '',
'content' => $this->content,
'created_at' => (string) $this->created_at,
'original_price' => (float) $this->original_price,
'price' => [
'show' => $this->price,
'score' => $this->score,
'price_min' => $this->price_min,
'price_max' => $this->price_max,
],
'specs' => SpecResource::collection($this->specs),
'skus' => SkuResource::collection($this->skus),
'canPick' => $user && $user->canPick(),
'hasCase' => $user && (bool) $user->case,
'hasLogin' => (bool) $user,
];
}
}