39 lines
1.2 KiB
PHP
39 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Str;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
use Illuminate\Http\Response;
|
|
|
|
class UserResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return array
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
return [
|
|
'phone' => $this->phone ??'',
|
|
'nick_name' => $this->nick_name ??'',
|
|
'avatar' => $this->avatar ? (Str::startsWith($this->avatar, 'http') ? $this->avatar:env('OSS_URL').$this->avatar):'',
|
|
'points' => $this->points ??0,
|
|
'draw_num' => $this->draw_num ??0,
|
|
'lv' => $this->rankLv(),
|
|
|
|
|
|
// 在登录的时候才返回 api_token, 和api过期时间
|
|
'api_token' => $this->when($this->api_token, $this->api_token),
|
|
'expire_in' => $this->when($this->api_token, Carbon::parse()->addSeconds(auth('api')->factory()->getTTL() * 60)->toDateTimeString())
|
|
];
|
|
}
|
|
|
|
public function with($request)
|
|
{
|
|
return ['code' => Response::HTTP_OK, 'message' => ''];
|
|
}
|
|
} |