Files
jinniu-daikuan/app/views/pages/query_totals.php
T
美术师andmultica-agent e61129500c HEL-335 全站按定版霜曜样板原样重构界面
- 新增 assets:fusion.css(样板全量 token/组件/动效)、fusion.js(主题/抽屉/弹层/开关/按住确认/计算器引擎/三态全选/toast)、日夜 Logo
- pageHeader/pageFooter 重写为样板侧栏骨架:固定侧栏导航、底部账户区、日间/夜间 token 切换、导入弹层、详情抽屉容器
- 新增工作台(风险入口卡+今日待办+快捷入口)、任务中心(四组分段+行内处理)、档案库目录管理三栏视图
- 档案列表恢复样板分段标签/KPI 卡/筛选条/批量条/行点击抽屉
- 档案详情页 + 右侧抽屉(概要/还款计划/附件三标签)按样板实现,保留全部真实绑定
- 新建/编辑档案改造为五步向导(字段与联动 JS 全量保留)
- 登录页左右布局、用户管理、个人设置、删除审批、统计查询四口径页签、便捷查询、两个计算器全部按样板重构
- 页面 view 抽取至 app/views/pages/,index.php 保留全部业务逻辑与路由
- 业务功能零删减:表单字段、权限、审批闭环、导入导出、计算口径均不变

Co-authored-by: multica-agent <github@multica.ai>
2026-09-01 13:11:10 +08:00

152 lines
8.2 KiB
PHP

<?php
requireLogin();
$scope = (string)($_GET['scope'] ?? 'all_bank');
$inst = trim((string)($_GET['inst'] ?? ''));
$allowedScopes = ['all_bank', 'all_guar', 'bank_inst', 'guar_inst'];
if (!in_array($scope, $allowedScopes, true)) {
$scope = 'all_bank';
}
$rowsAll = $pdo->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); ?>
<div class="page-head">
<div>
<h1 class="page-title">统计查询</h1>
<div class="page-sub">便捷统计 · 四个口径</div>
</div>
</div>
<div class="seg" role="tablist" aria-label="统计口径" style="margin-bottom:20px;">
<a role="tab" href="index.php?action=query_totals" data-active>总金额</a>
<a role="tab" href="index.php?action=query_payable_interest">应付本息</a>
<a role="tab" href="index.php?action=query_external_guarantee">对外担保</a>
<a role="tab" href="index.php?action=repayment_history">历史还款</a>
</div>
<form method="get" action="index.php" class="filter-bar" style="margin-top:0;">
<input type="hidden" name="action" value="query_totals">
<select name="scope" id="qt_scope" aria-label="统计范围">
<option value="all_bank" <?= $scope === 'all_bank' ? 'selected' : '' ?>>履行中及逾期中 — 全部银行贷款</option>
<option value="all_guar" <?= $scope === 'all_guar' ? 'selected' : '' ?>>履行中及逾期中 — 全部对外担保</option>
<option value="bank_inst" <?= $scope === 'bank_inst' ? 'selected' : '' ?>>履行中及逾期中 — 指定机构的银行贷款</option>
<option value="guar_inst" <?= $scope === 'guar_inst' ? 'selected' : '' ?>>履行中及逾期中 — 指定机构的对外担保</option>
</select>
<div class="search" id="qt_inst_wrap" style="min-width:240px;<?= ($scope === 'bank_inst' || $scope === 'guar_inst') ? '' : 'opacity:.45' ?>">
<span aria-hidden="true">⌕</span>
<input name="inst" id="qt_inst" list="qt_inst_list" value="<?= e($inst) ?>" placeholder="机构名称(指定机构时必填)" aria-label="机构名称">
</div>
<datalist id="qt_inst_list">
<?php foreach ($loanInstitutions as $li): ?><option value="<?= e($li) ?>"><?php endforeach; ?>
</datalist>
<button type="submit" class="btn btn--plain">查询</button>
<span class="filter-note">剩余额度含分期已还与手动归还本金</span>
</form>
<script>
(function(){
var sel=document.getElementById('qt_scope');
var wrap=document.getElementById('qt_inst_wrap');
function sync(){if(!sel||!wrap)return;var need=sel.value==='bank_inst'||sel.value==='guar_inst';wrap.style.opacity=need?'1':'.45';}
if(sel){sel.addEventListener('change',sync);}sync();
})();
</script>
<div class="stats">
<div class="stat"><div class="stat-label">在保笔数</div><div class="stat-value num"><?= (int)($tot['count'] ?? 0) ?><small>笔</small></div><div class="stat-foot"><?= e($scopeFoot) ?></div></div>
<div class="stat"><div class="stat-label">授信合计</div><div class="stat-value num"><?= e(fmtWan((float)($tot['sum_credit'] ?? 0))) ?></div><div class="stat-foot">不含已结清</div></div>
<div class="stat stat--gold"><div class="stat-label">剩余额度合计</div><div class="stat-value num"><?= e(fmtWan((float)($tot['sum_remaining'] ?? 0))) ?></div><div class="stat-foot">剩余额度联动实时更新</div></div>
<div class="stat stat--alert"><div class="stat-label">逾期中</div><div class="stat-value num"><?= $overdueCount ?><small>笔</small></div><div class="stat-foot">已计逾期利息</div></div>
</div>
<div class="section-title" style="margin-top:0;">按机构统计</div>
<div class="table-card">
<table>
<thead><tr><th>贷款机构</th><th class="cell-right">在保笔数</th><th class="cell-right">授信合计</th><th class="cell-right">剩余合计</th><th class="cell-right">当期应付利息</th></tr></thead>
<tbody>
<?php $qi = 0; foreach ($byInst as $instName => $g): ?>
<tr class="stagger-in" style="animation-delay:<?= min($qi, 8) * 45 ?>ms; cursor:default;">
<td><?= e($instName) ?></td>
<td class="cell-right num"><?= $g['n'] ?></td>
<td class="cell-right num"><?= e(fmtMoney($g['credit'])) ?></td>
<td class="cell-right num cell-remaining"><?= e(fmtMoney($g['remaining'])) ?></td>
<td class="cell-right num"><?= $isBankScope ? e(fmtMoney(round($g['interest'], 2))) : '—' ?></td>
</tr>
<?php $qi++; endforeach; ?>
</tbody>
</table>
<?php if (!$byInst): ?>
<div style="padding:16px;"><div class="empty">该统计范围内暂无履行中或逾期中的档案</div></div>
<?php endif; ?>
</div>
<?php pageFooter(); exit;