新增技术文档,详细描述了项目的技术栈、配置、鉴权与安全、数据层等内容。同时,更新小程序页面以支持收益数据的加载与刷新功能,优化用户体验。新增收益接口以返回用户的累计收益和可提现金额,并调整相关逻辑以确保数据准确性。

This commit is contained in:
2026-02-11 12:05:54 +08:00
parent a174d8e16d
commit 2c9364fd2f
11 changed files with 276 additions and 55 deletions

View File

@@ -20,8 +20,10 @@ Page({
totalSections: 62,
readCount: 0,
referralCount: 0,
earnings: 0,
pendingEarnings: 0,
earnings: '-',
pendingEarnings: '-',
earningsLoading: true,
earningsRefreshing: false,
// 阅读统计
totalReadTime: 0,
@@ -123,7 +125,7 @@ Page({
const userIdShort = userId.length > 20 ? userId.slice(0, 10) + '...' + userId.slice(-6) : userId
const userWechat = wx.getStorageSync('user_wechat') || userInfo.wechat || ''
// 先设基础信息;收益数据由 loadReferralEarnings 从推广中心同源接口拉取并覆盖
// 先设基础信息;收益由 loadMyEarnings 专用接口拉取,加载前用 - 占位
this.setData({
isLoggedIn: true,
userInfo,
@@ -131,12 +133,13 @@ Page({
userWechat,
readCount: Math.min(app.getReadCount(), this.data.totalSections || 62),
referralCount: userInfo.referralCount || 0,
earnings: '0.00',
pendingEarnings: '0.00',
earnings: '-',
pendingEarnings: '-',
earningsLoading: true,
recentChapters: recentList,
totalReadTime: Math.floor(Math.random() * 200) + 50
})
this.loadReferralEarnings()
this.loadMyEarnings()
this.loadPendingConfirm()
} else {
this.setData({
@@ -145,8 +148,9 @@ Page({
userIdShort: '',
readCount: app.getReadCount(),
referralCount: 0,
earnings: '0.00',
pendingEarnings: '0.00',
earnings: '-',
pendingEarnings: '-',
earningsLoading: false,
recentChapters: []
})
}
@@ -250,32 +254,48 @@ Page({
}
},
// 从与推广中心相同的接口拉取收益数据并更新展示(累计收益 = totalCommission可提现 = 累计-已提现-待审核
async loadReferralEarnings() {
// 专用接口拉取「我的收益」卡片数据(累计、可提现、推荐人数
async loadMyEarnings() {
const userInfo = app.globalData.userInfo
if (!app.globalData.isLoggedIn || !userInfo || !userInfo.id) return
if (!app.globalData.isLoggedIn || !userInfo || !userInfo.id) {
this.setData({ earningsLoading: false })
return
}
const formatMoney = (num) => (typeof num === 'number' ? num.toFixed(2) : '0.00')
try {
const res = await app.request('/api/miniprogram/referral/data?userId=' + userInfo.id)
if (!res || !res.success || !res.data) return
const res = await app.request('/api/miniprogram/earnings?userId=' + userInfo.id)
if (!res || !res.success || !res.data) {
this.setData({ earningsLoading: false, earnings: '0.00', pendingEarnings: '0.00' })
return
}
const d = res.data
const totalCommissionNum = d.totalCommission || 0
const withdrawnNum = d.withdrawnEarnings || 0
const pendingWithdrawNum = d.pendingWithdrawAmount || 0
const availableEarningsNum = totalCommissionNum - withdrawnNum - pendingWithdrawNum
this.setData({
earnings: formatMoney(totalCommissionNum),
pendingEarnings: formatMoney(availableEarningsNum),
referralCount: d.referralCount || d.stats?.totalBindings || this.data.referralCount
earnings: formatMoney(d.totalCommission),
pendingEarnings: formatMoney(d.availableEarnings),
referralCount: d.referralCount ?? this.data.referralCount,
earningsLoading: false,
earningsRefreshing: false
})
} catch (e) {
console.log('[My] 拉取推广收益失败:', e && e.message)
console.log('[My] 拉取我的收益失败:', e && e.message)
this.setData({
earningsLoading: false,
earningsRefreshing: false,
earnings: '0.00',
pendingEarnings: '0.00'
})
}
},
// 点击刷新图标:刷新我的收益
async refreshEarnings() {
if (!this.data.isLoggedIn) return
if (this.data.earningsRefreshing) return
this.setData({ earningsRefreshing: true })
wx.showToast({ title: '刷新中...', icon: 'loading', duration: 2000 })
await this.loadMyEarnings()
wx.showToast({ title: '已刷新', icon: 'success' })
},
// 微信原生获取头像button open-type="chooseAvatar" 回调)
async onChooseAvatar(e) {