feat: 增强玩家 API,新增 locale 和时间字段,更新钱包 API 以支持可用余额计算,添加错误码与多语言支持

This commit is contained in:
2026-05-09 15:05:46 +08:00
parent f1b38ef421
commit a0f86a4e36
36 changed files with 2523 additions and 34 deletions

View File

@@ -0,0 +1,55 @@
<?php
namespace App\Http\Controllers\Api\V1\Admin\Player;
use App\Http\Controllers\Controller;
use App\Models\Player;
use App\Models\PlayerWallet;
use App\Support\ApiResponse;
use Illuminate\Http\JsonResponse;
/**
* 后台:按玩家查询钱包余额(`player_wallets` 全币种)。
*
* 路由:`GET /api/v1/admin/players/{player}/wallets`
*/
final class PlayerWalletShowController extends Controller
{
public function __invoke(Player $player): JsonResponse
{
$wallets = PlayerWallet::query()
->where('player_id', $player->id)
->orderBy('wallet_type')
->orderBy('currency_code')
->get();
$rows = $wallets->map(static function (PlayerWallet $w): array {
$bal = (int) $w->balance;
$frozen = (int) $w->frozen_balance;
return [
'id' => $w->id,
'wallet_type' => $w->wallet_type,
'currency_code' => $w->currency_code,
'balance' => $bal,
'frozen_balance' => $frozen,
'available_balance' => max(0, $bal - $frozen),
'status' => (int) $w->status,
'version' => (int) $w->version,
];
})->values()->all();
return ApiResponse::success([
'player' => [
'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' => (int) $player->status,
],
'wallets' => $rows,
]);
}
}