41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|
/**
|
|
* 企业编辑接口 POST /api/company/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('company');
|
|
|
|
$id = (int)($_POST['id'] ?? 0);
|
|
if ($id <= 0) {
|
|
Response::error('参数错误', 400);
|
|
}
|
|
|
|
$data = extractFields(COMPANY_FIELDS);
|
|
unset($data['display_name']); // 显示名称不允许通过编辑接口置空/改名,如需改名请走完整字段
|
|
if (empty($data)) {
|
|
Response::error('没有需要更新的字段', 400);
|
|
}
|
|
|
|
$pdo = DB::getInstance()->getPdo();
|
|
|
|
$check = $pdo->prepare("SELECT id, display_name FROM companies WHERE id = ?");
|
|
$check->execute([$id]);
|
|
$old = $check->fetch();
|
|
if (!$old) {
|
|
Response::error('企业不存在');
|
|
}
|
|
|
|
[$sets, $params] = buildUpdate($data);
|
|
$params[] = $id;
|
|
$pdo->prepare("UPDATE companies SET $sets WHERE id = ?")->execute($params);
|
|
|
|
logCurrent('update', 'company', 'companies', $id, ['before' => $old, 'after' => $data]);
|
|
Response::success(null, '更新成功');
|