v1.0.31: 股票代码与是否上市联动 - 表单非上市(否/空)禁用股票代码输入并提交清空(前后端双保险)+完整度引擎条件字段(stock_code仅在is_listed=1时参与统计,非上市不要求补全股票代码)+已重算回填

This commit is contained in:
nanguaboss
2026-08-09 21:55:13 +08:00
parent 13e7b2180e
commit 07dd4670f5
5 changed files with 58 additions and 15 deletions
+35 -12
View File
@@ -24,7 +24,8 @@ const COMPLETENESS_LAYERS = [
'important' => ['address', 'country'],
'optional' => ['registration_number', 'legal_form', 'legal_representative', 'business_scope',
'established_date', 'registered_capital', 'industry_subdivision',
'latest_employee_count', 'latest_annual_revenue', 'is_listed', 'stock_code', 'website'],
'latest_employee_count', 'latest_annual_revenue', 'is_listed', 'website'],
'conditional' => ['stock_code' => ['layer' => 'optional', 'when' => ['is_listed' => '1']]], // 股票代码仅在“是否上市=是”时参与完整度
'virtual' => [],
],
'social_accounts' => [
@@ -93,8 +94,6 @@ function completenessCalc($table, $row)
$result = [];
$missing = ['core' => [], 'important' => [], 'optional' => []];
$totalAll = 0;
$filledAll = 0;
foreach (['core', 'important', 'optional'] as $layer) {
$total = count($layers[$layer]);
@@ -118,15 +117,39 @@ function completenessCalc($table, $row)
$filled++;
}
}
$rate = $total > 0 ? round($filled / $total * 100, 1) : 100;
$result[$layer] = [
'filled' => $filled,
'total' => $total,
'rate' => $rate,
'passed' => $rate >= COMPLETENESS_THRESHOLDS[$layer],
];
$totalAll += $total;
$filledAll += $filled;
$result[$layer] = ['filled' => $filled, 'total' => $total, 'rate' => 0, 'passed' => false];
}
// 条件字段:满足条件才计入完整度(如 stock_code 仅在 is_listed=1 时统计)
foreach (($layers['conditional'] ?? []) as $cf => $cond) {
$layer = $cond['layer'] ?? 'optional';
$match = true;
foreach (($cond['when'] ?? []) as $wf => $wv) {
if ((string)($row[$wf] ?? '') !== (string)$wv) {
$match = false;
break;
}
}
if (!$match) {
continue;
}
$result[$layer]['total']++;
if (completenessIsMissing($row[$cf] ?? null)) {
$missing[$layer][] = $cf;
} else {
$result[$layer]['filled']++;
}
}
// 条件字段处理完后重算各层 rate/passed 与整体
$totalAll = 0;
$filledAll = 0;
foreach (['core', 'important', 'optional'] as $layer) {
$rate = $result[$layer]['total'] > 0 ? round($result[$layer]['filled'] / $result[$layer]['total'] * 100, 1) : 100;
$result[$layer]['rate'] = $rate;
$result[$layer]['passed'] = $rate >= COMPLETENESS_THRESHOLDS[$layer];
$totalAll += $result[$layer]['total'];
$filledAll += $result[$layer]['filled'];
}
$overall = $totalAll > 0 ? round($filledAll / $totalAll * 100, 1) : 100;