fix: 全面优化小程序功能

🔧 数据库配置:
- 切换到腾讯云外网数据库
- 配置连接参数和连接池

🎨 界面优化:
- 未登录时只显示登录按钮,隐藏其他功能
- 优化登录卡片样式
- 修复章节图标和标题对齐问题

💳 支付流程优化:
- 增加重复购买检测,避免重复支付
- 优化openId获取逻辑,支持静默获取
- 已登录用户可直接支付,无需重复登录

📊 后台管理:
- 创建章节管理API (/api/admin/chapters)
- 创建章节管理页面 (/admin/chapters)
- 支持查看所有章节、修改价格、设置免费状态
This commit is contained in:
卡若
2026-01-23 17:25:15 +08:00
parent 1e1e6a1093
commit 7ff181f743
11 changed files with 1131 additions and 254 deletions

View File

@@ -363,6 +363,20 @@ ${id === 'preface' || id === 'epilogue' || id.startsWith('appendix') || id === '
// 处理支付 - 调用真实微信支付接口
async processPayment(type, sectionId, amount) {
// 检查是否已购买(避免重复购买)
if (type === 'section' && sectionId) {
const purchasedSections = app.globalData.purchasedSections || []
if (purchasedSections.includes(sectionId)) {
wx.showToast({ title: '已购买过此章节', icon: 'none' })
return
}
}
if (type === 'fullbook' && app.globalData.hasFullBook) {
wx.showToast({ title: '已购买全书', icon: 'none' })
return
}
this.setData({ isPaying: true })
try {
@@ -370,17 +384,23 @@ ${id === 'preface' || id === 'epilogue' || id.startsWith('appendix') || id === '
let openId = app.globalData.openId || wx.getStorageSync('openId')
if (!openId) {
console.log('[Pay] 需要先获取openId')
console.log('[Pay] 需要先获取openId,尝试静默获取')
openId = await app.getOpenId()
if (!openId) {
wx.showModal({
title: '提示',
content: '需要登录后才能支付,请先登录',
showCancel: false
})
this.setData({ showLoginModal: true, isPaying: false })
return
// openId获取失败但已登录用户可以使用用户ID替代
if (app.globalData.isLoggedIn && app.globalData.userInfo?.id) {
console.log('[Pay] 使用用户ID作为替代')
openId = app.globalData.userInfo.id
} else {
wx.showModal({
title: '提示',
content: '需要登录后才能支付,请先登录',
showCancel: false
})
this.setData({ showLoginModal: true, isPaying: false })
return
}
}
}