v1.0.19: 修复人员编辑入口缺失(person.js addPerson/editPerson) + 渠道明细数量字段名(analysis.php cnt) + CDP全量验证43项PASS
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* 渠道新增计划保存接口 POST /api/channel/plan_save.php
|
||||
* 入参:id(可选,编辑时传)/ channel_type(渠道类别=source_channel 枚举,必填)/
|
||||
* source_detail / industry / start_date / end_date / remark / status(待启动|已执行|错过)
|
||||
*/
|
||||
require_once __DIR__ . '/../common/db.php';
|
||||
require_once __DIR__ . '/../common/response.php';
|
||||
require_once __DIR__ . '/../common/auth.php';
|
||||
require_once __DIR__ . '/../common/helpers.php';
|
||||
require_once __DIR__ . '/../common/logger.php';
|
||||
|
||||
checkAjax();
|
||||
checkPermission('channel');
|
||||
|
||||
$channelType = trim($_POST['channel_type'] ?? '');
|
||||
if ($channelType === '') {
|
||||
Response::error('渠道类别(channel_type)为必填项', 400);
|
||||
}
|
||||
$status = trim($_POST['status'] ?? '待启动');
|
||||
if (!in_array($status, ['待启动', '已执行', '错过'], true)) {
|
||||
$status = '待启动';
|
||||
}
|
||||
|
||||
$id = (int)($_POST['id'] ?? 0);
|
||||
$pdo = DB::getInstance()->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], '新增成功');
|
||||
Reference in New Issue
Block a user