41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|
/**
|
|
* 删除用户接口 POST /api/system/user_delete.php
|
|
* 入参:id(或 ids 逗号分隔批量)
|
|
* 保护:不允许删除内置管理员(id=1)
|
|
*/
|
|
require_once __DIR__ . '/../common/db.php';
|
|
require_once __DIR__ . '/../common/response.php';
|
|
require_once __DIR__ . '/../common/auth.php';
|
|
require_once __DIR__ . '/../common/logger.php';
|
|
|
|
checkAjax();
|
|
checkPermission('system');
|
|
|
|
$id = (int)($_POST['id'] ?? 0);
|
|
$ids = trim($_POST['ids'] ?? '');
|
|
$idList = [];
|
|
if ($id > 0) $idList[] = $id;
|
|
if ($ids !== '') {
|
|
foreach (explode(',', $ids) as $v) {
|
|
$v = (int)trim($v);
|
|
if ($v > 0) $idList[] = $v;
|
|
}
|
|
}
|
|
$idList = array_unique($idList);
|
|
if (!$idList) {
|
|
Response::error('参数错误', 400);
|
|
}
|
|
if (in_array(1, $idList, true)) {
|
|
Response::error('不允许删除内置管理员账号', 400);
|
|
}
|
|
|
|
$pdo = DB::getInstance()->getPdo();
|
|
$in = implode(',', array_fill(0, count($idList), '?'));
|
|
$stmt = $pdo->prepare("DELETE FROM system_users WHERE id IN ($in)");
|
|
$stmt->execute($idList);
|
|
$affected = $stmt->rowCount();
|
|
|
|
logCurrent('delete', 'system', 'system_users', null, ['ids' => $idList]);
|
|
Response::success(['affected' => $affected], "已删除 $affected 个用户");
|