更新开发配置,调整项目路径以支持新环境。同时,优化提现管理API,增强安全性和错误处理逻辑,确保数据一致性和用户体验。重构数据库查询逻辑,提升性能和可维护性。

This commit is contained in:
乘风
2026-02-06 15:18:36 +08:00
parent 678bf297aa
commit f8fac00c85
7 changed files with 407 additions and 671 deletions

View File

@@ -98,7 +98,7 @@ Page({
// 初始化用户状态
initUserStatus() {
const { isLoggedIn, userInfo, hasFullBook, purchasedSections } = app.globalData
const { isLoggedIn, userInfo } = app.globalData
if (isLoggedIn && userInfo) {
const readIds = app.globalData.readSectionIds || []
@@ -107,17 +107,11 @@ Page({
title: `章节 ${id}`
}))
// 截短用户ID显示
const userId = userInfo.id || ''
const userIdShort = userId.length > 20 ? userId.slice(0, 10) + '...' + userId.slice(-6) : userId
// 获取微信号(优先显示)
const userWechat = wx.getStorageSync('user_wechat') || userInfo.wechat || ''
// 格式化收益金额(保留两位小数)
const earnings = Number(userInfo.earnings || 0)
const pendingEarnings = Number(userInfo.pendingEarnings || 0)
// 先设基础信息;收益数据由 loadReferralEarnings 从推广中心同源接口拉取并覆盖
this.setData({
isLoggedIn: true,
userInfo,
@@ -125,11 +119,12 @@ Page({
userWechat,
readCount: Math.min(app.getReadCount(), this.data.totalSections || 62),
referralCount: userInfo.referralCount || 0,
earnings: earnings.toFixed(2),
pendingEarnings: pendingEarnings.toFixed(2),
earnings: '0.00',
pendingEarnings: '0.00',
recentChapters: recentList,
totalReadTime: Math.floor(Math.random() * 200) + 50
})
this.loadReferralEarnings()
} else {
this.setData({
isLoggedIn: false,
@@ -143,6 +138,33 @@ Page({
})
}
},
// 从与推广中心相同的接口拉取收益数据并更新展示(累计收益 = totalCommission可提现 = 累计-已提现-待审核)
async loadReferralEarnings() {
const userInfo = app.globalData.userInfo
if (!app.globalData.isLoggedIn || !userInfo || !userInfo.id) return
const formatMoney = (num) => (typeof num === 'number' ? num.toFixed(2) : '0.00')
try {
const res = await app.request('/api/referral/data?userId=' + userInfo.id)
if (!res || !res.success || !res.data) 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
})
} catch (e) {
console.log('[My] 拉取推广收益失败:', e && e.message)
}
},
// 微信原生获取头像button open-type="chooseAvatar" 回调)
async onChooseAvatar(e) {