feat: enhance agent settlement features and improve data access controls
- Added new section in AGENTS.md detailing learned workspace facts for better understanding of settlement processes. - Updated AgentNodeDestroyController to remove unnecessary checks for admin users. - Enhanced AgentSettlement controllers to assert permissions for finance adjustments and bill operations. - Improved query scopes in AgentSettlement services to ensure proper data access based on admin roles. - Refactored methods in SettlementPartyEnrichment for better bill row enrichment and data handling. - Introduced new methods in AdminAgentSettlementScope for managing agent node visibility and finance adjustments.
This commit is contained in:
@@ -81,7 +81,7 @@ final class AgentSettlementBillIndexController extends Controller
|
||||
$items = collect($paginator->items());
|
||||
|
||||
return ApiResponse::success([
|
||||
'items' => $this->enrichBillRows($items),
|
||||
'items' => $this->partyEnrichment->enrichBillRows($items),
|
||||
'total' => $paginator->total(),
|
||||
'page' => $paginator->currentPage(),
|
||||
'per_page' => $paginator->perPage(),
|
||||
@@ -138,112 +138,4 @@ final class AgentSettlementBillIndexController extends Controller
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection<int, object> $items
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
private function enrichBillRows(Collection $items): array
|
||||
{
|
||||
if ($items->isEmpty()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$playerIds = [];
|
||||
$agentIds = [];
|
||||
foreach ($items as $row) {
|
||||
if ((string) $row->owner_type === 'player') {
|
||||
$playerIds[] = (int) $row->owner_id;
|
||||
} elseif ((string) $row->owner_type === 'agent') {
|
||||
$agentIds[] = (int) $row->owner_id;
|
||||
}
|
||||
if ((string) $row->counterparty_type === 'agent' && (int) $row->counterparty_id > 0) {
|
||||
$agentIds[] = (int) $row->counterparty_id;
|
||||
}
|
||||
}
|
||||
|
||||
$players = $playerIds !== []
|
||||
? DB::table('players')
|
||||
->whereIn('id', array_unique($playerIds))
|
||||
->select(['id', 'username', 'site_player_id', 'agent_node_id', 'funding_mode', 'auth_source'])
|
||||
->get()
|
||||
->keyBy('id')
|
||||
: collect();
|
||||
|
||||
foreach ($players as $player) {
|
||||
$aid = (int) ($player->agent_node_id ?? 0);
|
||||
if ($aid > 0) {
|
||||
$agentIds[] = $aid;
|
||||
}
|
||||
}
|
||||
|
||||
$agents = $this->partyEnrichment->loadAgents($agentIds);
|
||||
|
||||
$out = [];
|
||||
foreach ($items as $row) {
|
||||
$item = (array) $row;
|
||||
$ownerType = (string) $row->owner_type;
|
||||
$counterType = (string) $row->counterparty_type;
|
||||
$counterId = (int) $row->counterparty_id;
|
||||
|
||||
$item['owner_label'] = $this->legacyOwnerLabel($ownerType, (int) $row->owner_id, $players, $agents);
|
||||
$item['counterparty_label'] = $this->partyEnrichment->formatCounterpartyLabel($counterType, $counterId, $agents);
|
||||
|
||||
$item['player_username'] = null;
|
||||
$item['player_site_player_id'] = null;
|
||||
$item['player_id_display'] = null;
|
||||
$item['direct_agent_label'] = null;
|
||||
$item['superior_agent_label'] = null;
|
||||
$item['owner_party_label'] = null;
|
||||
|
||||
if ($ownerType === 'player') {
|
||||
$player = $players->get((int) $row->owner_id);
|
||||
$item['player_username'] = $this->partyEnrichment->formatPlayerUsername($player);
|
||||
$item['player_site_player_id'] = $this->partyEnrichment->formatPlayerSiteId($player);
|
||||
$item['player_id_display'] = (int) $row->owner_id;
|
||||
$item['owner_funding_mode'] = $player !== null ? (string) ($player->funding_mode ?? '') : null;
|
||||
$item['owner_auth_source'] = $player !== null ? $player->auth_source : null;
|
||||
|
||||
$directId = $counterType === 'agent' ? $counterId : (int) ($player->agent_node_id ?? 0);
|
||||
$line = $this->partyEnrichment->agentLineLabels($directId > 0 ? $directId : null, $agents);
|
||||
$item['direct_agent_label'] = $line['direct_agent_label'];
|
||||
$item['superior_agent_label'] = $line['parent_agent_label'];
|
||||
} elseif ($ownerType === 'agent') {
|
||||
$ownerAgentId = (int) $row->owner_id;
|
||||
$item['owner_party_label'] = $this->partyEnrichment->formatAgent($agents->get($ownerAgentId), $ownerAgentId);
|
||||
$item['superior_agent_label'] = $counterType === 'platform'
|
||||
? 'platform'
|
||||
: $this->partyEnrichment->formatCounterpartyLabel($counterType, $counterId, $agents);
|
||||
}
|
||||
|
||||
$out[] = $item;
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection<int, object> $players
|
||||
* @param Collection<int, object> $agents
|
||||
*/
|
||||
private function legacyOwnerLabel(
|
||||
string $type,
|
||||
int $id,
|
||||
Collection $players,
|
||||
Collection $agents,
|
||||
): string {
|
||||
if ($type === 'player') {
|
||||
$player = $players->get($id);
|
||||
|
||||
return $player !== null
|
||||
? (string) ($player->username ?: $player->site_player_id ?: "player#{$id}")
|
||||
: "player#{$id}";
|
||||
}
|
||||
|
||||
if ($type === 'agent') {
|
||||
return $this->partyEnrichment->formatAgent($agents->get($id), $id);
|
||||
}
|
||||
|
||||
return "{$type}#{$id}";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user