feat: 完善后台管理+搜索功能+分销系统

主要更新:
- 后台菜单精简(9项→6项)
- 新增搜索功能(敏感信息过滤)
- 分销绑定和提现系统完善
- 数据库初始化API(自动修复表结构)
- 用户管理:显示绑定关系详情
- 小程序:上下章导航优化、匹配页面重构
- 修复hydration和数据类型问题
This commit is contained in:
卡若
2026-01-25 19:37:59 +08:00
parent 65d2831a45
commit 4dd2f9f4a7
49 changed files with 5921 additions and 636 deletions

View File

@@ -1,167 +1,74 @@
/**
* 匹配规则配置API
* 管理后台匹配类型和规则配置
* 匹配配置API
* 获取匹配类型和价格配置
*/
import { NextResponse } from 'next/server'
import { NextRequest, NextResponse } from 'next/server'
import { getConfig } from '@/lib/db'
// 默认匹配类型配置
const DEFAULT_MATCH_TYPES = [
{
id: 'partner',
label: '创业合伙',
matchLabel: '创业伙伴',
icon: '',
matchFromDB: true,
showJoinAfterMatch: false,
description: '寻找志同道合的创业伙伴,共同打造事业',
enabled: true
},
{
id: 'investor',
label: '资源对接',
matchLabel: '资源对接',
icon: '👥',
matchFromDB: false,
showJoinAfterMatch: true,
description: '对接各类商业资源,拓展合作机会',
enabled: true
},
{
id: 'mentor',
label: '导师顾问',
matchLabel: '商业顾问',
icon: '❤️',
matchFromDB: false,
showJoinAfterMatch: true,
description: '寻找行业导师,获得专业指导',
enabled: true
},
{
id: 'team',
label: '团队招募',
matchLabel: '加入项目',
icon: '🎮',
matchFromDB: false,
showJoinAfterMatch: true,
description: '招募团队成员,扩充项目人才',
enabled: true
}
]
/**
* GET - 获取匹配类型配置
*/
export async function GET(request: Request) {
try {
console.log('[MatchConfig] 获取匹配配置')
// TODO: 从数据库获取配置
// 这里应该从数据库读取管理员配置的匹配类型
const matchTypes = DEFAULT_MATCH_TYPES.filter(type => type.enabled)
return NextResponse.json({
success: true,
data: {
matchTypes,
freeMatchLimit: 3, // 每日免费匹配次数
matchPrice: 1, // 付费匹配价格(元)
settings: {
enableFreeMatches: true,
enablePaidMatches: true,
maxMatchesPerDay: 10
}
}
})
} catch (error) {
console.error('[MatchConfig] 获取匹配配置失败:', error)
return NextResponse.json({
success: false,
error: '获取匹配配置失败'
}, { status: 500 })
// 默认匹配配置
const DEFAULT_MATCH_CONFIG = {
matchTypes: [
{ id: 'partner', label: '创业合伙', matchLabel: '创业伙伴', icon: '⭐', matchFromDB: true, showJoinAfterMatch: false, price: 1, enabled: true },
{ id: 'investor', label: '资源对接', matchLabel: '资源对接', icon: '👥', matchFromDB: false, showJoinAfterMatch: true, price: 1, enabled: true },
{ id: 'mentor', label: '导师顾问', matchLabel: '商业顾问', icon: '❤️', matchFromDB: false, showJoinAfterMatch: true, price: 1, enabled: true },
{ id: 'team', label: '团队招募', matchLabel: '加入项目', icon: '🎮', matchFromDB: false, showJoinAfterMatch: true, price: 1, enabled: true }
],
freeMatchLimit: 3,
matchPrice: 1,
settings: {
enableFreeMatches: true,
enablePaidMatches: true,
maxMatchesPerDay: 10
}
}
/**
* POST - 更新匹配类型配置(管理员功能)
* GET - 获取匹配配置
*/
export async function POST(request: Request) {
export async function GET(request: NextRequest) {
try {
const body = await request.json()
const { matchTypes, settings, adminToken } = body
// TODO: 验证管理员权限
if (!adminToken || adminToken !== 'admin_token_placeholder') {
return NextResponse.json({
success: false,
error: '无权限操作'
}, { status: 403 })
// 优先从数据库读取
let config = null
try {
config = await getConfig('match_config')
} catch (e) {
console.log('[MatchConfig] 数据库读取失败,使用默认配置')
}
console.log('[MatchConfig] 更新匹配配置:', { matchTypes: matchTypes?.length, settings })
// TODO: 保存到数据库
// 这里应该将配置保存到数据库
// 合并默认配置
const finalConfig = {
...DEFAULT_MATCH_CONFIG,
...(config || {})
}
// 只返回启用的匹配类型
const enabledTypes = finalConfig.matchTypes.filter((t: any) => t.enabled !== false)
return NextResponse.json({
success: true,
data: {
message: '配置更新成功',
updatedAt: new Date().toISOString()
}
matchTypes: enabledTypes,
freeMatchLimit: finalConfig.freeMatchLimit,
matchPrice: finalConfig.matchPrice,
settings: finalConfig.settings
},
source: config ? 'database' : 'default'
})
} catch (error) {
console.error('[MatchConfig] 更新匹配配置失败:', error)
console.error('[MatchConfig] GET错误:', error)
// 出错时返回默认配置
return NextResponse.json({
success: false,
error: '更新匹配配置失败'
}, { status: 500 })
success: true,
data: {
matchTypes: DEFAULT_MATCH_CONFIG.matchTypes,
freeMatchLimit: DEFAULT_MATCH_CONFIG.freeMatchLimit,
matchPrice: DEFAULT_MATCH_CONFIG.matchPrice,
settings: DEFAULT_MATCH_CONFIG.settings
},
source: 'fallback'
})
}
}
/**
* PUT - 启用/禁用特定匹配类型
*/
export async function PUT(request: Request) {
try {
const body = await request.json()
const { typeId, enabled, adminToken } = body
if (!adminToken || adminToken !== 'admin_token_placeholder') {
return NextResponse.json({
success: false,
error: '无权限操作'
}, { status: 403 })
}
if (!typeId || typeof enabled !== 'boolean') {
return NextResponse.json({
success: false,
error: '参数错误'
}, { status: 400 })
}
console.log('[MatchConfig] 切换匹配类型状态:', { typeId, enabled })
// TODO: 更新数据库中的匹配类型状态
return NextResponse.json({
success: true,
data: {
typeId,
enabled,
updatedAt: new Date().toISOString()
}
})
} catch (error) {
console.error('[MatchConfig] 切换匹配类型状态失败:', error)
return NextResponse.json({
success: false,
error: '操作失败'
}, { status: 500 })
}
}