57 lines
2.1 KiB
PHP
57 lines
2.1 KiB
PHP
<?php
|
|
/**
|
|
* 软碎片详情接口 GET /api/fragment/soft_detail.php?table=persons&id=1
|
|
* 返回:{ table, id, name, score, level, missing_core, missing_important, missing_supp, threshold, row }
|
|
*/
|
|
require_once __DIR__ . '/../common/db.php';
|
|
require_once __DIR__ . '/../common/response.php';
|
|
require_once __DIR__ . '/../common/auth.php';
|
|
require_once __DIR__ . '/../common/completeness.php';
|
|
|
|
checkPermission('preliminary');
|
|
|
|
$table = trim($_REQUEST['table'] ?? '');
|
|
$id = (int)($_REQUEST['id'] ?? 0);
|
|
if (!in_array($table, ['persons', 'companies', 'social_accounts', 'media'], true) || $id <= 0) {
|
|
Response::error('参数错误', 400);
|
|
}
|
|
|
|
$pdo = DB::getInstance()->getPdo();
|
|
$info = completenessInfo($pdo, $table, $id);
|
|
if (!$info) {
|
|
Response::error('记录不存在');
|
|
}
|
|
|
|
$tableLabels = ['persons' => '人员', 'companies' => '企业', 'social_accounts' => '联系方式', 'media' => '媒体'];
|
|
$name = '';
|
|
switch ($table) {
|
|
case 'persons':
|
|
$name = $info['row']['full_name'] ?? '';
|
|
break;
|
|
case 'companies':
|
|
$name = $info['row']['display_name'] ?? '';
|
|
break;
|
|
case 'social_accounts':
|
|
$name = $info['row']['account_id'] ?? '';
|
|
break;
|
|
case 'media':
|
|
$acc = $pdo->prepare("SELECT account_id FROM social_accounts WHERE id = ?");
|
|
$acc->execute([$id]);
|
|
$name = (string)$acc->fetchColumn();
|
|
break;
|
|
}
|
|
|
|
Response::success([
|
|
'table' => $table,
|
|
'table_label' => $tableLabels[$table],
|
|
'id' => $id,
|
|
'name' => $name ?: ('#' . $id),
|
|
'score' => $info['score'],
|
|
'level' => $info['level'],
|
|
'threshold' => $info['threshold'],
|
|
'missing_core' => array_map(function ($f) { return ['key' => $f, 'label' => COMPLETENESS_LABELS[$f] ?? $f]; }, $info['missing_core']),
|
|
'missing_important' => array_map(function ($f) { return ['key' => $f, 'label' => COMPLETENESS_LABELS[$f] ?? $f]; }, $info['missing_important']),
|
|
'missing_supp' => array_map(function ($f) { return ['key' => $f, 'label' => COMPLETENESS_LABELS[$f] ?? $f]; }, $info['missing_supp']),
|
|
'row' => $info['row'],
|
|
]);
|