query('SELECT * FROM archives ORDER BY id DESC')->fetchAll(); $financeAll = loadFinanceConfigs(); $tot = qqBuildTotalsQuery($rowsAll, $financeAll, $scope, $inst !== '' ? $inst : null); $loanInstitutions = loadLoanInstitutions(); /* 呈现层聚合:按机构分组 + 逾期笔数,过滤口径与 qqBuildTotalsQuery 完全一致 */ $isBankScope = ($scope === 'all_bank' || $scope === 'bank_inst'); $planAll = $isBankScope ? loadRepaymentPlans() : []; $instNorm = trim($inst); $byInst = []; $overdueCount = 0; foreach ($rowsAll as $a) { $aid = (int)$a['id']; $kind = normalizeArchiveKind((string)($a['archive_kind'] ?? '')); $cfg = getArchiveFinanceConfig($financeAll, $aid); if (!archiveStatusIsOngoingAggregate((string)($a['end_date'] ?? ''), $cfg)) { continue; } $rowInst = (string)($a['loan_institution'] ?? ''); if ($scope === 'all_bank' && $kind !== ARCHIVE_KIND_BANK_LOAN) { continue; } if ($scope === 'all_guar' && $kind !== ARCHIVE_KIND_EXTERNAL_GUARANTEE) { continue; } if ($scope === 'bank_inst' && ($instNorm === '' || $kind !== ARCHIVE_KIND_BANK_LOAN || $rowInst !== $instNorm)) { continue; } if ($scope === 'guar_inst' && ($instNorm === '' || $kind !== ARCHIVE_KIND_EXTERNAL_GUARANTEE || $rowInst !== $instNorm)) { continue; } $key = $rowInst !== '' ? $rowInst : '未填写机构'; if (!isset($byInst[$key])) { $byInst[$key] = ['n' => 0, 'credit' => 0.0, 'remaining' => 0.0, 'interest' => 0.0]; } $byInst[$key]['n']++; if ($a['credit_limit'] !== null && $a['credit_limit'] !== '') { $byInst[$key]['credit'] += (float)$a['credit_limit']; } if ($a['remaining_limit'] !== null && $a['remaining_limit'] !== '') { $byInst[$key]['remaining'] += (float)$a['remaining_limit']; } if (archiveStatusWithConfig((string)($a['end_date'] ?? ''), $cfg) === '逾期中') { $overdueCount++; } if ($isBankScope && $kind === ARCHIVE_KIND_BANK_LOAN) { $plans = (array)((getArchiveRepaymentPlan($planAll, $aid))['plans'] ?? []); $byInst[$key]['interest'] += calcCurrentInterest($a, $cfg, $plans); } } ksort($byInst); $scopeFoot = [ 'all_bank' => '银行贷款 · 履行中+逾期中', 'all_guar' => '对外担保 · 履行中+逾期中', 'bank_inst' => '指定机构 · 银行贷款', 'guar_inst' => '指定机构 · 对外担保', ][$scope]; /* 视觉层辅助在 index.php 尾部(本组页面 require 点之后)定义,这里做呈现级兜底 */ if (!function_exists('fmtMoney')) { function fmtMoney(?float $v): string { return $v === null ? '—' : number_format($v, 2, '.', ','); } } if (!function_exists('fmtWan')) { function fmtWan(?float $v): string { if ($v === null) { return '—'; } if (abs($v) >= 10000) { $s = rtrim(rtrim(number_format($v / 10000, 2, '.', ','), '0'), '.'); return $s . ' 万'; } return number_format($v, 2, '.', ','); } } pageHeader($me); ?>
| 贷款机构 | 在保笔数 | 授信合计 | 剩余合计 | 当期应付利息 |
|---|---|---|---|---|
| = e($instName) ?> | = $g['n'] ?> | = e(fmtMoney($g['credit'])) ?> | = e(fmtMoney($g['remaining'])) ?> | = $isBankScope ? e(fmtMoney(round($g['interest'], 2))) : '—' ?> |