getPdo(); $check = $pdo->prepare("SELECT id, display_name FROM companies WHERE id = ?"); $check->execute([$id]); $old = $check->fetch(); if (!$old) { Response::error('企业不存在'); } if (!empty($data)) { [$sets, $params] = buildUpdate($data); $params[] = $id; $pdo->prepare("UPDATE companies SET $sets WHERE id = ?")->execute($params); } // 财务信息 / 资质认证 / 联系方式(可选,整表替换) if ($hasFinancials || $hasCertifications || $hasAccounts) { $pdo->beginTransaction(); try { if ($hasFinancials) { $financials = json_decode($_POST['financials'], true); if (!is_array($financials)) { $pdo->rollBack(); Response::error('财务信息格式错误', 400); } saveCompanyFinancials($pdo, $id, $financials); } if ($hasCertifications) { $certs = json_decode($_POST['certifications'], true); if (!is_array($certs)) { $pdo->rollBack(); Response::error('资质认证格式错误', 400); } saveCompanyCertifications($pdo, $id, $certs); } if ($hasAccounts) { $accounts = json_decode($_POST['accounts'], true); if (!is_array($accounts)) { $pdo->rollBack(); Response::error('联系方式格式错误', 400); } saveCompanyAccounts($pdo, $id, $accounts); } $pdo->commit(); } catch (Exception $e) { $pdo->rollBack(); Response::error('关联信息保存失败:' . $e->getMessage()); } } // 完整度检查:企业主表 + 其 social_accounts updateIncomplete($pdo, 'companies', $id); updateAccountsIncomplete($pdo, 'company', $id); if (!empty($data)) { logCurrent('update', 'company', 'companies', $id, ['before' => $old, 'after' => $data]); } Response::success(null, '更新成功');