fix(admin): platform/users SELECT uid not id, UPDATE WHERE user not user_id

This commit is contained in:
ZhenYi 2026-04-22 20:52:39 +08:00
parent 0a02e14bda
commit 4d4a0dc886

View File

@ -79,20 +79,20 @@ export async function PATCH(req: NextRequest) {
// Get user ids from uids
const uidPlaceholders = ids.map((_, i) => `$${i + 1}`).join(", ");
const uidResult = await query<{ id: number }>(
`SELECT id FROM "user" WHERE uid IN (${uidPlaceholders})`,
const uidResult = await query<{ uid: string }>(
`SELECT uid FROM "user" WHERE uid IN (${uidPlaceholders})`,
ids
);
const userIds = uidResult.rows.map((r) => r.id);
const uids = uidResult.rows.map((r) => r.uid);
if (!userIds.length) {
if (!uids.length) {
return NextResponse.json({ error: "未找到匹配的用户" }, { status: 404 });
}
const idPlaceholders = userIds.map((_, i) => `$${i + 1}`).join(", ");
const uidPlaceholders2 = uids.map((_, i) => `$${i + 1}`).join(", ");
await query(
`UPDATE user_password SET is_active = $${userIds.length + 1}, updated_at = NOW() WHERE user_id IN (${idPlaceholders})`,
[...userIds, isActive]
`UPDATE user_password SET is_active = $${uids.length + 1}, updated_at = NOW() WHERE "user" IN (${uidPlaceholders2})`,
[...uids, isActive]
);
const adminUserId = parseInt(req.headers.get("x-admin-user-id") || "0", 10);
@ -102,13 +102,13 @@ export async function PATCH(req: NextRequest) {
username: adminUsername,
action: "update",
resource: "user_batch_status",
resourceId: `batch(${userIds.length})`,
requestParams: { uidCount: ids.length, userIdCount: userIds.length, action },
resourceId: `batch(${uids.length})`,
requestParams: { uidCount: ids.length, userIdCount: uids.length, action },
ipAddress: req.headers.get("x-forwarded-for") || undefined,
userAgent: req.headers.get("user-agent") || undefined,
});
return NextResponse.json({ success: true, updated: userIds.length });
return NextResponse.json({ success: true, updated: uids.length });
} catch (e) {
console.error("Batch update user status error:", e);
return NextResponse.json({ error: "服务器错误" }, { status: 500 });