fix: 优化支付失败提示+内容加载降级方案

1. 分享按钮精简为2个(推荐给好友+生成海报)
2. 章节内容三级降级:API→本地缓存→重试
3. 移除审核敏感文案(佣金/返利等)
4. 支付失败时显示客服微信号
This commit is contained in:
卡若
2026-01-25 21:29:04 +08:00
parent ac24853aa6
commit 5501397542
6 changed files with 123 additions and 54 deletions

View File

@@ -36,7 +36,7 @@ Page({
// 菜单列表
menuList: [
{ id: 'orders', title: '我的订单', icon: '📦', count: 0 },
{ id: 'referral', title: '推广中心', icon: '🎁', badge: '90%佣金' },
{ id: 'referral', title: '推广中心', icon: '🎁', badge: '' },
{ id: 'about', title: '关于作者', icon: '👤', iconBg: 'brand' },
{ id: 'settings', title: '设置', icon: '⚙️', iconBg: 'gray' }
],

View File

@@ -16,7 +16,7 @@
<view class="login-prompt">
<view class="login-icon-large">🔐</view>
<text class="login-title">登录 Soul创业实验</text>
<text class="login-desc">登录后可购买章节、参与匹配、赚取佣金</text>
<text class="login-desc">登录后可购买章节、解锁更多内容</text>
<button class="btn-wechat-large" bindtap="handleWechatLogin">
<text class="btn-icon">微</text>
<text>微信快捷登录</text>
@@ -176,7 +176,7 @@
<view class="modal-close" bindtap="closeLoginModal">✕</view>
<view class="login-icon">🔐</view>
<text class="login-title">登录 Soul创业实验</text>
<text class="login-desc">登录后可购买章节、参与匹配、赚取佣金</text>
<text class="login-desc">登录后可购买章节、解锁更多内容</text>
<button
class="btn-wechat"

View File

@@ -188,58 +188,119 @@ Page({
return titles[id] || `章节 ${id}`
},
// 加载内容 - 从真实API读取章节内容
// 加载内容 - 三级降级方案API → 本地缓存 → 备用API
async loadContent(id) {
const cacheKey = `chapter_${id}`
// 1. 优先从API获取
try {
// 从API获取真实章节内容
const res = await app.request(`/api/book/chapter/${id}`)
const res = await this.fetchChapterWithTimeout(id, 5000)
if (res && res.content) {
const lines = res.content.split('\n').filter(line => line.trim())
const previewCount = Math.ceil(lines.length * 0.2)
this.setData({
content: res.content,
previewContent: lines.slice(0, previewCount).join('\n'),
contentParagraphs: lines,
previewParagraphs: lines.slice(0, previewCount),
partTitle: res.partTitle || '',
chapterTitle: res.chapterTitle || ''
})
console.log('[Read] 成功加载章节内容:', id)
this.setChapterContent(res)
// 成功后缓存到本地
wx.setStorageSync(cacheKey, res)
console.log('[Read] 从API加载成功:', id)
return
}
} catch (e) {
console.error('[Read] API加载章节失败:', e.message)
console.warn('[Read] API加载失败,尝试本地缓存:', e.message)
}
// API失败时显示提示,不使用假内容
// 2. API失败,尝试从本地缓存读取
try {
const cached = wx.getStorageSync(cacheKey)
if (cached && cached.content) {
this.setChapterContent(cached)
console.log('[Read] 从本地缓存加载成功:', id)
// 后台静默刷新
this.silentRefresh(id)
return
}
} catch (e) {
console.warn('[Read] 本地缓存读取失败')
}
// 3. 都失败,显示加载中并持续重试
this.setData({
content: '章节内容加载中,请稍候...',
previewContent: '章节内容加载中,请稍候...',
contentParagraphs: ['章节内容加载中,请稍候...', '如果长时间无法加载,请检查网络连接后刷新页面。'],
previewParagraphs: ['章节内容加载中,请稍候...']
contentParagraphs: ['章节内容加载中...', '正在尝试连接服务器,请稍候...'],
previewParagraphs: ['章节内容加载中...']
})
// 延迟重试一次
// 延迟重试最多3次
this.retryLoadContent(id, 3)
},
// 带超时的章节请求
fetchChapterWithTimeout(id, timeout = 5000) {
return new Promise((resolve, reject) => {
const timer = setTimeout(() => {
reject(new Error('请求超时'))
}, timeout)
app.request(`/api/book/chapter/${id}`)
.then(res => {
clearTimeout(timer)
resolve(res)
})
.catch(err => {
clearTimeout(timer)
reject(err)
})
})
},
// 设置章节内容
setChapterContent(res) {
const lines = res.content.split('\n').filter(line => line.trim())
const previewCount = Math.ceil(lines.length * 0.2)
this.setData({
content: res.content,
previewContent: lines.slice(0, previewCount).join('\n'),
contentParagraphs: lines,
previewParagraphs: lines.slice(0, previewCount),
partTitle: res.partTitle || '',
chapterTitle: res.chapterTitle || ''
})
},
// 静默刷新(后台更新缓存)
async silentRefresh(id) {
try {
const res = await this.fetchChapterWithTimeout(id, 10000)
if (res && res.content) {
wx.setStorageSync(`chapter_${id}`, res)
console.log('[Read] 后台缓存更新成功:', id)
}
} catch (e) {
// 静默失败不处理
}
},
// 重试加载
retryLoadContent(id, maxRetries, currentRetry = 0) {
if (currentRetry >= maxRetries) {
this.setData({
contentParagraphs: ['内容加载失败', '请检查网络连接后下拉刷新重试'],
previewParagraphs: ['内容加载失败']
})
return
}
setTimeout(async () => {
try {
const res = await app.request(`/api/book/chapter/${id}`)
const res = await this.fetchChapterWithTimeout(id, 8000)
if (res && res.content) {
const lines = res.content.split('\n').filter(line => line.trim())
const previewCount = Math.ceil(lines.length * 0.2)
this.setData({
content: res.content,
previewContent: lines.slice(0, previewCount).join('\n'),
contentParagraphs: lines,
previewParagraphs: lines.slice(0, previewCount),
partTitle: res.partTitle || '',
chapterTitle: res.chapterTitle || ''
})
this.setChapterContent(res)
wx.setStorageSync(`chapter_${id}`, res)
console.log('[Read] 重试成功:', id, '第', currentRetry + 1, '次')
return
}
} catch (e) {
console.error('[Read] 重试加载失败:', e.message)
console.warn('[Read] 重试失败,继续重试:', currentRetry + 1)
}
}, 2000)
this.retryLoadContent(id, maxRetries, currentRetry + 1)
}, 2000 * (currentRetry + 1))
},
@@ -483,7 +544,23 @@ Page({
}
} catch (apiError) {
console.error('[Pay] API创建订单失败:', apiError.message)
wx.showToast({ title: '支付服务暂时不可用,请稍后重试', icon: 'none', duration: 3000 })
// 支付接口失败时,显示客服联系方式
wx.showModal({
title: '支付通道维护中',
content: '微信支付正在审核中请添加客服微信28533368手动购买感谢理解',
confirmText: '复制微信号',
cancelText: '稍后再说',
success: (res) => {
if (res.confirm) {
wx.setClipboardData({
data: '28533368',
success: () => {
wx.showToast({ title: '微信号已复制', icon: 'success' })
}
})
}
}
})
this.setData({ isPaying: false })
return
}
@@ -653,7 +730,7 @@ Page({
ctx.fillText('长按识别小程序码', 20, height - 60)
ctx.setFillStyle('rgba(255,255,255,0.6)')
ctx.setFontSize(11)
ctx.fillText('阅读全文 · 好友购买你获90%收益', 20, height - 38)
ctx.fillText('长按小程序码阅读全文', 20, height - 38)
// 绘制小程序码或占位符
const drawQRCode = () => {

View File

@@ -85,15 +85,11 @@
<view class="action-row-inline">
<button class="action-btn-inline btn-share-inline" open-type="share">
<text class="action-icon-small">💬</text>
<text class="action-text-small">分享</text>
<text class="action-text-small">推荐给好友</text>
</button>
<view class="action-btn-inline btn-poster-inline" bindtap="generatePoster">
<text class="action-icon-small">🖼️</text>
<text class="action-text-small">海报</text>
</view>
<view class="action-btn-inline btn-copy-inline" bindtap="copyShareText">
<text class="action-icon-small">📝</text>
<text class="action-text-small">文案</text>
<text class="action-text-small">生成海报</text>
</view>
</view>
</view>
@@ -146,7 +142,7 @@
</view>
</view>
<text class="paywall-tip">邀请好友加入享90%推广收益</text>
<text class="paywall-tip">分享给好友一起学习</text>
</view>
<!-- 章节导航 - 付费内容也显示 -->
@@ -211,7 +207,7 @@
<view class="modal-close" bindtap="closeLoginModal">✕</view>
<view class="login-icon">🔐</view>
<text class="login-title">登录 Soul创业派对</text>
<text class="login-desc">登录后可购买章节、参与匹配、赚取佣金</text>
<text class="login-desc">登录后可购买章节、解锁更多内容</text>
<button class="btn-wechat" bindtap="handleWechatLogin">
<text class="btn-wechat-icon">微</text>

View File

@@ -434,10 +434,6 @@
border: 2rpx solid rgba(255, 215, 0, 0.3);
}
.btn-copy-inline {
background: rgba(0, 206, 209, 0.15);
border: 2rpx solid rgba(0, 206, 209, 0.3);
}
.action-icon-small {
font-size: 28rpx;

View File

@@ -206,7 +206,7 @@ Page({
// 统计数据
ctx.setFillStyle('rgba(255,255,255,0.6)')
ctx.setFontSize(11)
ctx.fillText(`已推荐 ${referralCount} 人 · 累计收益 ¥${parseFloat(earnings || 0).toFixed(0)}`, 20, 245)
ctx.fillText(`已推荐 ${referralCount} 位好友阅读`, 20, 245)
// 优惠信息
ctx.setFillStyle('rgba(255,215,0,0.15)')
@@ -228,7 +228,7 @@ Page({
ctx.fillText('长按识别 立即购买', 20, height - 50)
ctx.setFillStyle('rgba(255,255,255,0.6)')
ctx.setFontSize(11)
ctx.fillText(`推广返利 ${distributorShare}%`, 20, height - 28)
ctx.fillText('扫码立即阅读', 20, height - 28)
// 绘制小程序码
const drawQRCode = () => {