免费赛事跳过支付流程

This commit is contained in:
马梓彭 2026-05-11 16:59:15 +08:00
parent 318408237a
commit 4486d2abc3

View File

@ -694,6 +694,38 @@ Page({
const payload = this._validateAndGetPayload(2);
if (!payload) return;
// 判断是否为免费赛事
const isFree = this.data.totalPrice <= 0;
if (isFree) {
// 免费赛事:直接显示确认弹窗
wx.showModal({
title: '确认报名',
content: '确定要报名参加本次赛事吗?',
success: async (res) => {
if (res.confirm) {
try {
this.setData({ submitting: true });
// 免费赛事直接提交报名
await this._submitApply(payload);
} catch (error) {
console.error('免费报名异常:', error);
wx.showToast({
title: error && error.message ? error.message : '报名失败,请稍后重试',
icon: 'none'
});
} finally {
this.setData({ submitting: false });
}
}
}
});
return;
}
// 收费赛事:走原有支付流程
let registrationId = null;
try {
// 1. 获取 openid
@ -714,14 +746,24 @@ Page({
const paymentInfo = await this._getPaymentInfo(registrationId, openid);
console.log('获取的支付信息:', paymentInfo);
// 5. 检查支付参数是否存在
// 5. 检查是否为免费(后端可能有优惠导致免费)
if (paymentInfo.isFree || (paymentInfo.actualAmount != null && paymentInfo.actualAmount <= 0)) {
// 免费:直接提示成功
wx.showToast({ title: '报名成功', icon: 'success' });
setTimeout(() => {
wx.switchTab({ url: '/pages/home/home' });
}, 1500);
return;
}
// 6. 检查支付参数是否存在
const wechatPayParams = paymentInfo.wechatPayParams || paymentInfo.WechatPayParams;
if (!wechatPayParams || !wechatPayParams.paySign) {
console.error('支付参数异常:', wechatPayParams);
throw new Error('获取支付参数失败,请稍后重试');
}
// 6. 调起微信支付
// 7. 调起微信支付
await this._invokeWeChatPay(wechatPayParams, registrationId);
} catch (error) {