v1.0.10
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* 媒体数据编辑接口 POST /api/media/update.php
|
||||
* 入参:id + 白名单字段(含商业属性)
|
||||
*/
|
||||
require_once __DIR__ . '/../common/db.php';
|
||||
require_once __DIR__ . '/../common/response.php';
|
||||
require_once __DIR__ . '/../common/auth.php';
|
||||
require_once __DIR__ . '/../common/logger.php';
|
||||
require_once __DIR__ . '/../common/helpers.php';
|
||||
|
||||
checkAjax();
|
||||
checkPermission('media');
|
||||
|
||||
$id = (int)($_POST['id'] ?? 0);
|
||||
if ($id <= 0) {
|
||||
Response::error('参数错误', 400);
|
||||
}
|
||||
|
||||
$pdo = DB::getInstance()->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']); // 归属关系不允许改
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
logCurrent('update', 'media', 'social_accounts', $id, ['before' => $old, 'after' => $data, 'attr' => $attr]);
|
||||
Response::success(null, '更新成功');
|
||||
Reference in New Issue
Block a user