Files
superlink/api/fragment/soft_detail.php
T

59 lines
2.1 KiB
PHP

<?php
/**
* 软碎片详情接口 GET /api/fragment/soft_detail.php?table=persons&id=1
* 返回:{ table, table_label, id, name, overall, level, layers, missing_core, missing_important,
* missing_optional, missing_labels, row }
*/
require_once __DIR__ . '/../common/Api.php';
$pdo = Api::boot(['module' => '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;
}
$label = function ($f) { return ['key' => $f, 'label' => COMPLETENESS_LABELS[$f] ?? $f]; };
Response::success([
'table' => $table,
'table_label' => $tableLabels[$table],
'id' => $id,
'name' => $name ?: ('#' . $id),
'overall' => $info['overall'],
'level' => $info['level'],
'layers' => $info['layers'],
'missing_core' => array_map($label, $info['missing']['core']),
'missing_important' => array_map($label, $info['missing']['important']),
'missing_optional' => array_map($label, $info['missing']['optional']),
'missing_labels' => array_map(function ($f) { return COMPLETENESS_LABELS[$f] ?? $f; },
array_merge($info['missing']['core'], $info['missing']['important'], $info['missing']['optional'])),
'row' => $info['row'],
]);