feat: 全面优化小程序界面和功能

 新增功能:
- 配置后台匹配规则选择功能,支持多种匹配类型自定义
- 推广中心使用真实数据,实现H5/小程序绑定关系
- 配置MySQL数据库连接,建立完整数据表结构

🎨 界面优化:
- 优化登录状态显示,未登录只显示基础功能
- 修复推广中心等页面宽度问题,统一界面布局
- 优化设置页面绑定弹窗样式,简洁大气
- 修复目录页图标和文字对齐问题

🔧 技术改进:
- 匹配功能支持后台配置,动态加载匹配类型
- 推广数据支持API获取,本地存储作为备份
- 数据库表结构完整,支持用户、订单、推广关系
- 小程序登录仅保留微信登录方式

📱 小程序优化:
- 匹配次数调整为每日3次免费
- 支持¥1购买额外匹配次数
- 分享到朋友圈功能优化
- 界面宽度统一,卡片布局一致
This commit is contained in:
卡若
2026-01-23 16:31:54 +08:00
parent e869974341
commit 1e1e6a1093
18 changed files with 1017 additions and 613 deletions

View File

@@ -1,16 +1,83 @@
/**
* 数据库初始化API
* 创建数据库表结构和默认配置
*/
import { NextResponse } from 'next/server'
import { initDatabase } from '@/lib/db'
// 初始化数据库表
export async function POST() {
/**
* POST - 初始化数据库
*/
export async function POST(request: Request) {
try {
const body = await request.json()
const { adminToken } = body
// 简单的管理员验证
if (adminToken !== 'init_db_2025') {
return NextResponse.json({
success: false,
error: '无权限执行此操作'
}, { status: 403 })
}
console.log('[DB Init] 开始初始化数据库...')
await initDatabase()
return NextResponse.json({ success: true, message: '数据库初始化成功' })
} catch (error: any) {
console.error('Database init error:', error)
return NextResponse.json({
success: false,
error: error.message || '数据库初始化失败'
console.log('[DB Init] 数据库初始化完成')
return NextResponse.json({
success: true,
data: {
message: '数据库初始化成功',
timestamp: new Date().toISOString()
}
})
} catch (error) {
console.error('[DB Init] 数据库初始化失败:', error)
return NextResponse.json({
success: false,
error: '数据库初始化失败: ' + (error as Error).message
}, { status: 500 })
}
}
/**
* GET - 检查数据库状态
*/
export async function GET() {
try {
const { query } = await import('@/lib/db')
// 检查数据库连接
await query('SELECT 1')
// 检查表是否存在
const tables = await query(`
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = DATABASE()
`) as any[]
const tableNames = tables.map(t => t.TABLE_NAME)
return NextResponse.json({
success: true,
data: {
connected: true,
tables: tableNames,
tablesCount: tableNames.length
}
})
} catch (error) {
console.error('[DB Status] 检查数据库状态失败:', error)
return NextResponse.json({
success: false,
error: '数据库连接失败: ' + (error as Error).message
}, { status: 500 })
}
}

View File

@@ -0,0 +1,167 @@
/**
* 匹配规则配置API
* 管理后台匹配类型和规则配置
*/
import { NextResponse } from 'next/server'
// 默认匹配类型配置
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 })
}
}
/**
* POST - 更新匹配类型配置(管理员功能)
*/
export async function POST(request: Request) {
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 })
}
console.log('[MatchConfig] 更新匹配配置:', { matchTypes: matchTypes?.length, settings })
// TODO: 保存到数据库
// 这里应该将配置保存到数据库
return NextResponse.json({
success: true,
data: {
message: '配置更新成功',
updatedAt: new Date().toISOString()
}
})
} catch (error) {
console.error('[MatchConfig] 更新匹配配置失败:', error)
return NextResponse.json({
success: false,
error: '更新匹配配置失败'
}, { status: 500 })
}
}
/**
* 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 })
}
}

View File

@@ -0,0 +1,95 @@
/**
* 推广中心数据API
* 获取用户推广数据、绑定关系等
*/
import { NextResponse } from 'next/server'
/**
* GET - 获取用户推广数据
*/
export async function GET(request: Request) {
try {
const { searchParams } = new URL(request.url)
const userId = searchParams.get('userId')
if (!userId) {
return NextResponse.json({
success: false,
error: '缺少用户ID'
}, { status: 400 })
}
console.log('[ReferralData] 获取推广数据, userId:', userId)
// TODO: 从数据库获取真实数据
// 这里应该连接数据库查询用户的推广数据
// 模拟数据结构
const mockData = {
earnings: 0,
pendingEarnings: 0,
referralCount: 0,
activeBindings: [],
convertedBindings: [],
expiredBindings: [],
referralCode: `SOUL${userId.slice(-6).toUpperCase()}`
}
return NextResponse.json({
success: true,
data: mockData
})
} catch (error) {
console.error('[ReferralData] 获取推广数据失败:', error)
return NextResponse.json({
success: false,
error: '获取推广数据失败'
}, { status: 500 })
}
}
/**
* POST - 创建推广绑定关系
*/
export async function POST(request: Request) {
try {
const body = await request.json()
const { referralCode, userId, userInfo } = body
if (!referralCode || !userId) {
return NextResponse.json({
success: false,
error: '缺少必要参数'
}, { status: 400 })
}
console.log('[ReferralData] 创建绑定关系:', { referralCode, userId })
// TODO: 数据库操作
// 1. 根据referralCode查找推广者
// 2. 创建绑定关系记录
// 3. 设置30天过期时间
// 模拟成功响应
return NextResponse.json({
success: true,
data: {
bindingId: `binding_${Date.now()}`,
referrerId: `referrer_${referralCode}`,
userId,
bindingDate: new Date().toISOString(),
expiryDate: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toISOString(),
status: 'active'
}
})
} catch (error) {
console.error('[ReferralData] 创建绑定关系失败:', error)
return NextResponse.json({
success: false,
error: '创建绑定关系失败'
}, { status: 500 })
}
}