getPdo(); $check = $pdo->prepare("SELECT * FROM social_accounts WHERE id = ?"); $check->execute([$id]); $old = $check->fetch(); if (!$old) { Response::error('媒体账号不存在'); } $data = extractFields(MEDIA_FIELDS); unset($data['owner_type'], $data['owner_id']); // 归属关系不允许改 // 唯一性校验(排除自身):社媒账号ID(同平台)/ 手机 / 邮箱 / 主页链接 if (isset($_POST['platform']) || isset($_POST['account_id']) || isset($_POST['profile_url'])) { $dup = checkSingleAccountDuplicate( $pdo, $_POST['platform'] ?? ($old['platform'] ?? ''), $_POST['account_id'] ?? ($old['account_id'] ?? ''), $_POST['profile_url'] ?? ($old['profile_url'] ?? ''), [$id] ); if ($dup) Response::duplicate($dup); } if (!empty($data)) { [$sets, $params] = buildUpdate($data); $params[] = $id; $pdo->prepare("UPDATE social_accounts SET $sets WHERE id = ?")->execute($params); } // 更新商业属性(存在则更新,不存在则插入) $attr = extractFields(MEDIA_ATTR_FIELDS); if (!empty($attr)) { $exists = $pdo->prepare("SELECT COUNT(*) FROM media_commercial_attributes WHERE social_account_id = ?"); $exists->execute([$id]); if ((int)$exists->fetchColumn() > 0) { [$attrSets, $attrParams] = buildUpdate($attr); $attrParams[] = $id; $pdo->prepare("UPDATE media_commercial_attributes SET $attrSets WHERE social_account_id = ?")->execute($attrParams); } else { $attr['social_account_id'] = $id; [$attrSql, $attrParams] = buildInsert($attr); $pdo->prepare("INSERT INTO media_commercial_attributes $attrSql")->execute($attrParams); } } // 完整度检查:媒体账号 + 商业属性 updateMediaIncomplete($pdo, $id); logCurrent('update', 'media', 'social_accounts', $id, ['before' => $old, 'after' => $data, 'attr' => $attr]); Response::success(null, '更新成功');