$channelName, 'channel_type' => trim($_POST['channel_type'] ?? '') ?: null, 'contact_person' => trim($_POST['contact_person'] ?? '') ?: null, 'contact_phone' => trim($_POST['contact_phone'] ?? '') ?: null, 'contact_email' => trim($_POST['contact_email'] ?? '') ?: null, 'remark' => trim($_POST['remark'] ?? '') ?: null, ]; $score = (float)($_POST['efficiency_score'] ?? 0); $fields['efficiency_score'] = max(0, min(100, $score)); $pdo = DB::getInstance()->getPdo(); if ($id > 0) { $check = $pdo->prepare("SELECT * FROM channels WHERE id = ?"); $check->execute([$id]); $old = $check->fetch(); if (!$old) { Response::error('渠道不存在'); } [$sets, $params] = buildUpdate($fields); $params[] = $id; $pdo->prepare("UPDATE channels SET $sets WHERE id = ?")->execute($params); logCurrent('update', 'channel', 'channels', $id, ['before' => $old, 'after' => $fields]); Response::success(['id' => $id], '更新成功'); } [$sql, $params] = buildInsert($fields); $pdo->prepare("INSERT INTO channels $sql")->execute($params); $newId = (int)$pdo->lastInsertId(); logCurrent('add', 'channel', 'channels', $newId, $fields); Response::success(['id' => $newId], '新增成功');