Files
lotteryLaravel/app/Http/Controllers/Api/V1/Player/MeController.php

40 lines
1.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Http\Controllers\Api\V1\Player;
use App\Http\Controllers\Controller;
use App\Support\ApiResponse;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
/**
* 鉴权自检:返回当前 Token 对应的玩家公开字段(不含密码)。
*
* 路由GET /api/v1/player/me ,需 middleware lottery.player。
*
* 补充字段与 PRD「识别玩家」及前端引导一致`locale` 为当次 API 实际使用的语言(与 `NegotiateLotteryLocale` 一致);
* 时间类为 ISO 8601 字符串,便于 H5 展示与排错。
*/
class MeController extends Controller
{
public function __invoke(Request $request): JsonResponse
{
$player = $request->lotteryPlayer();
// 理论上不会为 null路由已套 EnsurePlayerApi保留断言便于排查配置错误
abort_if($player === null, 500, 'lottery_player missing');
return ApiResponse::success([
'id' => $player->id,
'site_code' => $player->site_code,
'site_player_id' => $player->site_player_id,
'username' => $player->username,
'nickname' => $player->nickname,
'default_currency' => $player->default_currency,
'status' => $player->status,
'locale' => $request->lotteryLocale(),
'last_login_at' => $player->last_login_at?->toIso8601String(),
'created_at' => $player->created_at?->toIso8601String(),
]);
}
}