Files
soul/app/api/match/config/route.ts
卡若 4dd2f9f4a7 feat: 完善后台管理+搜索功能+分销系统
主要更新:
- 后台菜单精简(9项→6项)
- 新增搜索功能(敏感信息过滤)
- 分销绑定和提现系统完善
- 数据库初始化API(自动修复表结构)
- 用户管理:显示绑定关系详情
- 小程序:上下章导航优化、匹配页面重构
- 修复hydration和数据类型问题
2026-01-25 19:37:59 +08:00

75 lines
2.3 KiB
TypeScript

/**
* 匹配配置API
* 获取匹配类型和价格配置
*/
import { NextRequest, NextResponse } from 'next/server'
import { getConfig } from '@/lib/db'
// 默认匹配配置
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
}
}
/**
* GET - 获取匹配配置
*/
export async function GET(request: NextRequest) {
try {
// 优先从数据库读取
let config = null
try {
config = await getConfig('match_config')
} catch (e) {
console.log('[MatchConfig] 数据库读取失败,使用默认配置')
}
// 合并默认配置
const finalConfig = {
...DEFAULT_MATCH_CONFIG,
...(config || {})
}
// 只返回启用的匹配类型
const enabledTypes = finalConfig.matchTypes.filter((t: any) => t.enabled !== false)
return NextResponse.json({
success: true,
data: {
matchTypes: enabledTypes,
freeMatchLimit: finalConfig.freeMatchLimit,
matchPrice: finalConfig.matchPrice,
settings: finalConfig.settings
},
source: config ? 'database' : 'default'
})
} catch (error) {
console.error('[MatchConfig] GET错误:', error)
// 出错时返回默认配置
return NextResponse.json({
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'
})
}
}