feat: 增强后台设置校验、代理权限控制与财务审计能力

This commit is contained in:
2026-06-09 13:44:08 +08:00
parent 8d5d7f5b17
commit 41b964a606
25 changed files with 894 additions and 49 deletions

View File

@@ -520,6 +520,15 @@ final class SettlementCenterLedgerService
array_values($creditById),
), static fn (int $id): bool => $id > 0)),
);
$creditBillRefs = $this->settlementBillsByIds(
$admin,
array_values(array_filter(array_map(
static fn (object $row): int => (string) ($row->ref_type ?? '') === 'settlement_bill'
? (int) ($row->ref_id ?? 0)
: 0,
array_values($creditById),
), static fn (int $id): bool => $id > 0)),
);
$paymentById = [];
if ($paymentIds !== []) {
@@ -556,7 +565,10 @@ final class SettlementCenterLedgerService
if ($kind === 'credit' && isset($creditById[$id])) {
$row = $creditById[$id];
$pid = (int) $row->player_id;
$items[] = $this->formatCreditEntry($row, $playerBills[$pid] ?? null, $ticketRefs);
$bill = (string) ($row->ref_type ?? '') === 'settlement_bill'
? ($creditBillRefs[(int) ($row->ref_id ?? 0)] ?? null)
: ($playerBills[$pid] ?? null);
$items[] = $this->formatCreditEntry($row, $bill, $ticketRefs);
} elseif ($kind === 'payment' && isset($paymentById[$id])) {
$items[] = $this->formatPaymentEntry($paymentById[$id]);
} elseif ($kind === 'adjustment' && isset($adjustmentById[$id])) {
@@ -569,6 +581,40 @@ final class SettlementCenterLedgerService
return $items;
}
/**
* @param list<int> $ids
* @return array<int, object>
*/
private function settlementBillsByIds(AdminUser $admin, array $ids): array
{
$ids = array_values(array_unique(array_filter($ids, static fn (int $id): bool => $id > 0)));
if ($ids === []) {
return [];
}
$query = DB::table('settlement_bills as sb')
->whereIn('sb.id', $ids)
->select([
'sb.id',
'sb.owner_id as player_id',
'sb.status',
'sb.bill_type',
'sb.net_amount',
'sb.unpaid_amount',
'sb.paid_amount',
'sb.settlement_period_id',
]);
AdminAgentSettlementScope::applySubtreeToBillsQuery($query, $admin, 'sb');
$map = [];
foreach ($query->get() as $bill) {
$map[(int) $bill->id] = $bill;
}
return $map;
}
/**
* @return array{0: Carbon|null, 1: Carbon|null}
*/
@@ -1273,6 +1319,8 @@ final class SettlementCenterLedgerService
private function formatPaymentEntry(object $row): array
{
$amount = (int) $row->amount;
$method = trim((string) ($row->method ?? ''));
$methodLabel = $method !== '' && ! ctype_digit($method) ? ' · '.$method : '';
return array_merge(
$this->baseRow(
@@ -1289,7 +1337,7 @@ final class SettlementCenterLedgerService
billStatus: (string) ($row->bill_status ?? ''),
billType: (string) ($row->bill_type ?? ''),
billUnpaid: isset($row->unpaid_amount) ? (int) $row->unpaid_amount : null,
refLabel: 'bill#'.$row->settlement_bill_id.($row->method ? ' · '.$row->method : ''),
refLabel: 'bill#'.$row->settlement_bill_id.$methodLabel,
),
$this->partyFieldsFromRow($row),
);