海报随机文案 + 找伙伴匹配数据库用户

## 海报功能
1. 10条随机朋友圈文案(基于书内容)
2. 二维码已带用户ID

## 找伙伴
1. 新增 /api/match/users API
2. 只匹配数据库中的真实用户
3. 排除自己,筛选有头像和联系方式的用户
This commit is contained in:
卡若
2026-01-29 12:25:01 +08:00
parent 0f50fb7c3b
commit cd2c8d7cc5
3 changed files with 134 additions and 17 deletions

View File

@@ -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 })
}
}

View File

@@ -257,7 +257,7 @@ Page({
}) })
}, },
// 开始匹配 // 开始匹配 - 只匹配数据库中的真实用户
async startMatch() { async startMatch() {
this.setData({ this.setData({
isMatching: true, isMatching: true,
@@ -270,29 +270,23 @@ Page({
this.setData({ matchAttempts: this.data.matchAttempts + 1 }) this.setData({ matchAttempts: this.data.matchAttempts + 1 })
}, 1000) }, 1000)
// 尝试从API获取真实用户 // 从数据库获取真实用户匹配
let matchedUser = null let matchedUser = null
try { try {
const res = await app.request('/api/ckb/match', { const res = await app.request('/api/match/users', {
method: 'POST', method: 'POST',
data: { data: {
matchType: this.data.selectedType, matchType: this.data.selectedType,
userId: app.globalData.userInfo?.id || '', userId: app.globalData.userInfo?.id || ''
phone: this.data.phoneNumber,
wechat: this.data.wechatId
} }
}) })
if (res.success && res.data) { if (res.success && res.data) {
matchedUser = res.data matchedUser = res.data
console.log('[Match] 从数据库匹配到用户:', matchedUser.nickname)
} }
} catch (e) { } catch (e) {
console.log('API匹配失败使用模拟数据') console.log('[Match] 数据库匹配失败:', e)
}
// 如果API没返回使用模拟数据
if (!matchedUser) {
matchedUser = this.generateMockMatch()
} }
// 延迟显示结果(模拟匹配过程) // 延迟显示结果(模拟匹配过程)
@@ -300,6 +294,18 @@ Page({
setTimeout(() => { setTimeout(() => {
clearInterval(timer) clearInterval(timer)
// 如果没有匹配到用户,提示用户
if (!matchedUser) {
this.setData({ isMatching: false })
wx.showModal({
title: '暂无匹配',
content: '当前暂无合适的匹配用户,请稍后再试',
showCancel: false,
confirmText: '知道了'
})
return
}
// 增加今日匹配次数 // 增加今日匹配次数
const newCount = this.data.todayMatchCount + 1 const newCount = this.data.todayMatchCount + 1
const matchesRemaining = this.data.hasFullBook ? 999999 : Math.max(0, this.data.totalMatchesAllowed - newCount) const matchesRemaining = this.data.hasFullBook ? 999999 : Math.max(0, this.data.totalMatchesAllowed - newCount)
@@ -313,7 +319,7 @@ Page({
}) })
this.saveTodayMatchCount(newCount) this.saveTodayMatchCount(newCount)
// 上报匹配行为 // 上报匹配行为到存客宝
this.reportMatch(matchedUser) this.reportMatch(matchedUser)
}, delay) }, delay)

View File

@@ -373,18 +373,43 @@ Page({
// 阻止冒泡 // 阻止冒泡
stopPropagation() {}, stopPropagation() {},
// 分享到朋友圈 // 分享到朋友圈 - 随机文案
shareToMoments() { 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({ wx.setClipboardData({
data: shareText, data: shareText,
success: () => { success: () => {
wx.showModal({ wx.showModal({
title: '文案已复制', title: '文案已复制',
content: '请打开微信朋友圈,粘贴分享文案,配合推广海报一起发布效果更佳', content: '请打开微信朋友圈,粘贴分享文案,配合推广海报一起发布效果更佳\n\n再次点击可获取新的随机文案',
showCancel: false, showCancel: false,
confirmText: '知道了' confirmText: '去发朋友圈'
}) })
} }
}) })