Files
soul-yongping/next-project/app/api/withdraw/pending-confirm/route.ts
2026-02-09 14:43:35 +08:00

54 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 待确认收款列表 - 供小程序调起 wx.requestMerchantTransfer 使用
* GET ?userId=xxx 返回当前用户 status=pending_confirm 且含 package_info 的提现记录,及 mch_id、app_id
*/
import { NextRequest, NextResponse } from 'next/server'
import { prisma } from '@/lib/prisma'
import { getTransferMchAndAppId } from '@/lib/wechat-transfer'
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 })
}
// 原始查询(数据库 ENUM 已包含 pending_confirm
const list = await prisma.$queryRaw<
{ id: string; amount: unknown; package_info: string | null; created_at: Date }[]
>`
SELECT id, amount, package_info, created_at
FROM withdrawals
WHERE user_id = ${userId}
AND status = 'pending_confirm'
AND package_info IS NOT NULL
ORDER BY created_at DESC
`
const { mchId, appId } = getTransferMchAndAppId()
const items = list.map((w) => ({
id: w.id,
amount: Number(w.amount),
package: w.package_info ?? '',
createdAt: w.created_at,
}))
return NextResponse.json({
success: true,
data: {
list: items,
mchId,
appId,
},
})
} catch (e) {
console.error('[Withdraw pending-confirm]', e)
return NextResponse.json(
{ success: false, message: '获取待确认列表失败' },
{ status: 500 }
)
}
}