推广中心优化 + 用户资料功能
1. 推广中心优化: - 增加"待购买"、"已过期"统计 - 访问量单独显示 - 移除10元提现门槛,有收益即可提现 - 复制文案去掉"专属邀请码" 2. 我的页面: - 支持获取微信头像(原生能力) - 支持获取微信昵称 - 新增用户更新API 3. 后台API: - referral/data返回expiredCount和expiredUsers - 新增user/update接口同步用户信息
This commit is contained in:
@@ -105,18 +105,96 @@ Page({
|
||||
// 编辑用户资料(头像和昵称)
|
||||
editProfile() {
|
||||
wx.showActionSheet({
|
||||
itemList: ['修改头像', '修改昵称'],
|
||||
itemList: ['获取微信头像', '获取微信昵称', '从相册选择头像', '手动输入昵称'],
|
||||
success: (res) => {
|
||||
if (res.tapIndex === 0) {
|
||||
this.chooseAvatar()
|
||||
this.getWechatAvatar()
|
||||
} else if (res.tapIndex === 1) {
|
||||
this.getWechatNickname()
|
||||
} else if (res.tapIndex === 2) {
|
||||
this.chooseAvatar()
|
||||
} else if (res.tapIndex === 3) {
|
||||
this.editNickname()
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 选择头像
|
||||
// 获取微信头像(原生能力)
|
||||
getWechatAvatar() {
|
||||
// 使用chooseAvatar API(微信原生头像选择)
|
||||
wx.chooseAvatar({
|
||||
success: async (res) => {
|
||||
const avatarUrl = res.avatarUrl
|
||||
wx.showLoading({ title: '更新中...', mask: true })
|
||||
|
||||
try {
|
||||
// 更新本地显示
|
||||
const userInfo = this.data.userInfo
|
||||
userInfo.avatar = avatarUrl
|
||||
this.setData({ userInfo })
|
||||
app.globalData.userInfo = userInfo
|
||||
wx.setStorageSync('userInfo', userInfo)
|
||||
|
||||
// 同步到服务器
|
||||
await app.request('/api/user/update', {
|
||||
method: 'POST',
|
||||
data: { userId: userInfo.id, avatar: avatarUrl }
|
||||
})
|
||||
|
||||
wx.hideLoading()
|
||||
wx.showToast({ title: '头像已更新', icon: 'success' })
|
||||
} catch (e) {
|
||||
wx.hideLoading()
|
||||
wx.showToast({ title: '更新失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
wx.showToast({ title: '取消选择', icon: 'none' })
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 获取微信昵称(原生能力)
|
||||
getWechatNickname() {
|
||||
// 引导用户在弹窗中输入微信昵称
|
||||
wx.showModal({
|
||||
title: '获取微信昵称',
|
||||
content: '请在下方输入您的微信昵称',
|
||||
editable: true,
|
||||
placeholderText: '请输入微信昵称',
|
||||
success: async (res) => {
|
||||
if (res.confirm && res.content) {
|
||||
const nickname = res.content.trim()
|
||||
if (nickname.length < 1 || nickname.length > 20) {
|
||||
wx.showToast({ title: '昵称1-20个字符', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
// 更新本地
|
||||
const userInfo = this.data.userInfo
|
||||
userInfo.nickname = nickname
|
||||
this.setData({ userInfo })
|
||||
app.globalData.userInfo = userInfo
|
||||
wx.setStorageSync('userInfo', userInfo)
|
||||
|
||||
// 同步到服务器
|
||||
try {
|
||||
await app.request('/api/user/update', {
|
||||
method: 'POST',
|
||||
data: { userId: userInfo.id, nickname }
|
||||
})
|
||||
} catch (e) {
|
||||
console.log('同步昵称到服务器失败', e)
|
||||
}
|
||||
|
||||
wx.showToast({ title: '昵称已更新', icon: 'success' })
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 从相册选择头像
|
||||
chooseAvatar() {
|
||||
wx.chooseMedia({
|
||||
count: 1,
|
||||
@@ -134,7 +212,12 @@ Page({
|
||||
app.globalData.userInfo = userInfo
|
||||
wx.setStorageSync('userInfo', userInfo)
|
||||
|
||||
// TODO: 上传到服务器
|
||||
// 同步到服务器
|
||||
await app.request('/api/user/update', {
|
||||
method: 'POST',
|
||||
data: { userId: userInfo.id, avatar: tempFilePath }
|
||||
})
|
||||
|
||||
wx.hideLoading()
|
||||
wx.showToast({ title: '头像已更新', icon: 'success' })
|
||||
} catch (e) {
|
||||
@@ -145,7 +228,7 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
// 修改昵称
|
||||
// 手动输入昵称
|
||||
editNickname() {
|
||||
wx.showModal({
|
||||
title: '修改昵称',
|
||||
@@ -166,7 +249,16 @@ Page({
|
||||
app.globalData.userInfo = userInfo
|
||||
wx.setStorageSync('userInfo', userInfo)
|
||||
|
||||
// TODO: 上传到服务器
|
||||
// 同步到服务器
|
||||
try {
|
||||
await app.request('/api/user/update', {
|
||||
method: 'POST',
|
||||
data: { userId: userInfo.id, nickname: newNickname }
|
||||
})
|
||||
} catch (e) {
|
||||
console.log('同步昵称到服务器失败', e)
|
||||
}
|
||||
|
||||
wx.showToast({ title: '昵称已更新', icon: 'success' })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ Page({
|
||||
bindingCount: 0, // 绑定用户数(当前有效)
|
||||
visitCount: 0, // 通过链接进的人数
|
||||
paidCount: 0, // 带来的付款人数
|
||||
unboughtCount: 0, // 待购买人数(绑定但未付款)
|
||||
expiredCount: 0, // 已过期人数
|
||||
|
||||
// === 收益数据 ===
|
||||
earnings: 0, // 已结算收益
|
||||
@@ -84,7 +86,7 @@ Page({
|
||||
// 使用真实数据或默认值
|
||||
let activeBindings = realData?.activeUsers || []
|
||||
let convertedBindings = realData?.convertedUsers || []
|
||||
let expiredBindings = []
|
||||
let expiredBindings = realData?.expiredUsers || []
|
||||
|
||||
// 兼容旧字段名
|
||||
if (!activeBindings.length && realData?.activeBindings) {
|
||||
@@ -93,20 +95,40 @@ Page({
|
||||
if (!convertedBindings.length && realData?.convertedBindings) {
|
||||
convertedBindings = realData.convertedBindings
|
||||
}
|
||||
if (realData?.expiredBindings) {
|
||||
if (!expiredBindings.length && realData?.expiredBindings) {
|
||||
expiredBindings = realData.expiredBindings
|
||||
}
|
||||
|
||||
const expiringCount = activeBindings.filter(b => b.daysRemaining <= 7 && b.daysRemaining > 0).length
|
||||
|
||||
// 计算各类统计
|
||||
const bindingCount = realData?.bindingCount || activeBindings.length
|
||||
const paidCount = realData?.paidCount || convertedBindings.length
|
||||
const expiredCount = realData?.expiredCount || expiredBindings.length
|
||||
const unboughtCount = bindingCount // 绑定中但未付款的
|
||||
|
||||
// 格式化用户数据
|
||||
const formatUser = (user, type) => ({
|
||||
id: user.id,
|
||||
nickname: user.nickname || '用户' + (user.id || '').slice(-4),
|
||||
avatar: user.avatar,
|
||||
status: type,
|
||||
daysRemaining: user.daysRemaining || 0,
|
||||
bindingDate: user.bindingDate ? this.formatDate(user.bindingDate) : '--',
|
||||
commission: user.commission || 0,
|
||||
orderAmount: user.orderAmount || 0
|
||||
})
|
||||
|
||||
this.setData({
|
||||
isLoggedIn: true,
|
||||
userInfo,
|
||||
|
||||
// 核心可见数据
|
||||
bindingCount: realData?.bindingCount || activeBindings.length,
|
||||
bindingCount,
|
||||
visitCount: realData?.visitCount || 0,
|
||||
paidCount: realData?.paidCount || convertedBindings.length,
|
||||
paidCount,
|
||||
unboughtCount,
|
||||
expiredCount,
|
||||
|
||||
// 收益数据
|
||||
earnings: realData?.earnings || 0,
|
||||
@@ -119,10 +141,10 @@ Page({
|
||||
expiringCount,
|
||||
|
||||
referralCode,
|
||||
activeBindings,
|
||||
convertedBindings,
|
||||
expiredBindings,
|
||||
currentBindings: activeBindings,
|
||||
activeBindings: activeBindings.map(u => formatUser(u, 'active')),
|
||||
convertedBindings: convertedBindings.map(u => formatUser(u, 'converted')),
|
||||
expiredBindings: expiredBindings.map(u => formatUser(u, 'expired')),
|
||||
currentBindings: activeBindings.map(u => formatUser(u, 'active')),
|
||||
totalBindings: activeBindings.length + convertedBindings.length + expiredBindings.length,
|
||||
|
||||
// 收益明细
|
||||
@@ -353,14 +375,14 @@ Page({
|
||||
|
||||
// 分享到朋友圈
|
||||
shareToMoments() {
|
||||
const shareText = `🔥 发现一本超棒的创业实战书《Soul创业派对》!\n\n💡 62个真实商业案例,从私域运营到资源整合,干货满满!\n\n🎁 通过我的链接购买立享5%优惠,我是 ${this.data.userInfo?.nickname || '卡若'} 推荐!\n\n👉 ${this.data.referralCode} 是我的专属邀请码\n\n#创业派对 #私域运营 #商业案例`
|
||||
const shareText = `🔥 发现一本超棒的创业实战书《Soul创业派对》!\n\n💡 62个真实商业案例,从私域运营到资源整合,干货满满!\n\n🎁 ${this.data.userInfo?.nickname || '卡若'} 推荐,通过海报扫码购买立享优惠!\n\n#创业派对 #私域运营 #商业案例`
|
||||
|
||||
wx.setClipboardData({
|
||||
data: shareText,
|
||||
success: () => {
|
||||
wx.showModal({
|
||||
title: '文案已复制',
|
||||
content: '请打开微信朋友圈,粘贴分享文案即可',
|
||||
content: '请打开微信朋友圈,粘贴分享文案,配合推广海报一起发布效果更佳',
|
||||
showCancel: false,
|
||||
confirmText: '知道了'
|
||||
})
|
||||
@@ -368,12 +390,12 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
// 提现 - 直接到微信零钱
|
||||
// 提现 - 直接到微信零钱(无门槛)
|
||||
async handleWithdraw() {
|
||||
const pendingEarnings = parseFloat(this.data.pendingEarnings) || 0
|
||||
|
||||
if (pendingEarnings < 10) {
|
||||
wx.showToast({ title: '满10元可提现', icon: 'none' })
|
||||
if (pendingEarnings <= 0) {
|
||||
wx.showToast({ title: '暂无可提现收益', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
@@ -480,5 +502,14 @@ Page({
|
||||
|
||||
goBack() {
|
||||
wx.navigateBack()
|
||||
},
|
||||
|
||||
// 格式化日期
|
||||
formatDate(dateStr) {
|
||||
if (!dateStr) return '--'
|
||||
const d = new Date(dateStr)
|
||||
const month = (d.getMonth() + 1).toString().padStart(2, '0')
|
||||
const day = d.getDate().toString().padStart(2, '0')
|
||||
return `${month}-${day}`
|
||||
}
|
||||
})
|
||||
|
||||
@@ -43,8 +43,8 @@
|
||||
<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 class="withdraw-btn {{pendingEarnings <= 0 ? 'btn-disabled' : ''}}" bindtap="handleWithdraw">
|
||||
{{pendingEarnings <= 0 ? '暂无收益' : '立即提现 ¥' + pendingEarnings}}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -53,24 +53,31 @@
|
||||
<view class="stats-grid">
|
||||
<view class="stat-card highlight">
|
||||
<text class="stat-value brand">{{bindingCount}}</text>
|
||||
<text class="stat-label">绑定用户数</text>
|
||||
<text class="stat-label">绑定中</text>
|
||||
<text class="stat-tip">当前有效绑定</text>
|
||||
</view>
|
||||
<view class="stat-card">
|
||||
<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>
|
||||
<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>
|
||||
<text class="stat-tip">7天内到期</text>
|
||||
<text class="stat-value orange">{{unboughtCount}}</text>
|
||||
<text class="stat-label">待购买</text>
|
||||
<text class="stat-tip">绑定未付款</text>
|
||||
</view>
|
||||
<view class="stat-card">
|
||||
<text class="stat-value gray">{{expiredCount}}</text>
|
||||
<text class="stat-label">已过期</text>
|
||||
<text class="stat-tip">绑定已失效</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 访问量统计 -->
|
||||
<view class="visit-stat">
|
||||
<text class="visit-label">总访问量</text>
|
||||
<text class="visit-value">{{visitCount}}</text>
|
||||
<text class="visit-tip">人通过你的链接进入</text>
|
||||
</view>
|
||||
|
||||
<!-- 推广规则 -->
|
||||
|
||||
@@ -47,9 +47,16 @@
|
||||
.stat-value.brand { color: #00CED1; }
|
||||
.stat-value.gold { color: #FFD700; }
|
||||
.stat-value.orange { color: #FFA500; }
|
||||
.stat-value.gray { color: #9E9E9E; }
|
||||
.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; }
|
||||
|
||||
/* 访问量统计 */
|
||||
.visit-stat { display: flex; align-items: center; justify-content: center; gap: 12rpx; padding: 20rpx 32rpx; background: rgba(255,255,255,0.05); border-radius: 16rpx; margin-bottom: 24rpx; }
|
||||
.visit-label { font-size: 24rpx; color: rgba(255,255,255,0.5); }
|
||||
.visit-value { font-size: 32rpx; font-weight: 700; color: #00CED1; }
|
||||
.visit-tip { font-size: 24rpx; color: rgba(255,255,255,0.5); }
|
||||
|
||||
/* 推广规则 */
|
||||
.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; }
|
||||
.rules-header { display: flex; align-items: center; gap: 16rpx; margin-bottom: 16rpx; }
|
||||
|
||||
Reference in New Issue
Block a user