优化提现流程,新增用户确认模式以支持待用户确认的转账,更新相关API和数据库结构以确保数据一致性。同时,调整小程序界面以展示待确认收款信息,提升用户体验。

This commit is contained in:
2026-02-06 19:45:24 +08:00
parent 2e65d68e1e
commit 8e67eb5d62
19 changed files with 649 additions and 95 deletions

View File

@@ -40,9 +40,15 @@ Page({
menuList: [
{ id: 'orders', title: '我的订单', icon: '📦', count: 0 },
{ id: 'referral', title: '推广中心', icon: '🎁', iconBg: 'gold', badge: '90%佣金' },
{ id: 'withdrawRecords', title: '提现记录', icon: '📋', iconBg: 'gray' },
{ id: 'about', title: '关于作者', icon: '', iconBg: 'brand' },
{ id: 'settings', title: '设置', icon: '⚙️', iconBg: 'gray' }
],
// 待确认收款(用户确认模式)
pendingConfirmList: [],
withdrawMchId: '',
withdrawAppId: '',
// 登录弹窗
showLoginModal: false,
@@ -125,6 +131,7 @@ Page({
totalReadTime: Math.floor(Math.random() * 200) + 50
})
this.loadReferralEarnings()
this.loadPendingConfirm()
} else {
this.setData({
isLoggedIn: false,
@@ -139,6 +146,82 @@ Page({
}
},
// 拉取待确认收款列表(用于「确认收款」按钮)
async loadPendingConfirm() {
const userInfo = app.globalData.userInfo
if (!app.globalData.isLoggedIn || !userInfo || !userInfo.id) return
try {
const res = await app.request('/api/withdraw/pending-confirm?userId=' + userInfo.id)
if (res && res.success && res.data) {
const list = (res.data.list || []).map(item => ({
id: item.id,
amount: (item.amount || 0).toFixed(2),
package: item.package,
created_at: item.created_at ? this.formatDateMy(item.created_at) : '--'
}))
this.setData({
pendingConfirmList: list,
withdrawMchId: res.data.mch_id || '',
withdrawAppId: res.data.app_id || ''
})
} else {
this.setData({ pendingConfirmList: [], withdrawMchId: '', withdrawAppId: '' })
}
} catch (e) {
this.setData({ pendingConfirmList: [] })
}
},
formatDateMy(dateStr) {
if (!dateStr) return '--'
const d = new Date(dateStr)
const m = (d.getMonth() + 1).toString().padStart(2, '0')
const day = d.getDate().toString().padStart(2, '0')
return `${m}-${day}`
},
// 确认收款(调起微信收款页)
confirmReceive(e) {
const index = e.currentTarget.dataset.index
const id = e.currentTarget.dataset.id
const list = this.data.pendingConfirmList || []
let item = (typeof index === 'number' || (index !== undefined && index !== '')) ? list[index] : null
if (!item && id) item = list.find(x => x.id === id) || null
if (!item || !item.package) {
wx.showToast({ title: '请稍后刷新再试', icon: 'none' })
return
}
const mchId = this.data.withdrawMchId
const appId = this.data.withdrawAppId
if (!mchId || !appId) {
wx.showToast({ title: '参数缺失,请刷新重试', icon: 'none' })
return
}
if (!wx.canIUse('requestMerchantTransfer')) {
wx.showToast({ title: '当前微信版本不支持,请升级后重试', icon: 'none' })
return
}
wx.showLoading({ title: '调起收款...', mask: true })
wx.requestMerchantTransfer({
mchId,
appId,
package: item.package,
success: () => {
wx.hideLoading()
wx.showToast({ title: '收款成功', icon: 'success' })
const newList = list.filter(x => x.id !== item.id)
this.setData({ pendingConfirmList: newList })
this.loadPendingConfirm()
},
fail: (err) => {
wx.hideLoading()
const msg = (err.errMsg || '').includes('cancel') ? '已取消' : (err.errMsg || '收款失败')
wx.showToast({ title: msg, icon: 'none' })
},
complete: () => { wx.hideLoading() }
})
},
// 从与推广中心相同的接口拉取收益数据并更新展示(累计收益 = totalCommission可提现 = 累计-已提现-待审核)
async loadReferralEarnings() {
const userInfo = app.globalData.userInfo
@@ -438,6 +521,7 @@ Page({
const routes = {
orders: '/pages/purchases/purchases',
referral: '/pages/referral/referral',
withdrawRecords: '/pages/withdraw-records/withdraw-records',
about: '/pages/about/about',
settings: '/pages/settings/settings'
}