Files
soul/app/api/vip/profile/route.ts
卡若 afc2376e96 v1.19 全面改版:VIP会员系统、我的收益、创业老板排行、阅读量排序
- 后端: users表新增VIP字段, 4个VIP API (purchase/status/profile/members)
- 后端: hot接口改按user_tracks阅读量排序
- 后端: orders表支持vip产品类型, migrate新增vip_fields迁移
- 小程序「我的」: 推广中心改为我的收益, 头像VIP标识, VIP入口卡片
- 小程序「我的」: 最近阅读显示真实章节名称
- 小程序首页: 去掉内容概览, 新增创业老板排行(4列网格)
- 小程序首页: 精选推荐从hot接口获取, goToRead增加track记录
- 新增页面: VIP详情页, 会员详情页
- 开发文档精简为10个标准目录, 创建SKILL.md, 需求日志规范化

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-23 14:07:41 +08:00

78 lines
2.7 KiB
TypeScript

/**
* VIP会员资料填写/更新
*/
import { NextRequest, NextResponse } from 'next/server'
import { query } from '@/lib/db'
export async function POST(request: NextRequest) {
try {
const { userId, name, project, contact, avatar, bio } = await request.json()
if (!userId) {
return NextResponse.json({ success: false, error: '缺少userId' }, { status: 400 })
}
const users = await query('SELECT is_vip, vip_expire_date FROM users WHERE id = ?', [userId]) as any[]
if (!users.length) {
return NextResponse.json({ success: false, error: '用户不存在' }, { status: 404 })
}
const user = users[0]
if (!user.is_vip || !user.vip_expire_date || new Date(user.vip_expire_date) <= new Date()) {
return NextResponse.json({ success: false, error: '仅VIP会员可填写资料' }, { status: 403 })
}
const updates: string[] = []
const params: any[] = []
if (name !== undefined) { updates.push('vip_name = ?'); params.push(name) }
if (project !== undefined) { updates.push('vip_project = ?'); params.push(project) }
if (contact !== undefined) { updates.push('vip_contact = ?'); params.push(contact) }
if (avatar !== undefined) { updates.push('vip_avatar = ?'); params.push(avatar) }
if (bio !== undefined) { updates.push('vip_bio = ?'); params.push(bio) }
if (!updates.length) {
return NextResponse.json({ success: false, error: '无更新内容' }, { status: 400 })
}
params.push(userId)
await query(`UPDATE users SET ${updates.join(', ')} WHERE id = ?`, params)
return NextResponse.json({ success: true, message: '资料已更新' })
} catch (error) {
console.error('[VIP Profile]', error)
return NextResponse.json({ success: false, error: '更新失败' }, { status: 500 })
}
}
export async function GET(request: NextRequest) {
const userId = new URL(request.url).searchParams.get('userId')
if (!userId) {
return NextResponse.json({ success: false, error: '缺少userId' }, { status: 400 })
}
try {
const rows = await query(
'SELECT vip_name, vip_project, vip_contact, vip_avatar, vip_bio FROM users WHERE id = ?',
[userId]
) as any[]
if (!rows.length) {
return NextResponse.json({ success: false, error: '用户不存在' }, { status: 404 })
}
return NextResponse.json({
success: true,
data: {
name: rows[0].vip_name || '',
project: rows[0].vip_project || '',
contact: rows[0].vip_contact || '',
avatar: rows[0].vip_avatar || '',
bio: rows[0].vip_bio || ''
}
})
} catch (error) {
console.error('[VIP Profile GET]', error)
return NextResponse.json({ success: false, error: '查询失败' }, { status: 500 })
}
}