From 88915276d160e8aadb912f1a85246e5efd31856a Mon Sep 17 00:00:00 2001
From: Alex-larget <33240357+Alex-larget@users.noreply.github.com>
Date: Tue, 17 Mar 2026 15:17:33 +0800
Subject: [PATCH 1/7] =?UTF-8?q?=E5=90=8C=E6=AD=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
miniprogram/app.js | 4 +-
miniprogram/pages/gift-pay/detail.js | 67 ++-
miniprogram/pages/gift-pay/detail.wxml | 117 ++++--
miniprogram/pages/gift-pay/detail.wxss | 515 +++++++++++++++++-------
miniprogram/project.private.config.json | 18 +-
miniprogram/yulan.html | 210 ++++++++++
soul-api/internal/handler/gift_pay.go | 48 ++-
soul-api/wechat/info.log | 34 ++
8 files changed, 778 insertions(+), 235 deletions(-)
create mode 100644 miniprogram/yulan.html
diff --git a/miniprogram/app.js b/miniprogram/app.js
index 74bc8bfb..12b88878 100644
--- a/miniprogram/app.js
+++ b/miniprogram/app.js
@@ -9,8 +9,8 @@ const { checkAndExecute } = require('./utils/ruleEngine.js')
App({
globalData: {
// API 基础地址(切换环境时注释/取消注释)
- baseUrl: 'https://soulapi.quwanzhi.com',
- // baseUrl: 'http://localhost:8080', // 本地调试
+ // baseUrl: 'https://soulapi.quwanzhi.com',
+ baseUrl: 'http://localhost:8080', // 本地调试
// baseUrl: 'https://souldev.quwanzhi.com', // 测试环境
diff --git a/miniprogram/pages/gift-pay/detail.js b/miniprogram/pages/gift-pay/detail.js
index 427c5b09..8932b101 100644
--- a/miniprogram/pages/gift-pay/detail.js
+++ b/miniprogram/pages/gift-pay/detail.js
@@ -11,7 +11,9 @@ Page({
detail: null,
loading: true,
paying: false,
- isInitiator: false // 是否发起人,发起人看到「分享给好友」UI,好友看到「帮他付款」
+ isInitiator: false,
+ requesterMsg: '',
+ amountDisplay: '0.00' // 预格式化金额,WXML 中 toFixed 可能不生效
},
onLoad(options) {
@@ -35,7 +37,13 @@ Page({
if (res && res.success) {
const myId = app.globalData.userInfo?.id || ''
const isInitiator = !!myId && res.initiatorUserId === myId
- this.setData({ detail: res, loading: false, isInitiator })
+ const requesterMsg = isInitiator
+ ? '分享给好友,好友打开后即可为你完成支付。'
+ : (res.initiatorMsg || `" 请帮我代付「${res.sectionTitle || res.description || '该商品'}」,非常感谢! "`)
+ const amountDisplay = (res.amount != null && res.amount !== '')
+ ? Number(res.amount).toFixed(2)
+ : '0.00'
+ this.setData({ detail: res, loading: false, isInitiator, requesterMsg, amountDisplay })
} else {
this.setData({ loading: false })
wx.showToast({ title: res?.error || '加载失败', icon: 'none' })
@@ -47,14 +55,24 @@ Page({
},
async doPay() {
- if (!app.globalData.isLoggedIn || !app.globalData.userInfo) {
- wx.showToast({ title: '请先登录', icon: 'none' })
- setTimeout(() => wx.switchTab({ url: '/pages/my/my' }), 1500)
- return
- }
- const openId = app.globalData.openId || ''
+ // 优先尝试静默获取 openId(有会话时可直接发起支付)
+ let openId = app.globalData.openId || wx.getStorageSync('openId')
if (!openId) {
- wx.showToast({ title: '请先完成微信授权', icon: 'none' })
+ wx.showLoading({ title: '获取支付凭证...', mask: true })
+ openId = await app.getOpenId()
+ wx.hideLoading()
+ }
+ if (!openId) {
+ const { confirm } = await new Promise(r => {
+ wx.showModal({
+ title: '请先登录',
+ content: '登录后可帮他完成代付',
+ confirmText: '去登录',
+ cancelText: '取消',
+ success: res => r(res)
+ })
+ })
+ if (confirm) wx.switchTab({ url: '/pages/my/my' })
return
}
const { requestSn, detail } = this.data
@@ -98,7 +116,22 @@ Page({
if (e.errMsg && e.errMsg.includes('cancel')) {
wx.showToast({ title: '已取消支付', icon: 'none' })
} else {
- wx.showToast({ title: e.message || e.error || '支付失败', icon: 'none' })
+ const errMsg = e.message || e.error || '支付失败'
+ const isPrepayError = /prepay_id|创建订单|支付请求/i.test(errMsg)
+ if (isPrepayError) {
+ const { confirm } = await new Promise(r => {
+ wx.showModal({
+ title: '订单创建失败',
+ content: errMsg + '\n\n是否重新创建订单并重试?',
+ confirmText: '重新创建订单',
+ cancelText: '取消',
+ success: res => r(res)
+ })
+ })
+ if (confirm) this.doPay()
+ } else {
+ wx.showToast({ title: errMsg, icon: 'none' })
+ }
}
}
},
@@ -107,6 +140,20 @@ Page({
app.goBackOrToHome()
},
+ goToInitiatorProfile() {
+ const { detail } = this.data
+ if (!detail?.initiatorUserId) return
+ wx.navigateTo({ url: `/pages/member-detail/member-detail?id=${detail.initiatorUserId}` })
+ },
+
+ goToArticle() {
+ const { detail } = this.data
+ if (!detail || detail.productType !== 'section' || !detail.productId) return
+ const mid = detail.productMid || app.getSectionMid?.(detail.productId)
+ const q = mid ? `mid=${mid}` : `id=${detail.productId}`
+ wx.navigateTo({ url: `/pages/read/read?${q}` })
+ },
+
onShareAppMessage() {
const { requestSn } = this.data
return {
diff --git a/miniprogram/pages/gift-pay/detail.wxml b/miniprogram/pages/gift-pay/detail.wxml
index 08e5b1f5..f6cc715f 100644
--- a/miniprogram/pages/gift-pay/detail.wxml
+++ b/miniprogram/pages/gift-pay/detail.wxml
@@ -1,4 +1,4 @@
-
+
=ec),uy=" ",hy=!1;function fy(l,d){switch(l){case"keyup":return f3.indexOf(d.keyCode)!==-1;case"keydown":return d.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function py(l){return l=l.detail,typeof l=="object"&&"data"in l?l.data:null}var Lo=!1;function m3(l,d){switch(l){case"compositionend":return py(d);case"keypress":return d.which!==32?null:(hy=!0,uy);case"textInput":return l=d.data,l===uy&&hy?null:l;default:return null}}function g3(l,d){if(Lo)return l==="compositionend"||!Zf&&fy(l,d)?(l=ay(),Ed=qf=Da=null,Lo=!1,l):null;switch(l){case"paste":return null;case"keypress":if(!(d.ctrlKey||d.altKey||d.metaKey)||d.ctrlKey&&d.altKey){if(d.char&&1 <\/script>",l=l.removeChild(l.firstChild)):typeof x.is=="string"?l=A.createElement(p,{is:x.is}):(l=A.createElement(p),p==="select"&&(A=l,x.multiple?A.multiple=!0:x.size&&(A.size=x.size))):l=A.createElementNS(l,p),l[Ds]=d,l[lc]=x,Hb(l,d,!1,!1),d.stateNode=l;e:{switch(A=As(p,x),p){case"dialog":qt("cancel",l),qt("close",l),j=x;break;case"iframe":case"object":case"embed":qt("load",l),j=x;break;case"video":case"audio":for(j=0;j