同步
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
const app = getApp()
|
||||
const soulBridge = require('../../utils/soulBridge.js')
|
||||
const { checkAndExecute } = require('../../utils/ruleEngine.js')
|
||||
const { trackClick } = require('../../utils/trackClick')
|
||||
|
||||
@@ -426,6 +427,7 @@ Page({
|
||||
|
||||
// 从数据库获取真实用户匹配
|
||||
let matchedUser = null
|
||||
let matchProfileError = ''
|
||||
try {
|
||||
const res = await app.request({ url: '/api/miniprogram/match/users', silent: true,
|
||||
method: 'POST',
|
||||
@@ -434,20 +436,38 @@ Page({
|
||||
userId: app.globalData.userInfo?.id || ''
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
if (res.success && res.data) {
|
||||
matchedUser = res.data
|
||||
console.log('[Match] 从数据库匹配到用户:', matchedUser.nickname)
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('[Match] 数据库匹配失败:', e)
|
||||
const r = e.response || {}
|
||||
if (r.errorCode === 'ERR_PROFILE_INCOMPLETE') {
|
||||
matchProfileError = r.message || '请先完善手机号或微信号后再发起匹配'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 延迟显示结果(模拟匹配过程)
|
||||
const delay = Math.random() * 2000 + 2000
|
||||
setTimeout(() => {
|
||||
clearInterval(timer)
|
||||
|
||||
|
||||
if (matchProfileError) {
|
||||
this.setData({ isMatching: false })
|
||||
wx.showModal({
|
||||
title: '完善资料',
|
||||
content: matchProfileError,
|
||||
confirmText: '去完善',
|
||||
showCancel: false,
|
||||
success: (mr) => {
|
||||
if (mr.confirm) wx.navigateTo({ url: '/pages/profile-edit/profile-edit' })
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 如果没有匹配到用户,提示用户
|
||||
if (!matchedUser) {
|
||||
this.setData({ isMatching: false })
|
||||
@@ -632,7 +652,27 @@ Page({
|
||||
wx.showToast({ title: res.error || '加入失败', icon: 'none' })
|
||||
}
|
||||
} catch (e) {
|
||||
wx.showToast({ title: '网络异常,请重试', icon: 'none' })
|
||||
const r = e.response || {}
|
||||
if (r.errorCode === 'ERR_REQUIRE_PURCHASE') {
|
||||
wx.showModal({
|
||||
title: '需要先购买',
|
||||
content: r.message || '请先购买章节或解锁全书后再使用资源对接',
|
||||
confirmText: '去购买',
|
||||
cancelText: '取消',
|
||||
success: (mr) => { if (mr.confirm) this.goToChapters() }
|
||||
})
|
||||
} else if (r.errorCode === 'ERR_PROFILE_INCOMPLETE') {
|
||||
wx.showModal({
|
||||
title: '完善资料',
|
||||
content: r.message || '请先完善资料',
|
||||
confirmText: '去完善',
|
||||
success: (mr) => {
|
||||
if (mr.confirm) wx.navigateTo({ url: '/pages/profile-edit/profile-edit' })
|
||||
}
|
||||
})
|
||||
} else {
|
||||
wx.showToast({ title: e.message || '网络异常,请重试', icon: 'none' })
|
||||
}
|
||||
} finally {
|
||||
this.setData({ isJoining: false })
|
||||
}
|
||||
@@ -670,9 +710,7 @@ Page({
|
||||
return
|
||||
}
|
||||
|
||||
// 邀请码:与章节支付一致,写入订单便于分销归属与对账
|
||||
const referralCode = wx.getStorageSync('referral_code') || ''
|
||||
// 调用支付接口购买匹配次数
|
||||
const referralCode = soulBridge.getReferralCodeForPay(app)
|
||||
const res = await app.request('/api/miniprogram/pay', {
|
||||
method: 'POST',
|
||||
data: {
|
||||
@@ -685,17 +723,11 @@ Page({
|
||||
referralCode: referralCode || undefined
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
if (res.success && res.data?.payParams) {
|
||||
// 调用微信支付
|
||||
await new Promise((resolve, reject) => {
|
||||
wx.requestPayment({
|
||||
...res.data.payParams,
|
||||
success: resolve,
|
||||
fail: reject
|
||||
})
|
||||
})
|
||||
|
||||
await soulBridge.requestWxJsapiPayment(res.data.payParams)
|
||||
await soulBridge.syncOrderStatusQuery(app, res.data.orderSn)
|
||||
|
||||
// 支付成功,增加匹配次数
|
||||
const extraMatches = (wx.getStorageSync('extra_match_count') || 0) + 1
|
||||
wx.setStorageSync('extra_match_count', extraMatches)
|
||||
|
||||
Reference in New Issue
Block a user