55 lines
2.2 KiB
PHP
55 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Endpoint\Api\Http\Resources;
|
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class OrderResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
if ($this->resource->relationLoaded('products')) {
|
|
foreach ($this->resource->products as $product) {
|
|
$product->setRelation('order', $this->resource);
|
|
}
|
|
}
|
|
|
|
return [
|
|
'id' => $this->id,
|
|
'sn' => $this->sn,
|
|
'products' => OrderProductResource::collection($this->whenLoaded('products')),
|
|
'coupon_discount_amount' => $this->coupon_discount_amount_format,
|
|
'vip_discount_amount' => $this->vip_discount_amount_format,
|
|
'reduced_amount' => $this->reduced_amount_format,
|
|
'bargain_amount' => $this->bargain_amount_format,
|
|
'shipping_fee' => $this->shipping_fee_format,
|
|
'products_total_amount' => $this->products_total_amount_format,
|
|
'point_discount_amount' => $this->point_discount_amount_format,
|
|
'total_amount' => $this->total_amount_format,
|
|
'status' => $this->order_status,
|
|
'note' => (string) $this->note,
|
|
'consignee_name' => $this->consignee_name,
|
|
'consignee_telephone' => $this->consignee_telephone,
|
|
'consignee_zone' => $this->consignee_zone,
|
|
'consignee_address' => $this->consignee_address,
|
|
'pay_way' => (string) $this->pay_way?->label(),
|
|
'pay_at' => (string) $this->pay_at?->toDateTimeString(),
|
|
'completed_at' => (string) $this->completed_at?->toDateTimeString(),
|
|
'created_at' => $this->created_at->toDateTimeString(),
|
|
'expires_at' => $this->expires_at,
|
|
|
|
'packages' => OrderPackageResource::make($this->whenLoaded('lastPackage')),
|
|
|
|
'source_type' => $this->source_type,
|
|
'source_id' => $this->source_id,
|
|
'store_id' => $this->store_id,
|
|
];
|
|
}
|
|
}
|