/** * 提现记录列表 - 当前用户的全部提现记录(供小程序「提现记录」展示) * GET ?userId=xxx */ import { NextRequest, NextResponse } from 'next/server' import { prisma } from '@/lib/prisma' export async function GET(request: NextRequest) { try { const userId = request.nextUrl.searchParams.get('userId') if (!userId) { return NextResponse.json({ success: false, message: '缺少 userId' }, { status: 400 }) } const rows = await prisma.$queryRaw< { id: string; amount: unknown; status: string; created_at: Date; processed_at: Date | null }[] >` SELECT id, amount, status, created_at, processed_at FROM withdrawals WHERE user_id = ${userId} ORDER BY created_at DESC LIMIT 100 ` const list = rows.map((r) => ({ id: r.id, amount: Number(r.amount), status: r.status, created_at: r.created_at, processed_at: r.processed_at, })) return NextResponse.json({ success: true, data: { list }, }) } catch (e) { console.error('[Withdraw records]', e) return NextResponse.json( { success: false, message: '获取提现记录失败' }, { status: 500 } ) } }