['label' => '人员', 'name' => 'full_name'], 'companies' => ['label' => '企业', 'name' => 'display_name'], 'social_accounts' => ['label' => '联系方式', 'name' => 'account_id'], 'media' => ['label' => '媒体', 'name' => null], // media 需 JOIN social_accounts 取名 ]; $pdo = DB::getInstance()->getPdo(); $all = []; foreach ($tableMap as $t => $cfg) { if ($table !== '' && $table !== $t) { continue; } if ($t === 'media') { $rows = $pdo->query( "SELECT m.social_account_id AS id, sa.account_id AS name, m.updated_at AS updated_at FROM media_commercial_attributes m LEFT JOIN social_accounts sa ON sa.id = m.social_account_id WHERE m.is_incomplete = 1" )->fetchAll(); } else { $rows = $pdo->query("SELECT id, {$cfg['name']} AS name, updated_at FROM `$t` WHERE is_incomplete = 1")->fetchAll(); } foreach ($rows as $r) { $info = completenessInfo($pdo, $t, (int)$r['id']); if (!$info) { continue; } if ($level !== '' && $info['level'] !== $level) { continue; } // 缺失字段按优先级:核心 → 重要 → 非必要 $missingFields = array_merge($info['missing']['core'], $info['missing']['important'], $info['missing']['optional']); $all[] = [ 'table' => $t, 'table_label' => $cfg['label'], 'id' => (int)$r['id'], 'name' => $r['name'] ?: ('#' . $r['id']), 'overall' => $info['overall'], 'level' => $info['level'], 'layer_rates' => [ 'core' => $info['layers']['core']['rate'], 'important' => $info['layers']['important']['rate'], 'optional' => $info['layers']['optional']['rate'], ], 'missing_fields' => array_map(function ($f) { return COMPLETENESS_LABELS[$f] ?? $f; }, $missingFields), 'updated_at' => $r['updated_at'] ?? null, ]; } } // 排序:整体完整度升序(最残缺在前),同分按更新时间倒序 usort($all, function ($a, $b) { if ($a['overall'] !== $b['overall']) { return $a['overall'] <=> $b['overall']; } return strcmp($b['updated_at'] ?? '', $a['updated_at'] ?? ''); }); if ($keyword !== '') { $all = array_values(array_filter($all, function ($r) use ($keyword) { return mb_strpos($r['name'], $keyword) !== false; })); } $total = count($all); $offset = ($page - 1) * $limit; $list = array_slice($all, $offset, $limit); Response::success(['list' => $list, 'total' => $total, 'page' => $page, 'limit' => $limit]);