Files
soul/app/api/db/withdrawals/route.ts
卡若 b60edb3d47 feat: 完整重构小程序匹配功能 + 修复UI对齐 + 文章数据API
主要更新:
1. 按H5网页端完全重构匹配功能(match页面)
   - 4种匹配类型: 创业合伙/资源对接/导师顾问/团队招募
   - 资源对接等类型弹出手机号/微信号输入框
   - 去掉重新匹配按钮,改为返回按钮

2. 修复所有卡片对齐和宽度问题
   - 目录页附录卡片居中
   - 首页阅读进度卡片满宽度
   - 我的页面菜单卡片对齐
   - 推广中心分享卡片统一宽度

3. 修复目录页图标和文字对齐
   - section-icon固定40rpx宽高
   - section-title与图标垂直居中

4. 更新真实完整文章标题(62篇)
   - 从book目录读取真实markdown文件名
   - 替换之前的简化标题

5. 新增文章数据API
   - /api/db/chapters - 获取完整书籍结构
   - 支持按ID获取单篇文章内容
2026-01-21 15:49:12 +08:00

114 lines
3.0 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import { withdrawalDB, userDB } from '@/lib/db'
// 获取提现记录
export async function GET(req: NextRequest) {
try {
const { searchParams } = new URL(req.url)
const userId = searchParams.get('user_id')
if (userId) {
const withdrawals = await withdrawalDB.getByUserId(userId)
return NextResponse.json({ success: true, withdrawals })
}
const withdrawals = await withdrawalDB.getAll()
return NextResponse.json({ success: true, withdrawals })
} catch (error: any) {
console.error('Get withdrawals error:', error)
return NextResponse.json({
success: false,
error: error.message
}, { status: 500 })
}
}
// 创建提现申请
export async function POST(req: NextRequest) {
try {
const body = await req.json()
const { user_id, amount, method, account, name } = body
// 验证用户余额
const user = await userDB.getById(user_id)
if (!user) {
return NextResponse.json({
success: false,
error: '用户不存在'
}, { status: 404 })
}
if ((user.earnings || 0) < amount) {
return NextResponse.json({
success: false,
error: '余额不足'
}, { status: 400 })
}
// 创建提现记录
const withdrawal = await withdrawalDB.create({
id: `withdrawal_${Date.now()}`,
user_id,
amount,
method,
account,
name,
status: 'pending'
})
// 扣除用户余额,增加待提现金额
await userDB.update(user_id, {
earnings: (user.earnings || 0) - amount,
pending_earnings: (user.pending_earnings || 0) + amount
})
return NextResponse.json({ success: true, withdrawal })
} catch (error: any) {
console.error('Create withdrawal error:', error)
return NextResponse.json({
success: false,
error: error.message
}, { status: 500 })
}
}
// 更新提现状态
export async function PUT(req: NextRequest) {
try {
const body = await req.json()
const { id, status } = body
if (!id) {
return NextResponse.json({
success: false,
error: '缺少提现记录ID'
}, { status: 400 })
}
await withdrawalDB.updateStatus(id, status)
// 如果状态是已完成,更新用户的已提现金额
if (status === 'completed') {
const withdrawals = await withdrawalDB.getAll()
const withdrawal = withdrawals.find((w: any) => w.id === id)
if (withdrawal) {
const user = await userDB.getById(withdrawal.user_id)
if (user) {
await userDB.update(user.id, {
pending_earnings: (user.pending_earnings || 0) - withdrawal.amount,
withdrawn_earnings: (user.withdrawn_earnings || 0) + withdrawal.amount
})
}
}
}
return NextResponse.json({ success: true })
} catch (error: any) {
console.error('Update withdrawal status error:', error)
return NextResponse.json({
success: false,
error: error.message
}, { status: 500 })
}
}