- 在多个控制器中引入 agent_node_id,以支持基于代理节点的权限和数据过滤。 - 更新 AdminRole 和 AdminUser 模型,新增角色范围和代理节点相关功能,提升角色管理的灵活性。 - 在请求验证中添加 agent_node_id 字段,确保 API 接口支持代理节点的相关操作。 - 优化 LotterySettings 服务,支持批量写入设置,提升配置管理的效率。 - 更新仪表板和报告服务,增强数据统计功能,确保管理员能够获取更全面的统计信息。
46 lines
1.6 KiB
PHP
46 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Support;
|
|
|
|
use App\Models\Player;
|
|
use App\Models\PlayerWallet;
|
|
|
|
/** 玩家 API 统一 JSON 形状(列表行 / 详情)。 */
|
|
final class PlayerApiPresenter
|
|
{
|
|
/** @return array<string, mixed> */
|
|
public static function listItem(Player $player): array
|
|
{
|
|
$wallets = $player->relationLoaded('wallets')
|
|
? $player->wallets
|
|
: $player->wallets()->get();
|
|
|
|
$walletRows = $wallets->map(static fn (PlayerWallet $w): array => [
|
|
'wallet_type' => $w->wallet_type,
|
|
'currency_code' => $w->currency_code,
|
|
'balance' => (int) $w->balance,
|
|
'frozen_balance' => (int) $w->frozen_balance,
|
|
'available_balance' => max(0, (int) $w->balance - (int) $w->frozen_balance),
|
|
'status' => (int) $w->status,
|
|
])->values()->all();
|
|
|
|
$agent = $player->relationLoaded('agentNode')
|
|
? $player->agentNode
|
|
: ($player->agent_node_id ? $player->agentNode()->first() : null);
|
|
|
|
return [
|
|
'id' => (int) $player->id,
|
|
...AgentNodeApiPresenter::embed($agent),
|
|
'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,
|
|
'last_login_at' => $player->last_login_at?->toIso8601String(),
|
|
'created_at' => $player->created_at?->toIso8601String(),
|
|
'wallets' => $walletRows,
|
|
];
|
|
}
|
|
}
|