feat: 分销规则完善 + 微信支付修复
1. 分销规则: - 链接带ID绑定推荐关系 - 一级分销 + 30天有效期 - 客户抢夺机制(过期可被抢走) - 90%收益归分发者 2. 新增统计数据: - 绑定用户数 - 链接进入人数 - 带来付款人数 3. 微信支付: - 添加点击反馈 - 优化支付流程日志 - 改善错误提示 4. 分销中心UI优化
This commit is contained in:
@@ -455,26 +455,50 @@ Page({
|
||||
|
||||
// 购买章节 - 直接调起支付
|
||||
async handlePurchaseSection() {
|
||||
console.log('[Pay] 点击购买章节按钮')
|
||||
wx.showLoading({ title: '处理中...', mask: true })
|
||||
|
||||
if (!this.data.isLoggedIn) {
|
||||
wx.hideLoading()
|
||||
console.log('[Pay] 用户未登录,显示登录弹窗')
|
||||
this.setData({ showLoginModal: true })
|
||||
return
|
||||
}
|
||||
|
||||
await this.processPayment('section', this.data.sectionId, this.data.section.price)
|
||||
const price = this.data.section?.price || 1
|
||||
console.log('[Pay] 开始支付流程:', { sectionId: this.data.sectionId, price })
|
||||
wx.hideLoading()
|
||||
await this.processPayment('section', this.data.sectionId, price)
|
||||
},
|
||||
|
||||
// 购买全书 - 直接调起支付
|
||||
async handlePurchaseFullBook() {
|
||||
console.log('[Pay] 点击购买全书按钮')
|
||||
wx.showLoading({ title: '处理中...', mask: true })
|
||||
|
||||
if (!this.data.isLoggedIn) {
|
||||
wx.hideLoading()
|
||||
console.log('[Pay] 用户未登录,显示登录弹窗')
|
||||
this.setData({ showLoginModal: true })
|
||||
return
|
||||
}
|
||||
|
||||
console.log('[Pay] 开始支付流程: 全书', { price: this.data.fullBookPrice })
|
||||
wx.hideLoading()
|
||||
await this.processPayment('fullbook', null, this.data.fullBookPrice)
|
||||
},
|
||||
|
||||
// 处理支付 - 调用真实微信支付接口
|
||||
async processPayment(type, sectionId, amount) {
|
||||
console.log('[Pay] processPayment开始:', { type, sectionId, amount })
|
||||
|
||||
// 检查金额是否有效
|
||||
if (!amount || amount <= 0) {
|
||||
console.error('[Pay] 金额无效:', amount)
|
||||
wx.showToast({ title: '价格信息错误', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否已购买(避免重复购买)
|
||||
if (type === 'section' && sectionId) {
|
||||
const purchasedSections = app.globalData.purchasedSections || []
|
||||
@@ -490,6 +514,7 @@ Page({
|
||||
}
|
||||
|
||||
this.setData({ isPaying: true })
|
||||
wx.showLoading({ title: '正在发起支付...', mask: true })
|
||||
|
||||
try {
|
||||
// 1. 先获取openId (支付必需)
|
||||
@@ -497,6 +522,7 @@ Page({
|
||||
|
||||
if (!openId) {
|
||||
console.log('[Pay] 需要先获取openId,尝试静默获取')
|
||||
wx.showLoading({ title: '获取支付凭证...', mask: true })
|
||||
openId = await app.getOpenId()
|
||||
|
||||
if (!openId) {
|
||||
@@ -505,6 +531,7 @@ Page({
|
||||
console.log('[Pay] 使用用户ID作为替代')
|
||||
openId = app.globalData.userInfo.id
|
||||
} else {
|
||||
wx.hideLoading()
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content: '需要登录后才能支付,请先登录',
|
||||
@@ -517,6 +544,7 @@ Page({
|
||||
}
|
||||
|
||||
console.log('[Pay] 开始创建订单:', { type, sectionId, amount, openId: openId.slice(0, 10) + '...' })
|
||||
wx.showLoading({ title: '创建订单中...', mask: true })
|
||||
|
||||
// 2. 调用后端创建预支付订单
|
||||
let paymentData = null
|
||||
@@ -538,12 +566,13 @@ Page({
|
||||
|
||||
if (res.success && res.data?.payParams) {
|
||||
paymentData = res.data.payParams
|
||||
console.log('[Pay] 获取支付参数成功')
|
||||
console.log('[Pay] 获取支付参数成功:', paymentData)
|
||||
} else {
|
||||
throw new Error(res.error || '创建订单失败')
|
||||
throw new Error(res.error || res.message || '创建订单失败')
|
||||
}
|
||||
} catch (apiError) {
|
||||
console.error('[Pay] API创建订单失败:', apiError.message)
|
||||
console.error('[Pay] API创建订单失败:', apiError)
|
||||
wx.hideLoading()
|
||||
// 支付接口失败时,显示客服联系方式
|
||||
wx.showModal({
|
||||
title: '支付通道维护中',
|
||||
@@ -566,24 +595,48 @@ Page({
|
||||
}
|
||||
|
||||
// 3. 调用微信支付
|
||||
console.log('[Pay] 调起微信支付')
|
||||
await this.callWechatPay(paymentData)
|
||||
wx.hideLoading()
|
||||
console.log('[Pay] 调起微信支付, paymentData:', paymentData)
|
||||
|
||||
// 4. 支付成功,更新本地数据
|
||||
this.mockPaymentSuccess(type, sectionId)
|
||||
wx.showToast({ title: '购买成功', icon: 'success' })
|
||||
|
||||
// 5. 刷新页面
|
||||
this.initSection(this.data.sectionId)
|
||||
try {
|
||||
await this.callWechatPay(paymentData)
|
||||
|
||||
// 4. 支付成功,更新本地数据
|
||||
console.log('[Pay] 微信支付成功!')
|
||||
this.mockPaymentSuccess(type, sectionId)
|
||||
wx.showToast({ title: '购买成功', icon: 'success' })
|
||||
|
||||
// 5. 刷新页面
|
||||
this.initSection(this.data.sectionId)
|
||||
} catch (payErr) {
|
||||
console.error('[Pay] 微信支付调起失败:', payErr)
|
||||
if (payErr.errMsg && payErr.errMsg.includes('cancel')) {
|
||||
wx.showToast({ title: '已取消支付', icon: 'none' })
|
||||
} else if (payErr.errMsg && payErr.errMsg.includes('requestPayment:fail')) {
|
||||
// 支付失败,可能是参数错误或权限问题
|
||||
wx.showModal({
|
||||
title: '支付失败',
|
||||
content: '微信支付暂不可用,请添加客服微信(28533368)手动购买',
|
||||
confirmText: '复制微信号',
|
||||
cancelText: '取消',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
wx.setClipboardData({
|
||||
data: '28533368',
|
||||
success: () => wx.showToast({ title: '微信号已复制', icon: 'success' })
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
wx.showToast({ title: payErr.errMsg || '支付失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.error('[Pay] 支付失败:', e)
|
||||
|
||||
if (e.errMsg && e.errMsg.includes('cancel')) {
|
||||
wx.showToast({ title: '已取消支付', icon: 'none' })
|
||||
} else {
|
||||
wx.showToast({ title: e.errMsg || '支付失败', icon: 'none' })
|
||||
}
|
||||
console.error('[Pay] 支付流程异常:', e)
|
||||
wx.hideLoading()
|
||||
wx.showToast({ title: '支付出错,请重试', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ isPaying: false })
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
/**
|
||||
* Soul创业派对 - 分销中心页
|
||||
* 1:1还原Web版本
|
||||
*
|
||||
* 可见数据:
|
||||
* - 绑定用户数(当前有效绑定)
|
||||
* - 通过链接进的人数(总访问量)
|
||||
* - 带来的付款人数(已转化购买)
|
||||
* - 收益统计(90%归分发者)
|
||||
*/
|
||||
const app = getApp()
|
||||
|
||||
@@ -10,19 +15,25 @@ Page({
|
||||
isLoggedIn: false,
|
||||
userInfo: null,
|
||||
|
||||
// 收益数据
|
||||
earnings: 0,
|
||||
pendingEarnings: 0,
|
||||
distributorShare: 90,
|
||||
// === 核心可见数据 ===
|
||||
bindingCount: 0, // 绑定用户数(当前有效)
|
||||
visitCount: 0, // 通过链接进的人数
|
||||
paidCount: 0, // 带来的付款人数
|
||||
|
||||
// 统计数据
|
||||
referralCount: 0,
|
||||
expiringCount: 0,
|
||||
// === 收益数据 ===
|
||||
earnings: 0, // 已结算收益
|
||||
pendingEarnings: 0, // 待结算收益
|
||||
withdrawnEarnings: 0, // 已提现金额
|
||||
shareRate: 90, // 分成比例(90%)
|
||||
|
||||
// === 统计数据 ===
|
||||
referralCount: 0, // 总推荐人数
|
||||
expiringCount: 0, // 即将过期人数
|
||||
|
||||
// 邀请码
|
||||
referralCode: '',
|
||||
|
||||
// 绑定用户
|
||||
// 绑定用户列表
|
||||
showBindingList: true,
|
||||
activeTab: 'active',
|
||||
activeBindings: [],
|
||||
@@ -31,6 +42,9 @@ Page({
|
||||
currentBindings: [],
|
||||
totalBindings: 0,
|
||||
|
||||
// 收益明细
|
||||
earningsDetails: [],
|
||||
|
||||
// 海报
|
||||
showPosterModal: false,
|
||||
isGeneratingPoster: false
|
||||
@@ -61,48 +75,58 @@ Page({
|
||||
})
|
||||
if (res.success) {
|
||||
realData = res.data
|
||||
console.log('[Referral] 获取推广数据成功:', realData)
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('获取推广数据失败,使用本地数据')
|
||||
console.log('[Referral] 获取推广数据失败,使用本地数据')
|
||||
}
|
||||
|
||||
// 使用真实数据或本地存储的数据
|
||||
const storedBindings = wx.getStorageSync('referral_bindings') || []
|
||||
const storedEarnings = wx.getStorageSync('referral_earnings') || { total: 0, pending: 0 }
|
||||
// 使用真实数据或默认值
|
||||
let activeBindings = realData?.activeUsers || []
|
||||
let convertedBindings = realData?.convertedUsers || []
|
||||
let expiredBindings = []
|
||||
|
||||
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 = []
|
||||
// 兼容旧字段名
|
||||
if (!activeBindings.length && realData?.activeBindings) {
|
||||
activeBindings = realData.activeBindings
|
||||
}
|
||||
if (!convertedBindings.length && realData?.convertedBindings) {
|
||||
convertedBindings = realData.convertedBindings
|
||||
}
|
||||
if (realData?.expiredBindings) {
|
||||
expiredBindings = realData.expiredBindings
|
||||
}
|
||||
|
||||
const expiringCount = activeBindings.filter(b => b.daysRemaining <= 7).length
|
||||
const expiringCount = activeBindings.filter(b => b.daysRemaining <= 7 && b.daysRemaining > 0).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,
|
||||
|
||||
// 核心可见数据
|
||||
bindingCount: realData?.bindingCount || activeBindings.length,
|
||||
visitCount: realData?.visitCount || 0,
|
||||
paidCount: realData?.paidCount || convertedBindings.length,
|
||||
|
||||
// 收益数据
|
||||
earnings: realData?.earnings || 0,
|
||||
pendingEarnings: realData?.pendingEarnings || 0,
|
||||
withdrawnEarnings: realData?.withdrawnEarnings || 0,
|
||||
shareRate: realData?.shareRate || 90,
|
||||
|
||||
// 统计
|
||||
referralCount: realData?.referralCount || realData?.stats?.totalBindings || activeBindings.length + convertedBindings.length,
|
||||
expiringCount,
|
||||
|
||||
referralCode,
|
||||
activeBindings,
|
||||
convertedBindings,
|
||||
expiredBindings,
|
||||
expiringCount,
|
||||
currentBindings: activeBindings,
|
||||
totalBindings: activeBindings.length + convertedBindings.length + expiredBindings.length
|
||||
totalBindings: activeBindings.length + convertedBindings.length + expiredBindings.length,
|
||||
|
||||
// 收益明细
|
||||
earningsDetails: realData?.earningsDetails || []
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
<view class="wallet-icon">💰</view>
|
||||
<view class="earnings-info">
|
||||
<text class="earnings-label">累计收益</text>
|
||||
<text class="commission-rate">{{distributorShare}}% 返利</text>
|
||||
<text class="commission-rate">{{shareRate}}% 返利</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="earnings-right">
|
||||
@@ -40,42 +40,51 @@
|
||||
<text class="pending-text">待结算: ¥{{pendingEarnings}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="withdraw-btn {{earnings < 10 ? 'btn-disabled' : ''}}" bindtap="handleWithdraw">
|
||||
{{earnings < 10 ? '满10元可提现' : '申请提现'}}
|
||||
<view class="earnings-detail">
|
||||
<text class="detail-item">已提现: ¥{{withdrawnEarnings}}</text>
|
||||
</view>
|
||||
<view class="withdraw-btn {{pendingEarnings < 10 ? 'btn-disabled' : ''}}" bindtap="handleWithdraw">
|
||||
{{pendingEarnings < 10 ? '满10元可提现' : '申请提现'}}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 数据统计 -->
|
||||
<!-- 核心数据统计(重点可见数据) -->
|
||||
<view class="stats-grid">
|
||||
<view class="stat-card">
|
||||
<text class="stat-value">{{activeBindings.length}}</text>
|
||||
<text class="stat-label">绑定中</text>
|
||||
<view class="stat-card highlight">
|
||||
<text class="stat-value brand">{{bindingCount}}</text>
|
||||
<text class="stat-label">绑定用户数</text>
|
||||
<text class="stat-tip">当前有效绑定</text>
|
||||
</view>
|
||||
<view class="stat-card">
|
||||
<text class="stat-value">{{convertedBindings.length}}</text>
|
||||
<text class="stat-label">已付款</text>
|
||||
<text class="stat-value">{{visitCount}}</text>
|
||||
<text class="stat-label">链接进入人数</text>
|
||||
<text class="stat-tip">通过你的链接进入</text>
|
||||
</view>
|
||||
<view class="stat-card highlight">
|
||||
<text class="stat-value gold">{{paidCount}}</text>
|
||||
<text class="stat-label">付款人数</text>
|
||||
<text class="stat-tip">成功转化购买</text>
|
||||
</view>
|
||||
<view class="stat-card">
|
||||
<text class="stat-value orange">{{expiringCount}}</text>
|
||||
<text class="stat-label">即将过期</text>
|
||||
</view>
|
||||
<view class="stat-card">
|
||||
<text class="stat-value">{{referralCount}}</text>
|
||||
<text class="stat-label">总邀请</text>
|
||||
<text class="stat-tip">7天内到期</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 推广规则 -->
|
||||
<view class="rules-card">
|
||||
<view class="rules-header">
|
||||
<view class="rules-icon">ℹ️</view>
|
||||
<view class="rules-icon">📋</view>
|
||||
<text class="rules-title">推广规则</text>
|
||||
</view>
|
||||
<view class="rules-list">
|
||||
<text class="rule-item">• 好友通过你的链接购买,<text class="gold">立享5%优惠</text></text>
|
||||
<text class="rule-item">• 好友成功付款后,你获得 <text class="brand">{{distributorShare}}%</text> 收益</text>
|
||||
<text class="rule-item">• 绑定期<text class="brand">30天</text>,期满未付款自动解除</text>
|
||||
<text class="rule-item">• <text class="brand">链接带ID</text>:谁发的链接,进的人就绑谁</text>
|
||||
<text class="rule-item">• <text class="brand">一级、一月</text>:只有一级分销,绑定有效期30天</text>
|
||||
<text class="rule-item">• <text class="orange">长期不发</text>:别人发得多,过期后客户会被「抢走」</text>
|
||||
<text class="rule-item">• <text class="gold">每天发</text>:持续发的人绑定续期,收益越来越高</text>
|
||||
<text class="rule-item">• <text class="brand">{{shareRate}}%给分发</text>:好友付款后,你得 {{shareRate}}% 收益</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
|
||||
@@ -35,12 +35,20 @@
|
||||
.withdraw-btn { padding: 24rpx; background: #00CED1; color: #000; font-size: 28rpx; font-weight: 600; text-align: center; border-radius: 24rpx; }
|
||||
.withdraw-btn.btn-disabled { background: rgba(0,206,209,0.3); color: rgba(0,0,0,0.5); }
|
||||
|
||||
/* 数据统计 */
|
||||
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16rpx; margin-bottom: 24rpx; width: 100%; box-sizing: border-box; }
|
||||
.stat-card { background: #1c1c1e; border-radius: 24rpx; padding: 24rpx 16rpx; text-align: center; }
|
||||
.stat-value { font-size: 40rpx; font-weight: 700; color: #fff; display: block; }
|
||||
/* 收益详情 */
|
||||
.earnings-detail { padding-top: 16rpx; border-top: 2rpx solid rgba(255,255,255,0.1); margin-bottom: 24rpx; }
|
||||
.detail-item { font-size: 24rpx; color: rgba(255,255,255,0.5); }
|
||||
|
||||
/* 核心数据统计 */
|
||||
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16rpx; margin-bottom: 24rpx; width: 100%; box-sizing: border-box; }
|
||||
.stat-card { background: #1c1c1e; border-radius: 24rpx; padding: 28rpx 20rpx; text-align: center; position: relative; }
|
||||
.stat-card.highlight { background: linear-gradient(135deg, rgba(0,206,209,0.1) 0%, rgba(0,206,209,0.05) 100%); border: 2rpx solid rgba(0,206,209,0.2); }
|
||||
.stat-value { font-size: 48rpx; font-weight: 700; color: #fff; display: block; }
|
||||
.stat-value.brand { color: #00CED1; }
|
||||
.stat-value.gold { color: #FFD700; }
|
||||
.stat-value.orange { color: #FFA500; }
|
||||
.stat-label { font-size: 20rpx; color: rgba(255,255,255,0.5); margin-top: 8rpx; display: block; }
|
||||
.stat-label { font-size: 24rpx; color: rgba(255,255,255,0.7); margin-top: 8rpx; display: block; font-weight: 500; }
|
||||
.stat-tip { font-size: 20rpx; color: rgba(255,255,255,0.4); margin-top: 4rpx; display: block; }
|
||||
|
||||
/* 推广规则 */
|
||||
.rules-card { background: rgba(0,206,209,0.05); border: 2rpx solid rgba(0,206,209,0.2); border-radius: 24rpx; padding: 24rpx; margin-bottom: 24rpx; width: 100%; box-sizing: border-box; }
|
||||
@@ -48,9 +56,10 @@
|
||||
.rules-icon { width: 56rpx; height: 56rpx; background: rgba(0,206,209,0.2); border-radius: 16rpx; display: flex; align-items: center; justify-content: center; font-size: 28rpx; }
|
||||
.rules-title { font-size: 28rpx; font-weight: 500; color: #fff; }
|
||||
.rules-list { padding-left: 8rpx; }
|
||||
.rule-item { font-size: 24rpx; color: rgba(255,255,255,0.6); line-height: 1.8; display: block; }
|
||||
.rule-item .gold { color: #FFD700; }
|
||||
.rule-item .brand { color: #00CED1; }
|
||||
.rule-item { font-size: 24rpx; color: rgba(255,255,255,0.6); line-height: 2; display: block; margin-bottom: 4rpx; }
|
||||
.rule-item .gold { color: #FFD700; font-weight: 500; }
|
||||
.rule-item .brand { color: #00CED1; font-weight: 500; }
|
||||
.rule-item .orange { color: #FFA500; font-weight: 500; }
|
||||
|
||||
/* 绑定用户卡片 */
|
||||
.binding-card { background: #1c1c1e; border-radius: 32rpx; overflow: hidden; margin-bottom: 24rpx; width: 100%; box-sizing: border-box; }
|
||||
|
||||
Reference in New Issue
Block a user