Files
soul/app/api/vip/status/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

74 lines
2.3 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.

/**
* VIP会员状态查询
*/
import { NextRequest, NextResponse } from 'next/server'
import { query, getConfig } from '@/lib/db'
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 is_vip, vip_expire_date, vip_name, vip_project, vip_contact, vip_avatar, vip_bio,
has_full_book, nickname, avatar
FROM users WHERE id = ?`,
[userId]
) as any[]
if (!rows.length) {
return NextResponse.json({ success: false, error: '用户不存在' }, { status: 404 })
}
const user = rows[0]
const now = new Date()
const isVip = user.is_vip && user.vip_expire_date && new Date(user.vip_expire_date) > now
// 若过期则自动标记
if (user.is_vip && !isVip) {
await query('UPDATE users SET is_vip = FALSE WHERE id = ?', [userId]).catch(() => {})
}
let vipPrice = 1980
let vipRights: string[] = []
try {
const priceConfig = await getConfig('vip_price')
if (priceConfig) vipPrice = Number(priceConfig) || 1980
const rightsConfig = await getConfig('vip_rights')
if (rightsConfig) vipRights = Array.isArray(rightsConfig) ? rightsConfig : JSON.parse(rightsConfig)
} catch { /* 使用默认 */ }
if (!vipRights.length) {
vipRights = [
'解锁全部章节内容365天',
'匹配所有创业伙伴',
'创业老板排行榜展示',
'专属VIP标识'
]
}
return NextResponse.json({
success: true,
data: {
isVip,
expireDate: user.vip_expire_date,
daysRemaining: isVip ? Math.ceil((new Date(user.vip_expire_date).getTime() - now.getTime()) / 86400000) : 0,
profile: {
name: user.vip_name || '',
project: user.vip_project || '',
contact: user.vip_contact || '',
avatar: user.vip_avatar || user.avatar || '',
bio: user.vip_bio || ''
},
price: vipPrice,
rights: vipRights
}
})
} catch (error) {
console.error('[VIP Status]', error)
return NextResponse.json({ success: false, error: '查询失败' }, { status: 500 })
}
}