推广中心优化 + 用户资料功能

1. 推广中心优化:
   - 增加"待购买"、"已过期"统计
   - 访问量单独显示
   - 移除10元提现门槛,有收益即可提现
   - 复制文案去掉"专属邀请码"

2. 我的页面:
   - 支持获取微信头像(原生能力)
   - 支持获取微信昵称
   - 新增用户更新API

3. 后台API:
   - referral/data返回expiredCount和expiredUsers
   - 新增user/update接口同步用户信息
This commit is contained in:
卡若
2026-01-29 11:35:56 +08:00
parent 8b2c3f4661
commit a228911170
6 changed files with 271 additions and 35 deletions

View File

@@ -128,7 +128,8 @@ export async function GET(request: NextRequest) {
// 6. 获取已转化用户列表
const convertedBindings = await query(`
SELECT rb.id, rb.referee_id, rb.conversion_date, rb.commission_amount,
u.nickname, u.avatar
u.nickname, u.avatar,
(SELECT COALESCE(SUM(amount), 0) FROM orders WHERE user_id = rb.referee_id AND status = 'paid') as order_amount
FROM referral_bindings rb
JOIN users u ON rb.referee_id = u.id
WHERE rb.referrer_id = ? AND rb.status = 'converted'
@@ -136,6 +137,17 @@ export async function GET(request: NextRequest) {
LIMIT 50
`, [userId]) as any[]
// 6.5 获取已过期用户列表
const expiredBindings = await query(`
SELECT rb.id, rb.referee_id, rb.expiry_date, rb.binding_date,
u.nickname, u.avatar
FROM referral_bindings rb
JOIN users u ON rb.referee_id = u.id
WHERE rb.referrer_id = ? AND (rb.status = 'expired' OR (rb.status = 'active' AND rb.expiry_date <= NOW()))
ORDER BY rb.expiry_date DESC
LIMIT 50
`, [userId]) as any[]
// 7. 获取收益明细
let earningsDetails: any[] = []
try {
@@ -165,6 +177,8 @@ export async function GET(request: NextRequest) {
visitCount: totalVisits,
// 带来的付款人数
paidCount: paymentStats.paidCount,
// 已过期用户数
expiredCount: bindingStats.expired,
// === 收益数据 ===
// 已结算收益
@@ -201,7 +215,8 @@ export async function GET(request: NextRequest) {
avatar: b.avatar,
daysRemaining: Math.max(0, b.days_remaining),
hasFullBook: b.has_full_book,
bindingDate: b.binding_date
bindingDate: b.binding_date,
status: 'active'
})),
convertedUsers: convertedBindings.map((b: any) => ({
@@ -209,7 +224,19 @@ export async function GET(request: NextRequest) {
nickname: b.nickname || '用户' + b.referee_id.slice(-4),
avatar: b.avatar,
commission: parseFloat(b.commission_amount) || 0,
conversionDate: b.conversion_date
orderAmount: parseFloat(b.order_amount) || 0,
conversionDate: b.conversion_date,
status: 'converted'
})),
// 已过期用户列表
expiredUsers: expiredBindings.map((b: any) => ({
id: b.referee_id,
nickname: b.nickname || '用户' + b.referee_id.slice(-4),
avatar: b.avatar,
bindingDate: b.binding_date,
expiryDate: b.expiry_date,
status: 'expired'
})),
// === 收益明细 ===

View File

@@ -0,0 +1,72 @@
// app/api/user/update/route.ts
// 更新用户信息(头像、昵称等)
import { NextRequest, NextResponse } from 'next/server'
import { getDb } from '@/lib/db'
export async function POST(req: NextRequest) {
try {
const { userId, nickname, avatar, phone, wechatId, address } = await req.json()
if (!userId) {
return NextResponse.json({ error: '缺少用户ID' }, { status: 400 })
}
const db = await getDb()
// 构建更新字段
const updates: string[] = []
const values: any[] = []
if (nickname !== undefined) {
updates.push('nickname = ?')
values.push(nickname)
}
if (avatar !== undefined) {
updates.push('avatar = ?')
values.push(avatar)
}
if (phone !== undefined) {
updates.push('phone = ?')
values.push(phone)
}
if (wechatId !== undefined) {
updates.push('wechat_id = ?')
values.push(wechatId)
}
if (address !== undefined) {
updates.push('address = ?')
values.push(address)
}
if (updates.length === 0) {
return NextResponse.json({ error: '没有要更新的字段' }, { status: 400 })
}
updates.push('updated_at = NOW()')
values.push(userId)
const sql = `UPDATE users SET ${updates.join(', ')} WHERE id = ?`
await db.execute(sql, values)
// 返回更新后的用户信息
const [rows] = await db.execute(
'SELECT id, nickname, avatar, phone, wechat_id, address FROM users WHERE id = ?',
[userId]
)
const user = (rows as any[])[0]
return NextResponse.json({
success: true,
user
})
} catch (error) {
console.error('[User Update] Error:', error)
return NextResponse.json(
{ error: '更新用户信息失败' },
{ status: 500 }
)
}
}