6
0
Fork 0
jiqu-library-server/app/Endpoint/Api/Http/Resources/OrderResource.php

41 lines
1.6 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)
{
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,
'shipping_fee' => $this->shipping_fee_format,
'products_total_amount' => $this->products_total_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,
'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,
];
}
}