diff --git a/app/api/match/users/route.ts b/app/api/match/users/route.ts new file mode 100644 index 0000000..2407246 --- /dev/null +++ b/app/api/match/users/route.ts @@ -0,0 +1,86 @@ +/** + * 匹配用户API + * 从数据库中查询用户进行匹配 + */ + +import { NextRequest, NextResponse } from 'next/server' +import { query } from '@/lib/db' + +/** + * POST - 获取匹配的用户 + */ +export async function POST(request: NextRequest) { + try { + const body = await request.json() + const { userId, matchType } = body + + if (!userId) { + return NextResponse.json({ success: false, message: '缺少用户ID' }, { status: 400 }) + } + + // 从数据库查询其他用户(排除自己) + // 筛选条件:有头像、有昵称、有微信号或手机号 + const users = await query(` + SELECT + id, + nickname, + avatar, + wechat as wechatId, + phone, + introduction, + created_at + FROM users + WHERE id != ? + AND nickname IS NOT NULL + AND nickname != '' + AND (wechat IS NOT NULL OR phone IS NOT NULL) + AND (avatar IS NOT NULL AND avatar != '') + ORDER BY RAND() + LIMIT 10 + `, [userId]) as any[] + + if (!users || users.length === 0) { + return NextResponse.json({ + success: false, + message: '暂无匹配用户', + data: null + }) + } + + // 随机选择一个用户 + const randomUser = users[Math.floor(Math.random() * users.length)] + + // 构建匹配结果 + const matchResult = { + id: randomUser.id, + nickname: randomUser.nickname || '创业者', + avatar: randomUser.avatar || 'https://picsum.photos/200/200?random=' + Date.now(), + wechat: randomUser.wechatId || '', + phone: randomUser.phone ? randomUser.phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2') : '', + introduction: randomUser.introduction || '来自Soul创业派对的伙伴', + tags: ['创业者', '私域运营', matchType === 'partner' ? '创业合伙' : + matchType === 'investor' ? '资源对接' : + matchType === 'mentor' ? '导师顾问' : '团队招募'], + matchScore: Math.floor(Math.random() * 20) + 80, + commonInterests: [ + { icon: '📚', text: '都在读《创业派对》' }, + { icon: '💼', text: '对创业感兴趣' }, + { icon: '🎯', text: '相似的发展方向' } + ] + } + + return NextResponse.json({ + success: true, + data: matchResult, + totalUsers: users.length + }) + + } catch (error) { + console.error('[Match Users] Error:', error) + return NextResponse.json({ + success: false, + message: '匹配失败', + error: String(error) + }, { status: 500 }) + } +} diff --git a/miniprogram/pages/match/match.js b/miniprogram/pages/match/match.js index 5adca0c..e463d13 100644 --- a/miniprogram/pages/match/match.js +++ b/miniprogram/pages/match/match.js @@ -257,7 +257,7 @@ Page({ }) }, - // 开始匹配 + // 开始匹配 - 只匹配数据库中的真实用户 async startMatch() { this.setData({ isMatching: true, @@ -270,29 +270,23 @@ Page({ this.setData({ matchAttempts: this.data.matchAttempts + 1 }) }, 1000) - // 尝试从API获取真实用户 + // 从数据库获取真实用户匹配 let matchedUser = null try { - const res = await app.request('/api/ckb/match', { + const res = await app.request('/api/match/users', { method: 'POST', data: { matchType: this.data.selectedType, - userId: app.globalData.userInfo?.id || '', - phone: this.data.phoneNumber, - wechat: this.data.wechatId + userId: app.globalData.userInfo?.id || '' } }) if (res.success && res.data) { matchedUser = res.data + console.log('[Match] 从数据库匹配到用户:', matchedUser.nickname) } } catch (e) { - console.log('API匹配失败,使用模拟数据') - } - - // 如果API没返回,使用模拟数据 - if (!matchedUser) { - matchedUser = this.generateMockMatch() + console.log('[Match] 数据库匹配失败:', e) } // 延迟显示结果(模拟匹配过程) @@ -300,6 +294,18 @@ Page({ setTimeout(() => { clearInterval(timer) + // 如果没有匹配到用户,提示用户 + if (!matchedUser) { + this.setData({ isMatching: false }) + wx.showModal({ + title: '暂无匹配', + content: '当前暂无合适的匹配用户,请稍后再试', + showCancel: false, + confirmText: '知道了' + }) + return + } + // 增加今日匹配次数 const newCount = this.data.todayMatchCount + 1 const matchesRemaining = this.data.hasFullBook ? 999999 : Math.max(0, this.data.totalMatchesAllowed - newCount) @@ -313,7 +319,7 @@ Page({ }) this.saveTodayMatchCount(newCount) - // 上报匹配行为 + // 上报匹配行为到存客宝 this.reportMatch(matchedUser) }, delay) diff --git a/miniprogram/pages/referral/referral.js b/miniprogram/pages/referral/referral.js index 381d88f..f1fcf77 100644 --- a/miniprogram/pages/referral/referral.js +++ b/miniprogram/pages/referral/referral.js @@ -373,18 +373,43 @@ Page({ // 阻止冒泡 stopPropagation() {}, - // 分享到朋友圈 + // 分享到朋友圈 - 随机文案 shareToMoments() { - const shareText = `🔥 发现一本超棒的创业实战书《Soul创业派对》!\n\n💡 62个真实商业案例,从私域运营到资源整合,干货满满!\n\n🎁 ${this.data.userInfo?.nickname || '卡若'} 推荐,通过海报扫码购买立享优惠!\n\n#创业派对 #私域运营 #商业案例` + // 10条随机文案,基于书的内容 + const shareTexts = [ + `🔥 在派对房里听到的真实故事,比虚构的小说精彩100倍!\n\n电动车出租月入5万、私域一年赚1000万、一个人的公司月入10万...\n\n62个真实案例,搜"Soul创业派对"小程序看全部!\n\n#创业 #私域 #商业`, + + `💡 今天终于明白:会赚钱的人,都在用"流量杠杆"\n\n抖音、Soul、飞书...同一套内容,撬动不同平台的流量。\n\n《Soul创业派对》里的实战方法,受用终身!\n\n#流量 #副业 #创业派对`, + + `📚 一个70后大健康私域,一个月150万流水是怎么做到的?\n\n答案在《Soul创业派对》第9章,全是干货。\n\n搜小程序"Soul创业派对",我在里面等你\n\n#大健康 #私域运营 #真实案例`, + + `🎯 "分钱不是分你的钱,是分不属于对方的钱"\n\n这句话改变了我对商业合作的认知。\n\n推荐《Soul创业派对》,创业者必读!\n\n#云阿米巴 #商业思维 #创业`, + + `✨ 资源整合高手的社交方法论,在派对房里学到了\n\n"先让对方赚到钱,自己才能长久赚钱"\n\n这本《Soul创业派对》,每章都是实战经验\n\n#资源整合 #社交 #创业故事`, + + `🚀 AI工具推广:一个隐藏的高利润赛道\n\n客单价高、复购率高、需求旺盛...\n\n《Soul创业派对》里的商业机会,你发现了吗?\n\n#AI #副业 #商业机会`, + + `💰 美业整合:一个人的公司如何月入十万?\n\n不开店、不囤货、轻资产运营...\n\n《Soul创业派对》告诉你答案!\n\n#美业 #轻创业 #月入十万`, + + `🌟 3000万流水是怎么跑出来的?\n\n不是靠运气,是靠系统。\n\n《Soul创业派对》里的电商底层逻辑,值得反复看\n\n#电商 #创业 #商业系统`, + + `📖 "人与人之间的关系,归根结底就三个东西:利益、情感、价值观"\n\n在派对房里聊出的金句,都在《Soul创业派对》里\n\n#人性 #商业 #创业派对`, + + `🔔 未来职业的三个方向:技术型、资源型、服务型\n\n你属于哪一种?\n\n《Soul创业派对》帮你找到答案!\n\n#职业规划 #创业 #未来` + ] + + // 随机选择一条文案 + const randomIndex = Math.floor(Math.random() * shareTexts.length) + const shareText = shareTexts[randomIndex] wx.setClipboardData({ data: shareText, success: () => { wx.showModal({ title: '文案已复制', - content: '请打开微信朋友圈,粘贴分享文案,配合推广海报一起发布效果更佳', + content: '请打开微信朋友圈,粘贴分享文案,配合推广海报一起发布效果更佳!\n\n再次点击可获取新的随机文案', showCancel: false, - confirmText: '知道了' + confirmText: '去发朋友圈' }) } })