getPdo(); $chk = $pdo->prepare("SELECT COUNT(*) FROM companies WHERE id = ?"); $chk->execute([$companyId]); if ((int)$chk->fetchColumn() === 0) { Response::error('企业不存在'); } // 唯一性校验:社媒账号ID(同平台)/ 手机 / 邮箱 / 主页链接,收集全部重复 $dups = checkSingleAccountDuplicate($pdo, $platform, $accountId, $_POST['profile_url'] ?? ''); if (!empty($dups)) Response::duplicates($dups); $ins = $pdo->prepare( "INSERT INTO social_accounts (owner_type, owner_id, platform, account_id, profile_url, remark, is_primary, is_defult, is_active) VALUES ('company', ?, ?, ?, ?, ?, 0, ?, ?)" ); $ins->execute([ $companyId, $platform, $accountId, strOrNull($_POST['profile_url'] ?? null), strOrNull($_POST['remark'] ?? null), !empty($_POST['is_defult']) ? 1 : 0, isset($_POST['is_active']) && (int)$_POST['is_active'] === 0 ? 0 : 1, ]); $newId = (int)$pdo->lastInsertId(); // 完整度检查:新官媒账号 + 所属企业全部联系方式 updateIncomplete($pdo, 'social_accounts', $newId); updateAccountsIncomplete($pdo, 'company', $companyId); logCurrent('add', 'official_media', 'social_accounts', $newId, ['company_id' => $companyId, 'platform' => $platform, 'account_id' => $accountId]); Response::success(['id' => $newId], '新增成功');