主要更新: - 后台菜单精简(9项→6项) - 新增搜索功能(敏感信息过滤) - 分销绑定和提现系统完善 - 数据库初始化API(自动修复表结构) - 用户管理:显示绑定关系详情 - 小程序:上下章导航优化、匹配页面重构 - 修复hydration和数据类型问题
272 lines
7.5 KiB
JavaScript
272 lines
7.5 KiB
JavaScript
/**
|
||
* Soul创业派对 - 分销中心页
|
||
* 1:1还原Web版本
|
||
*/
|
||
const app = getApp()
|
||
|
||
Page({
|
||
data: {
|
||
statusBarHeight: 44,
|
||
isLoggedIn: false,
|
||
userInfo: null,
|
||
|
||
// 收益数据
|
||
earnings: 0,
|
||
pendingEarnings: 0,
|
||
distributorShare: 90,
|
||
|
||
// 统计数据
|
||
referralCount: 0,
|
||
expiringCount: 0,
|
||
|
||
// 邀请码
|
||
referralCode: '',
|
||
|
||
// 绑定用户
|
||
showBindingList: true,
|
||
activeTab: 'active',
|
||
activeBindings: [],
|
||
convertedBindings: [],
|
||
expiredBindings: [],
|
||
currentBindings: [],
|
||
totalBindings: 0
|
||
},
|
||
|
||
onLoad() {
|
||
this.setData({ statusBarHeight: app.globalData.statusBarHeight })
|
||
this.initData()
|
||
},
|
||
|
||
onShow() {
|
||
this.initData()
|
||
},
|
||
|
||
// 初始化数据
|
||
async initData() {
|
||
const { isLoggedIn, userInfo } = app.globalData
|
||
if (isLoggedIn && userInfo) {
|
||
// 生成邀请码
|
||
const referralCode = userInfo.referralCode || 'SOUL' + (userInfo.id || Date.now().toString(36)).toUpperCase().slice(-6)
|
||
|
||
// 尝试从API获取真实数据
|
||
let realData = null
|
||
try {
|
||
const res = await app.request('/api/referral/data', {
|
||
method: 'GET',
|
||
data: { userId: userInfo.id }
|
||
})
|
||
if (res.success) {
|
||
realData = res.data
|
||
}
|
||
} catch (e) {
|
||
console.log('获取推广数据失败,使用本地数据')
|
||
}
|
||
|
||
// 使用真实数据或本地存储的数据
|
||
const storedBindings = wx.getStorageSync('referral_bindings') || []
|
||
const storedEarnings = wx.getStorageSync('referral_earnings') || { total: 0, pending: 0 }
|
||
|
||
let activeBindings, convertedBindings, expiredBindings
|
||
|
||
if (realData) {
|
||
activeBindings = realData.activeBindings || []
|
||
convertedBindings = realData.convertedBindings || []
|
||
expiredBindings = realData.expiredBindings || []
|
||
} else if (storedBindings.length > 0) {
|
||
// 使用本地存储的数据
|
||
activeBindings = storedBindings.filter(b => b.status === 'active')
|
||
convertedBindings = storedBindings.filter(b => b.status === 'converted')
|
||
expiredBindings = storedBindings.filter(b => b.status === 'expired')
|
||
} else {
|
||
// 默认空数据
|
||
activeBindings = []
|
||
convertedBindings = []
|
||
expiredBindings = []
|
||
}
|
||
|
||
const expiringCount = activeBindings.filter(b => b.daysRemaining <= 7).length
|
||
|
||
this.setData({
|
||
isLoggedIn: true,
|
||
userInfo,
|
||
earnings: realData?.earnings || storedEarnings.total || 0,
|
||
pendingEarnings: realData?.pendingEarnings || storedEarnings.pending || 0,
|
||
referralCount: realData?.referralCount || activeBindings.length + convertedBindings.length,
|
||
referralCode,
|
||
activeBindings,
|
||
convertedBindings,
|
||
expiredBindings,
|
||
expiringCount,
|
||
currentBindings: activeBindings,
|
||
totalBindings: activeBindings.length + convertedBindings.length + expiredBindings.length
|
||
})
|
||
}
|
||
},
|
||
|
||
// 切换Tab
|
||
switchTab(e) {
|
||
const tab = e.currentTarget.dataset.tab
|
||
let currentBindings = []
|
||
|
||
if (tab === 'active') {
|
||
currentBindings = this.data.activeBindings
|
||
} else if (tab === 'converted') {
|
||
currentBindings = this.data.convertedBindings
|
||
} else {
|
||
currentBindings = this.data.expiredBindings
|
||
}
|
||
|
||
this.setData({ activeTab: tab, currentBindings })
|
||
},
|
||
|
||
// 切换绑定列表显示
|
||
toggleBindingList() {
|
||
this.setData({ showBindingList: !this.data.showBindingList })
|
||
},
|
||
|
||
// 复制邀请链接
|
||
copyLink() {
|
||
const link = `https://soul.quwanzhi.com/?ref=${this.data.referralCode}`
|
||
wx.setClipboardData({
|
||
data: link,
|
||
success: () => wx.showToast({ title: '链接已复制', icon: 'success' })
|
||
})
|
||
},
|
||
|
||
// 生成海报
|
||
generatePoster() {
|
||
wx.showToast({ title: '海报功能开发中', icon: 'none' })
|
||
},
|
||
|
||
// 分享到朋友圈
|
||
shareToMoments() {
|
||
const shareText = `🔥 发现一本超棒的创业实战书《Soul创业派对》!\n\n💡 62个真实商业案例,从私域运营到资源整合,干货满满!\n\n🎁 通过我的链接购买立享5%优惠,我是 ${this.data.userInfo?.nickname || '卡若'} 推荐!\n\n👉 ${this.data.referralCode} 是我的专属邀请码\n\n#创业派对 #私域运营 #商业案例`
|
||
|
||
wx.setClipboardData({
|
||
data: shareText,
|
||
success: () => {
|
||
wx.showModal({
|
||
title: '文案已复制',
|
||
content: '请打开微信朋友圈,粘贴分享文案即可',
|
||
showCancel: false,
|
||
confirmText: '知道了'
|
||
})
|
||
}
|
||
})
|
||
},
|
||
|
||
// 提现 - 直接到微信零钱
|
||
async handleWithdraw() {
|
||
const pendingEarnings = parseFloat(this.data.pendingEarnings) || 0
|
||
|
||
if (pendingEarnings < 10) {
|
||
wx.showToast({ title: '满10元可提现', icon: 'none' })
|
||
return
|
||
}
|
||
|
||
// 确认提现
|
||
wx.showModal({
|
||
title: '确认提现',
|
||
content: `将提现 ¥${pendingEarnings.toFixed(2)} 到您的微信零钱`,
|
||
confirmText: '立即提现',
|
||
success: async (res) => {
|
||
if (res.confirm) {
|
||
await this.doWithdraw(pendingEarnings)
|
||
}
|
||
}
|
||
})
|
||
},
|
||
|
||
// 执行提现
|
||
async doWithdraw(amount) {
|
||
wx.showLoading({ title: '提现中...' })
|
||
|
||
try {
|
||
const userId = app.globalData.userInfo?.id
|
||
if (!userId) {
|
||
wx.hideLoading()
|
||
wx.showToast({ title: '请先登录', icon: 'none' })
|
||
return
|
||
}
|
||
|
||
const res = await app.request('/api/withdraw', {
|
||
method: 'POST',
|
||
data: { userId, amount }
|
||
})
|
||
|
||
wx.hideLoading()
|
||
|
||
if (res.success) {
|
||
wx.showModal({
|
||
title: '提现成功 🎉',
|
||
content: `¥${amount.toFixed(2)} 已到账您的微信零钱`,
|
||
showCancel: false,
|
||
confirmText: '好的'
|
||
})
|
||
|
||
// 刷新数据
|
||
this.initData()
|
||
} else {
|
||
if (res.needBind) {
|
||
wx.showModal({
|
||
title: '需要绑定微信',
|
||
content: '请先在设置中绑定微信账号后再提现',
|
||
confirmText: '去绑定',
|
||
success: (modalRes) => {
|
||
if (modalRes.confirm) {
|
||
wx.navigateTo({ url: '/pages/settings/settings' })
|
||
}
|
||
}
|
||
})
|
||
} else {
|
||
wx.showToast({ title: res.error || '提现失败', icon: 'none' })
|
||
}
|
||
}
|
||
} catch (e) {
|
||
wx.hideLoading()
|
||
console.error('[Referral] 提现失败:', e)
|
||
wx.showToast({ title: '提现失败,请重试', icon: 'none' })
|
||
}
|
||
},
|
||
|
||
// 显示通知
|
||
showNotification() {
|
||
wx.showToast({ title: '暂无新消息', icon: 'none' })
|
||
},
|
||
|
||
// 显示设置
|
||
showSettings() {
|
||
wx.showActionSheet({
|
||
itemList: ['自动提现设置', '收益通知设置'],
|
||
success: (res) => {
|
||
if (res.tapIndex === 0) {
|
||
wx.showToast({ title: '自动提现功能开发中', icon: 'none' })
|
||
} else {
|
||
wx.showToast({ title: '通知设置开发中', icon: 'none' })
|
||
}
|
||
}
|
||
})
|
||
},
|
||
|
||
// 分享 - 带推荐码
|
||
onShareAppMessage() {
|
||
return {
|
||
title: '📚 Soul创业派对 - 来自派对房的真实商业故事',
|
||
path: `/pages/index/index?ref=${this.data.referralCode}`,
|
||
imageUrl: '/assets/share-cover.png'
|
||
}
|
||
},
|
||
|
||
// 分享到朋友圈
|
||
onShareTimeline() {
|
||
return {
|
||
title: `Soul创业派对 - 62个真实商业案例`,
|
||
query: `ref=${this.data.referralCode}`
|
||
}
|
||
},
|
||
|
||
goBack() {
|
||
wx.navigateBack()
|
||
}
|
||
})
|