This commit is contained in:
nanguaboss
2026-08-03 00:07:01 +08:00
commit 71c6e8d9c1
112 changed files with 7815 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
<?php
/**
* 需求编辑接口 POST /api/need/update.php
* 入参:id + 白名单字段(可含 is_valid 作废/恢复)
*/
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('need');
$id = (int)($_POST['id'] ?? 0);
if ($id <= 0) {
Response::error('参数错误', 400);
}
// is_valid 允许单独传
$data = extractFields(NEED_FIELDS);
if (isset($_POST['is_valid']) && $_POST['is_valid'] !== '') {
$data['is_valid'] = (int)$_POST['is_valid'] ? 1 : 0;
}
if (empty($data)) {
Response::error('没有需要更新的字段', 400);
}
$pdo = DB::getInstance()->getPdo();
$check = $pdo->prepare("SELECT * FROM company_needs WHERE id = ?");
$check->execute([$id]);
$old = $check->fetch();
if (!$old) {
Response::error('需求不存在');
}
[$sets, $params] = buildUpdate($data);
$params[] = $id;
$pdo->prepare("UPDATE company_needs SET $sets WHERE id = ?")->execute($params);
logCurrent('update', 'need', 'company_needs', $id, ['before' => $old, 'after' => $data]);
Response::success(null, '更新成功');