新增技术文档,详细描述了项目的技术栈、配置、鉴权与安全、数据层等内容。同时,更新小程序页面以支持收益数据的加载与刷新功能,优化用户体验。新增收益接口以返回用户的累计收益和可提现金额,并调整相关逻辑以确保数据准确性。
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -97,27 +97,26 @@
|
||||
<view class="bg-decoration bg-decoration-brand"></view>
|
||||
|
||||
<view class="earnings-content">
|
||||
<!-- 标题行 -->
|
||||
<!-- 标题行:右侧为刷新图标 -->
|
||||
<view class="earnings-header">
|
||||
<view class="earnings-title-wrap">
|
||||
<text class="earnings-icon">💰</text>
|
||||
<text class="earnings-title">我的收益</text>
|
||||
</view>
|
||||
<view class="earnings-link" bindtap="goToReferral">
|
||||
<text class="link-text brand-color">推广中心</text>
|
||||
<text class="link-arrow brand-color">↗</text>
|
||||
<view class="earnings-refresh-wrap" bindtap="refreshEarnings">
|
||||
<text class="earnings-refresh-icon {{earningsRefreshing ? 'earnings-refresh-spin' : ''}}">↻</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 收益数据 -->
|
||||
<!-- 收益数据:加载中显示 - 占位 -->
|
||||
<view class="earnings-data">
|
||||
<view class="earnings-main">
|
||||
<text class="earnings-label">累计收益</text>
|
||||
<text class="earnings-amount-large gold-gradient">¥{{earnings}}</text>
|
||||
<text class="earnings-amount-large gold-gradient">{{earningsLoading ? '-' : '¥' + earnings}}</text>
|
||||
</view>
|
||||
<view class="earnings-secondary">
|
||||
<text class="earnings-label">可提现</text>
|
||||
<text class="earnings-amount-medium">¥{{pendingEarnings}}</text>
|
||||
<text class="earnings-amount-medium">{{earningsLoading ? '-' : '¥' + pendingEarnings}}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
|
||||
@@ -471,6 +471,36 @@
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* 我的收益 - 刷新图标 */
|
||||
.earnings-refresh-wrap {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 64rpx;
|
||||
height: 64rpx;
|
||||
border-radius: 50%;
|
||||
background: rgba(0, 206, 209, 0.15);
|
||||
}
|
||||
|
||||
.earnings-refresh-wrap:active {
|
||||
background: rgba(0, 206, 209, 0.3);
|
||||
}
|
||||
|
||||
.earnings-refresh-icon {
|
||||
font-size: 36rpx;
|
||||
font-weight: 600;
|
||||
color: #00CED1;
|
||||
}
|
||||
|
||||
.earnings-refresh-spin {
|
||||
animation: earnings-spin 0.8s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes earnings-spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
/* 收益数据 */
|
||||
.earnings-data {
|
||||
display: flex;
|
||||
|
||||
Reference in New Issue
Block a user