优化支付逻辑、防止用户连击
This commit is contained in:
@@ -31,6 +31,7 @@ Page({
|
||||
isGoHome: false,
|
||||
welcomeMsg: '',
|
||||
isRequesting: false,
|
||||
isPaying: false,
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -120,69 +121,7 @@ Page({
|
||||
});
|
||||
},
|
||||
|
||||
checkIsPayed(orderSn) {
|
||||
this.setData({
|
||||
flg: 777,
|
||||
msg: '正在查询支付结果...'
|
||||
})
|
||||
let that = this;
|
||||
setTimeout(function () {
|
||||
app.$api.memberIsPayed({
|
||||
orderSn: orderSn
|
||||
}).then(res => {
|
||||
if (res.isPayed) {
|
||||
that.setData({
|
||||
flg: 0,
|
||||
msg: ''
|
||||
})
|
||||
that.openDoor(orderSn, that.data.venues.enterFlag != '1')
|
||||
} else {
|
||||
that.setData({
|
||||
flg: 777,
|
||||
msg: '正在确认支付结果,请勿退出...'
|
||||
})
|
||||
//第二次
|
||||
setTimeout(function () {
|
||||
app.$api.memberIsPayed({
|
||||
orderSn: orderSn
|
||||
}).then(res => {
|
||||
if (res.isPayed) {
|
||||
that.setData({
|
||||
flg: 0,
|
||||
msg: ''
|
||||
})
|
||||
that.openDoor(orderSn, that.data.venues.enterFlag != '1')
|
||||
} else {
|
||||
that.setData({
|
||||
flg: 777,
|
||||
msg: '最后一次确认订单状态...'
|
||||
})
|
||||
// 第三次
|
||||
setTimeout(function () {
|
||||
app.$api.memberIsPayed({
|
||||
orderSn: orderSn
|
||||
}).then(res => {
|
||||
if (res.isPayed) {
|
||||
that.setData({
|
||||
flg: 0,
|
||||
msg: ''
|
||||
})
|
||||
that.openDoor(orderSn, that.data.venues.enterFlag != '1')
|
||||
} else {
|
||||
that.setData({
|
||||
flg: 999,
|
||||
msg: '订单未成功支付'
|
||||
})
|
||||
}
|
||||
});
|
||||
}, 5000)
|
||||
}
|
||||
});
|
||||
}, 5000)
|
||||
}
|
||||
});
|
||||
}, 5000)
|
||||
},
|
||||
// 原 checkIsPayed 轮询废弃,已由 venueJoin / venueOut 接口主动状态校验代替
|
||||
|
||||
// 打开导航,
|
||||
opnGPS() {
|
||||
@@ -256,7 +195,7 @@ Page({
|
||||
type: 'wgs84',
|
||||
success: (locRes) => {
|
||||
let distance = getDistance(locRes.latitude, locRes.longitude, Number(this.data.venues.latitude), Number(this.data.venues.longitude));
|
||||
if (distance > 90000) {
|
||||
if (distance > 40000) {
|
||||
this.setData({ isRequesting: false });
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
@@ -275,7 +214,15 @@ Page({
|
||||
isRequesting: false
|
||||
})
|
||||
if (res.join.flg == 0) {
|
||||
this.openDoor('000', true)
|
||||
if (res.join.order_sn) {
|
||||
this.openDoor(res.join.order_sn, true)
|
||||
} else {
|
||||
console.log('已在场内,无操作')
|
||||
this.setData({
|
||||
flg: 100
|
||||
})
|
||||
wx.showToast({ title: '您已在场内', icon: 'none' });
|
||||
}
|
||||
}
|
||||
}, err => {
|
||||
this.setData({ isRequesting: false });
|
||||
@@ -311,7 +258,7 @@ Page({
|
||||
isRequesting: false
|
||||
})
|
||||
if (res.out.flg == 0) {
|
||||
this.openDoor('000', false)
|
||||
this.openDoor(res.out.order_sn || '000', false)
|
||||
}
|
||||
}, err => {
|
||||
console.log(err);
|
||||
@@ -396,6 +343,10 @@ Page({
|
||||
|
||||
// 关闭提示框
|
||||
cancelDeleteDialog() {
|
||||
if (this.data.isPaying) {
|
||||
wx.showToast({ title: '订单处理中,请稍后', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
this.setData({
|
||||
flg: 100
|
||||
})
|
||||
@@ -403,32 +354,58 @@ Page({
|
||||
|
||||
// 点击提示框确认
|
||||
confirmDeleteDialog() {
|
||||
if (this.data.isPaying) return; // 防重复点击
|
||||
this.setData({ isPaying: true });
|
||||
wx.showLoading({ title: '正在处理订单...', mask: true }); // 物理锁死屏幕
|
||||
|
||||
// 去支付
|
||||
app.$api.basketOrder({
|
||||
venueId: this.data.venues.id,
|
||||
enterFlag: this.data.venues.enterFlag,
|
||||
payMoney: this.data.payMoney
|
||||
}).then(res => {
|
||||
// 如果后端判定这笔订单已经支付,直接开门
|
||||
if (res.paid_flag) {
|
||||
wx.hideLoading();
|
||||
this.setData({ isPaying: false, flg: 0, msg: '' });
|
||||
this.openDoor(res.order_sn, this.data.venues.enterFlag != '1');
|
||||
return;
|
||||
}
|
||||
|
||||
// 未支付,拿到单号拉起微信支付
|
||||
let orderSn = res.order_sn || (res.pay && res.pay.orderSn);
|
||||
this.setData({
|
||||
orderSn: res.pay.orderSn,
|
||||
flg: 777,
|
||||
msg: '正在支付...'
|
||||
orderSn: orderSn
|
||||
})
|
||||
app.$pay.wxPay(res.pay).then(res => {
|
||||
console.log('支付成功了')
|
||||
this.checkIsPayed(this.data.orderSn)
|
||||
wx.hideLoading(); // 隐藏下单的 Loading
|
||||
|
||||
app.$pay.wxPay(res.pay).then(wxRes => {
|
||||
console.log('支付成功了');
|
||||
this.setData({ isPaying: false, isRequesting: false });
|
||||
wx.showLoading({ title: '确认支付结果...', mask: true });
|
||||
if (this.data.venues.enterFlag == '1') {
|
||||
this.out();
|
||||
} else {
|
||||
this.enter();
|
||||
}
|
||||
}, err => {
|
||||
console.log('支付失败')
|
||||
this.setData({
|
||||
flg: 999,
|
||||
msg: '支付失败,用户取消支付'
|
||||
})
|
||||
console.log('支付失败');
|
||||
this.setData({ isPaying: false, isRequesting: false });
|
||||
if (this.data.venues.enterFlag == '1') {
|
||||
this.out();
|
||||
} else {
|
||||
this.enter();
|
||||
}
|
||||
})
|
||||
}, err => {
|
||||
if (err.data.err_code == 30022) {
|
||||
this.setData({ isPaying: false });
|
||||
wx.hideLoading();
|
||||
if (err.data && err.data.err_code == 30022) {
|
||||
this.setData({
|
||||
isWxLogin: true,
|
||||
})
|
||||
} else {
|
||||
wx.showToast({ title: '网络异常,请重试', icon: 'none' });
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
@@ -38,10 +38,17 @@
|
||||
"packNpmManually": false,
|
||||
"packNpmRelationList": [],
|
||||
"minifyWXSS": true,
|
||||
"condition": false
|
||||
"condition": false,
|
||||
"compileWorklet": false,
|
||||
"minifyWXML": true,
|
||||
"localPlugins": false,
|
||||
"disableUseStrict": false,
|
||||
"useCompilerPlugins": false,
|
||||
"swc": false,
|
||||
"disableSWC": true
|
||||
},
|
||||
"compileType": "miniprogram",
|
||||
"libVersion": "2.17.0",
|
||||
"libVersion": "2.27.3",
|
||||
"appid": "wx73eb8a9ed10a029d",
|
||||
"projectname": "%E6%99%BA%E6%85%A7%E4%BA%91%E9%A6%86",
|
||||
"simulatorType": "wechat",
|
||||
|
||||
Reference in New Issue
Block a user