Files
soul-yongping/app/api/referral/data/route.ts

95 lines
2.3 KiB
TypeScript
Raw Normal View History

/**
* 广API
* 广
*/
import { NextResponse } from 'next/server'
/**
* GET - 广
*/
export async function GET(request: Request) {
try {
const { searchParams } = new URL(request.url)
const userId = searchParams.get('userId')
if (!userId) {
return NextResponse.json({
success: false,
error: '缺少用户ID'
}, { status: 400 })
}
console.log('[ReferralData] 获取推广数据, userId:', userId)
// TODO: 从数据库获取真实数据
// 这里应该连接数据库查询用户的推广数据
// 模拟数据结构
const mockData = {
earnings: 0,
pendingEarnings: 0,
referralCount: 0,
activeBindings: [],
convertedBindings: [],
expiredBindings: [],
referralCode: `SOUL${userId.slice(-6).toUpperCase()}`
}
return NextResponse.json({
success: true,
data: mockData
})
} catch (error) {
console.error('[ReferralData] 获取推广数据失败:', error)
return NextResponse.json({
success: false,
error: '获取推广数据失败'
}, { status: 500 })
}
}
/**
* POST - 广
*/
export async function POST(request: Request) {
try {
const body = await request.json()
const { referralCode, userId, userInfo } = body
if (!referralCode || !userId) {
return NextResponse.json({
success: false,
error: '缺少必要参数'
}, { status: 400 })
}
console.log('[ReferralData] 创建绑定关系:', { referralCode, userId })
// TODO: 数据库操作
// 1. 根据referralCode查找推广者
// 2. 创建绑定关系记录
// 3. 设置30天过期时间
// 模拟成功响应
return NextResponse.json({
success: true,
data: {
bindingId: `binding_${Date.now()}`,
referrerId: `referrer_${referralCode}`,
userId,
bindingDate: new Date().toISOString(),
expiryDate: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toISOString(),
status: 'active'
}
})
} catch (error) {
console.error('[ReferralData] 创建绑定关系失败:', error)
return NextResponse.json({
success: false,
error: '创建绑定关系失败'
}, { status: 500 })
}
}