41 lines
1.3 KiB
PHP
41 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class OrderResource extends JsonResource
|
|
{
|
|
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return array
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
$cancel = Carbon::now()->diffInSeconds($this->created_at->addMinutes(config('aslong_order.auto_cancel_order')), false);
|
|
return [
|
|
'id' => $this->id,
|
|
'orderid' => $this->orderid,
|
|
'goods_list' => OrderDetailResource::collection($this->details),
|
|
'state' => $this->state,
|
|
'state_text' => $this->state_text,
|
|
'total' => number_format($this->total, 2),
|
|
'amount' => number_format($this->amount, 2),
|
|
'freight' => number_format($this->freight, 2),
|
|
'handleOption' => [
|
|
'pay' => $this->canPay(),
|
|
],
|
|
'created_at' => (string) $this->created_at,
|
|
'paid' => $this->when($this->paid_at, [
|
|
'paid_at' => (string) $this->payment->end_at,
|
|
'type' => strip_tags($this->payment->type_text),
|
|
'transaction_id' => $this->payment->transaction_id,
|
|
]),
|
|
];
|
|
}
|
|
}
|