赛事报名未支付不算支付成功

This commit is contained in:
马梓彭 2026-05-09 17:26:30 +08:00
parent ecd24de151
commit 162c49fc15
2 changed files with 43 additions and 5 deletions

View File

@ -694,6 +694,7 @@ Page({
const payload = this._validateAndGetPayload(2);
if (!payload) return;
let registrationId = null;
try {
// 1. 获取 openid
const openid = await this._getOpenId();
@ -702,9 +703,9 @@ Page({
return;
}
// 2. 提交报名
// 2. 提交报名(创建预报名记录)
this.setData({ submitting: true });
const registrationId = await this._submitApplyForPayment(payload);
registrationId = await this._submitApplyForPayment(payload);
// 3. 选择支付方式并获取支付参数
await this._selectPaymentMethod(registrationId, openid, 2);
@ -725,6 +726,16 @@ Page({
} catch (error) {
console.error('支付流程异常:', error);
// 如果已经创建了预报名记录,尝试取消
if (registrationId) {
try {
await this._cancelPreRegistration(registrationId);
} catch (cancelErr) {
console.error('取消预报名失败:', cancelErr);
}
}
wx.showToast({
title: error && error.message ? error.message : '支付失败,请稍后重试',
icon: 'none'
@ -843,14 +854,14 @@ Page({
try {
// 支付成功,同步支付状态
await request({
path: `/api/eventclient/sync-payment/${registrationId}`,
path: API.syncPayment(registrationId),
method: 'POST',
needAuth: true,
data: {},
contentType: 'application/json'
});
wx.showToast({ title: '支付成功', icon: 'success' });
wx.showToast({ title: '支付成功,报名完成', icon: 'success' });
setTimeout(() => {
wx.switchTab({ url: '/pages/home/home' });
}, 1500);
@ -868,8 +879,16 @@ Page({
resolve();
}
},
fail: (err) => {
fail: async (err) => {
console.error('微信支付失败:', err);
// 支付失败,尝试取消预报名记录
try {
await this._cancelPreRegistration(registrationId);
} catch (cancelErr) {
console.error('取消预报名失败:', cancelErr);
}
if (err.errMsg && err.errMsg.includes('cancel')) {
wx.showToast({ title: '支付已取消', icon: 'none' });
} else {
@ -884,6 +903,23 @@ Page({
});
},
/** 取消预报名记录 */
async _cancelPreRegistration(registrationId) {
try {
await request({
path: API.cancelRegistration(registrationId),
method: 'POST',
needAuth: true,
data: {},
contentType: 'application/json'
});
console.log('预报名记录已取消:', registrationId);
} catch (err) {
console.error('取消预报名失败:', err);
// 取消预报名失败不影响主要流程,仅记录日志
}
},
_submitApply(payload) {
this.setData({ submitting: true });
request({

View File

@ -14,6 +14,8 @@ const API = {
calculateAmount: '/api/eventclient/calculate-amount',
cancelRegistrationRefund: '/api/eventclient/cancel-registration-refund',
couponValidate: '/api/eventclient/coupon/validate',
syncPayment: (registrationId) => `/api/eventclient/sync-payment/${registrationId}`,
cancelRegistration: (registrationId) => `/api/eventclient/cancel/${registrationId}`,
wechatLogin: '/api/oauth/login',
loginByCode: '/api/oauth/login',