feat: 添加房源审核功能及定时审核任务

This commit is contained in:
Cuishibing
2026-03-24 22:54:24 +08:00
parent 9998fb8649
commit 1b6e7fa886
6 changed files with 72 additions and 6 deletions

View File

@@ -10,10 +10,11 @@ export async function GET(
const { id } = await params;
connection = await pool.getConnection();
const [rows] = await connection.query<any[]>('SELECT * FROM houses WHERE id = ?', [id]);
const [rows] = await connection.query<any[]>("SELECT * FROM houses WHERE id = ? AND status = 'approved'", [id]);
if (rows.length === 0) {
return NextResponse.json({ error: '房屋不存在' }, { status: 404 });
connection.release();
return NextResponse.json({ error: '房屋不存在或待审核' }, { status: 404 });
}
const row = rows[0];
@@ -30,6 +31,7 @@ export async function GET(
createdAt: row.created_at
};
connection.release();
return NextResponse.json({ house });
} catch (error) {
console.error('Get house error:', error);
@@ -75,7 +77,7 @@ export async function PUT(
const { title, description, price, district, address, phone, images } = body;
await connection.query(
'UPDATE houses SET title = ?, description = ?, price = ?, district = ?, address = ?, phone = ?, images = ? WHERE id = ?',
'UPDATE houses SET title = ?, description = ?, price = ?, district = ?, address = ?, phone = ?, images = ?, status = ?, reject_reason = NULL WHERE id = ?',
[
title || houses[0].title,
description ?? houses[0].description,
@@ -84,6 +86,7 @@ export async function PUT(
address || houses[0].address,
phone || houses[0].phone,
images ? JSON.stringify(images) : houses[0].images,
'pending',
id
]
);
@@ -100,6 +103,8 @@ export async function PUT(
address: row.address,
phone: row.phone,
images: row.images ? JSON.parse(row.images) : [],
status: row.status,
reject_reason: row.reject_reason,
createdAt: row.created_at
};