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

37 lines
1.1 KiB
PHP

<?php
namespace App\Endpoint\Api\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class UserWalletResource 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 (is_null($this->resource)) {//没有钱包数据时默认数据
return [
'balance'=> '0.00',
// 'total_expenses'=> $this->total_expenses,
// 'total_revenue' => $this->total_revenue,
'withdrawable' => true,
'has_password' => false,
'is_frozen' => false,
];
}
return [
'balance'=> $this->balance_format,
// 'total_expenses'=> $this->total_expenses,
// 'total_revenue' => $this->total_revenue,
'withdrawable' => (bool) $this->withdrawable,
'is_frozen' => (bool) $this->is_frozen,
'has_password' => (bool) $this->password??false,
];
}
}