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

@@ -11,7 +11,7 @@ export async function GET(request: NextRequest) {
connection = await pool.getConnection();
let sql = 'SELECT * FROM houses WHERE 1=1';
let sql = "SELECT * FROM houses WHERE status = 'approved'";
const params: any[] = [];
if (district && district !== '全部') {
@@ -42,6 +42,7 @@ export async function GET(request: NextRequest) {
createdAt: row.created_at
}));
connection.release();
return NextResponse.json({ houses });
} catch (error) {
console.error('Get houses error:', error);
@@ -65,6 +66,7 @@ export async function POST(request: NextRequest) {
const [users] = await connection.query<any[]>('SELECT username FROM users WHERE token = ?', [token]);
if (users.length === 0) {
connection.release();
return NextResponse.json({ error: '用户不存在' }, { status: 401 });
}
@@ -72,13 +74,14 @@ export async function POST(request: NextRequest) {
const { title, description, price, district, address, phone, images } = body;
if (!title || !price || !district || !address || !phone) {
connection.release();
return NextResponse.json({ error: '请填写完整信息' }, { status: 400 });
}
const id = crypto.randomUUID();
await connection.query(
'INSERT INTO houses (id, owner, title, description, price, district, address, phone, images, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
[id, users[0].username, title, description || '', Number(price), district, address, phone, JSON.stringify(images || []), new Date()]
'INSERT INTO houses (id, owner, title, description, price, district, address, phone, images, status, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
[id, users[0].username, title, description || '', Number(price), district, address, phone, JSON.stringify(images || []), 'pending', new Date()]
);
const house = {
@@ -91,9 +94,11 @@ export async function POST(request: NextRequest) {
address,
phone,
images: images || [],
status: 'pending',
createdAt: new Date()
};
connection.release();
return NextResponse.json({ success: true, house });
} catch (error) {
console.error('Create house error:', error);