feat: 增加支付前订单状态和实际支付金额判断,避免不必要的微信支付。

This commit is contained in:
邹方成 2026-01-02 17:31:11 +08:00
parent 5cbd30fcb7
commit ed67c4f7fa
2 changed files with 39 additions and 29 deletions

View File

@ -289,24 +289,29 @@ async function onPaymentConfirm(paymentData) {
} }
// 2. 使 // 2. 使
const payRes = await createWechatOrder({ // Check if order is already paid (e.g. via Game Pass or Points)
openid: openid, const isPaid = (joinRes?.status === 2) || (joinRes?.actual_amount <= 0)
order_no: orderNo
})
// if (!isPaid) {
await new Promise((resolve, reject) => { const payRes = await createWechatOrder({
uni.requestPayment({ openid: openid,
provider: 'wxpay', order_no: orderNo
timeStamp: payRes.timeStamp || payRes.timestamp, })
nonceStr: payRes.nonceStr || payRes.noncestr,
package: payRes.package, //
signType: payRes.signType || 'MD5', await new Promise((resolve, reject) => {
paySign: payRes.paySign, uni.requestPayment({
success: resolve, provider: 'wxpay',
fail: reject timeStamp: payRes.timeStamp || payRes.timestamp,
}) nonceStr: payRes.nonceStr || payRes.noncestr,
}) package: payRes.package,
signType: payRes.signType || 'MD5',
paySign: payRes.paySign,
success: resolve,
fail: reject
})
})
}
uni.hideLoading() uni.hideLoading()
uni.showLoading({ title: '查询结果...' }) uni.showLoading({ title: '查询结果...' })

View File

@ -378,19 +378,24 @@ async function onMachineDraw(count) {
const orderNo = joinRes?.order_no || joinRes?.data?.order_no || joinRes?.result?.order_no const orderNo = joinRes?.order_no || joinRes?.data?.order_no || joinRes?.result?.order_no
if (!orderNo) throw new Error('未获取到订单号') if (!orderNo) throw new Error('未获取到订单号')
const payRes = await createWechatOrder({ openid, order_no: orderNo }) // Check if order is already paid (e.g. via Game Pass or Points)
await new Promise((resolve, reject) => { const isPaid = (joinRes?.status === 2) || (joinRes?.actual_amount <= 0)
uni.requestPayment({
provider: 'wxpay', if (!isPaid) {
timeStamp: payRes.timeStamp || payRes.timestamp, const payRes = await createWechatOrder({ openid, order_no: orderNo })
nonceStr: payRes.nonceStr || payRes.noncestr, await new Promise((resolve, reject) => {
package: payRes.package, uni.requestPayment({
signType: payRes.signType || 'MD5', provider: 'wxpay',
paySign: payRes.paySign, timeStamp: payRes.timeStamp || payRes.timestamp,
success: resolve, nonceStr: payRes.nonceStr || payRes.noncestr,
fail: reject package: payRes.package,
signType: payRes.signType || 'MD5',
paySign: payRes.paySign,
success: resolve,
fail: reject
})
}) })
}) }
// //
drawTotal.value = times drawTotal.value = times