浏览代码

支付订单接口轮询30秒拿不到成功回调做抛出异常处理并清除轮询

lyb 4 年之前
父节点
当前提交
fe8f1e9a08
共有 3 个文件被更改,包括 46 次插入16 次删除
  1. 20 7
      pages/activity/activityDetail.vue
  2. 20 6
      pages/shop/detail.vue
  3. 6 3
      store/index.js

+ 20 - 7
pages/activity/activityDetail.vue

@@ -128,7 +128,7 @@
 			this.getActivitySetting();
 		},
 		onShow(){
-			if(this.vuex_isInterval){
+			if(this.vuex_voteInterval){
 				this.queryOrder();
 			}
 		},
@@ -409,8 +409,8 @@
 					// uni.navigateTo({
 					// 	url: `/pages/webview/payOrder?url=${res.data.data.qrCodeUrl}&orderId=${res.data.data.id}`
 					// })
-					this.$u.vuex('vuex_orderId', res.data.data.id);
-					this.$u.vuex('vuex_isInterval', true);
+					this.$u.vuex('vuex_voteOrder', res.data.data.id);
+					this.$u.vuex('vuex_voteInterval', true);
 					window.location.href = res.data.data.qrCodeUrl
 				} else {
 					this.$refs.toast.error(res.data.msg)
@@ -419,19 +419,32 @@
 			},
 			//查询订单状态
 			queryOrder(){
-				
 				let params = {
-					id: this.vuex_orderId
+					id: this.vuex_voteOrder
 				}
 				this.interval = setInterval(async() => {
 				  let res = await this.$api.order.orderDetail(params)
 				  if(res.data.success && res.data.data.payStatus === '付款成功'){
 					  this.voteSuccess();
-					  this.$u.vuex('vuex_isInterval', false);
-					  this.$u.vuex('vuex_orderId', 0);
+					  this.$u.vuex('vuex_voteInterval', false);
+					  this.$u.vuex('vuex_voteOrder', 0);
 					  clearInterval(this.interval)
 				  }
 				}, 1500)
+				this.countDown(); //30秒拿不到支付回调抛出异常处理
+			},
+			countDown(){
+				let seconds = 30;
+				let timer = setInterval(() => {
+					seconds--
+					if (seconds == 0) {
+						this.$refs.toast.error('订单回调异常');
+						this.$u.vuex('vuex_voteInterval', false);
+						this.$u.vuex('vuex_voteOrder', 0);
+						clearInterval(timer)
+						clearInterval(this.interval) //清除支付回调接口轮询
+					}
+				}, 1000)
 			},
 			async cmccVote(item) {
 				this.$refs.smsAlert.hideSms()

+ 20 - 6
pages/shop/detail.vue

@@ -179,7 +179,7 @@
 			this.confirmStyle.color = this.vuex_theme.bgColor;
 		},
 		onShow() {
-			if(this.vuex_isInterval){
+			if(this.vuex_goodsInterval){
 				this.queryOrder();
 			}
 			uni.$on('ADDRESS',(res)=>{
@@ -301,8 +301,8 @@
 							// uni.navigateTo({
 							// 	url: `/pages/webview/payOrder?url=${res.data.data.qrCodeUrl}&orderId=${res.data.data.id}`
 							// })
-							this.$u.vuex('vuex_orderId', res.data.data.id);
-							this.$u.vuex('vuex_isInterval', true);
+							this.$u.vuex('vuex_goodsOrder', res.data.data.id);
+							this.$u.vuex('vuex_goodsInterval', true);
 							window.location.href = res.data.data.qrCodeUrl
 						}
 						
@@ -314,17 +314,31 @@
 			//查询订单状态
 			queryOrder(){
 				let params = {
-					id: this.vuex_orderId
+					id: this.vuex_goodsOrder
 				}
 				this.interval = setInterval(async() => {
 				  let res = await this.$api.order.orderDetail(params)
 				  if(res.data.success && res.data.data.payStatus === '付款成功'){
 					  this.$refs.exchangeSuccess.showSuccess(this.detail.imgUrl);
-					  this.$u.vuex('vuex_isInterval', false);
-					  this.$u.vuex('vuex_orderId', 0);
+					  this.$u.vuex('vuex_goodsInterval', false);
+					  this.$u.vuex('vuex_goodsOrder', 0);
 					  clearInterval(this.interval)
 				  }
 				}, 1500)
+				this.countDown(); //30秒拿不到支付回调抛出异常处理
+			},
+			countDown(){
+				let seconds = 30;
+				let timer = setInterval(() => {
+					seconds--
+					if (seconds == 0) {
+						this.$refs.toast.error('订单回调异常');
+						this.$u.vuex('vuex_goodsInterval', false);
+						this.$u.vuex('vuex_goodsOrder', 0);
+						clearInterval(timer)
+						clearInterval(this.interval) //清除支付回调接口轮询
+					}
+				}, 1000)
 			},
 			cancel(){
 				this.exchangeShow = false;

+ 6 - 3
store/index.js

@@ -17,7 +17,8 @@ try {
 
 // 需要永久存储,且下次APP启动需要取出的,在state中的变量名
 let saveStateKeys = ['vuex_audit', 'vuex_userId', 'vuex_phone', 'vuex_skin',
-	'vuex_theme', 'vuex_active_setting', 'vuex_isCMCC' , 'vuex_isInterval' , 'vuex_orderId'
+	'vuex_theme', 'vuex_active_setting', 'vuex_isCMCC' , 'vuex_voteInterval' , 'vuex_voteOrder',
+	'vuex_goodsInterval', 'vuex_goodsOrder'
 ];
 
 // 保存变量到本地存储中
@@ -46,8 +47,10 @@ const store = new Vuex.Store({
 		vuex_theme: lifeData.vuex_theme ? lifeData.vuex_theme : config.themeRed.theme,
 		vuex_active_setting: lifeData.vuex_active_setting ? lifeData.vuex_active_setting : {},
 		vuex_isCMCC: lifeData.vuex_isCMCC ? lifeData.vuex_isCMCC : false,
-		vuex_isInterval: lifeData.vuex_isInterval ? lifeData.vuex_isInterval : false,
-		vuex_orderId: lifeData.vuex_orderId ? lifeData.vuex_orderId : 0,
+		vuex_voteInterval: lifeData.vuex_voteInterval ? lifeData.vuex_voteInterval : false,
+		vuex_voteOrder: lifeData.vuex_voteOrder ? lifeData.vuex_voteOrder : 0,
+		vuex_goodsInterval: lifeData.vuex_goodsInterval ? lifeData.vuex_goodsInterval : false,
+		vuex_goodsOrder: lifeData.vuex_goodsOrder ? lifeData.vuex_goodsOrder : 0,
 	},
 
 	mutations: {