sync: Gitea 同步配置、miniprogram 页面逻辑、miniprogram 页面样式、脚本与配置、soul-admin 前端、soul-admin 页面、soul-api 接口逻辑、soul-api 路由等 | 原因: 多模块开发更新
This commit is contained in:
@@ -141,15 +141,22 @@ App({
|
||||
}
|
||||
},
|
||||
|
||||
// 绑定推荐码到用户
|
||||
// 绑定推荐码到用户(自己的推荐码不请求接口,避免 400 与控制台报错)
|
||||
async bindReferralCode(refCode) {
|
||||
try {
|
||||
const userId = this.globalData.userInfo?.id
|
||||
if (!userId || !refCode) return
|
||||
|
||||
|
||||
const myCode = this.getMyReferralCode()
|
||||
if (myCode && this._normalizeReferralCode(refCode) === this._normalizeReferralCode(myCode)) {
|
||||
console.log('[App] 跳过绑定:不能使用自己的推荐码')
|
||||
this.globalData.pendingReferralCode = null
|
||||
wx.removeStorageSync('pendingReferralCode')
|
||||
return
|
||||
}
|
||||
|
||||
console.log('[App] 绑定推荐码:', refCode, '到用户:', userId)
|
||||
|
||||
// 调用API绑定推荐关系
|
||||
|
||||
const res = await this.request('/api/miniprogram/referral/bind', {
|
||||
method: 'POST',
|
||||
data: {
|
||||
@@ -158,19 +165,31 @@ App({
|
||||
},
|
||||
silent: true
|
||||
})
|
||||
|
||||
|
||||
if (res.success) {
|
||||
console.log('[App] 推荐码绑定成功')
|
||||
// 仅记录当前已绑定的推荐码,用于展示/调试;是否允许更换由后端根据30天规则判断
|
||||
wx.setStorageSync('boundReferralCode', refCode)
|
||||
this.globalData.pendingReferralCode = null
|
||||
wx.removeStorageSync('pendingReferralCode')
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[App] 绑定推荐码失败:', e)
|
||||
const msg = (e && e.message) ? String(e.message) : ''
|
||||
if (msg.indexOf('不能使用自己的推荐码') !== -1) {
|
||||
console.log('[App] 跳过绑定:不能使用自己的推荐码')
|
||||
this.globalData.pendingReferralCode = null
|
||||
wx.removeStorageSync('pendingReferralCode')
|
||||
} else {
|
||||
console.error('[App] 绑定推荐码失败:', e)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// 推荐码归一化后比较(忽略大小写、短横线等)
|
||||
_normalizeReferralCode(code) {
|
||||
if (!code || typeof code !== 'string') return ''
|
||||
return code.replace(/[\s\-_]/g, '').toUpperCase().trim()
|
||||
},
|
||||
|
||||
// 根据业务 id 从 bookData 查 mid(用于跳转)
|
||||
getSectionMid(sectionId) {
|
||||
const list = this.globalData.bookData || []
|
||||
|
||||
Reference in New Issue
Block a user