getPdo(); $fields = [ 'channel_type' => $channelType, 'source_detail' => trim($_POST['source_detail'] ?? '') !== '' ? trim($_POST['source_detail']) : null, 'industry' => trim($_POST['industry'] ?? '') !== '' ? trim($_POST['industry']) : null, 'start_date' => trim($_POST['start_date'] ?? '') !== '' ? $_POST['start_date'] : null, 'end_date' => trim($_POST['end_date'] ?? '') !== '' ? $_POST['end_date'] : null, 'remark' => trim($_POST['remark'] ?? '') !== '' ? trim($_POST['remark']) : null, 'status' => $status, ]; if ($id > 0) { $check = $pdo->prepare("SELECT id FROM channel_plans WHERE id = ? AND is_active = 1"); $check->execute([$id]); if (!$check->fetch()) { Response::error('计划不存在'); } [$sets, $params] = buildUpdate($fields); $params[] = $id; $pdo->prepare("UPDATE channel_plans SET $sets WHERE id = ?")->execute($params); logCurrent('update', 'channel_plan', 'channel_plans', $id, $fields); Response::success(null, '更新成功'); } [$sql, $params] = buildInsert($fields); $pdo->prepare("INSERT INTO channel_plans $sql")->execute($params); $newId = (int)$pdo->lastInsertId(); logCurrent('add', 'channel_plan', 'channel_plans', $newId, $fields); Response::success(['id' => $newId], '新增成功');