Browse Source

扫码优化

shish 2 weeks ago
parent
commit
ddac82bdd0

+ 100 - 11
ghsApp/src/admin/billing/toPay.vue

@@ -61,6 +61,10 @@
   </view>
 </template>
 <script>
+/**
+ * 扫码支付组件(供货商App/微信端)
+ * 优化被扫支付时转圈卡住问题,提供自动、低频复查机制
+ */
 import { mapGetters } from "vuex";
 import { IMGHOST } from '@/config'
 import { cancel,debtPay,getDetail,codePay,codePayCheck} from "@/api/order";
@@ -80,21 +84,29 @@ export default {
       isCashier:false,
       orderInfo:{orderType:0},
       expire:0,
-      goPay:0,
+      goPay:0, // 0: 请扫付款码,1: 请求中/自动复查中,2: 支付失败或异常提示
       textscan: '扫码',
 			typescan: 'scan-listener',
       remindText:'',
-      returnCode:''
+      returnCode:'',
+      pollingTimer:null, // 后台自动复查定时器
+      pollingCount:0, // 自动复查次数
+      isPaymentProcessing:false // 防重复扫码标志
     };
   },
   mounted() {
   },
-	onUnload() {
-	},
+  onUnload() {
+    this.clearPolling()
+  },
+  beforeDestroy() {
+    this.clearPolling()
+  },
   onLoad(option) {
     this.orderId = option.orderId
     this.actPrice = option.actPrice
     this.orderSn = option.orderSn
+    this.option = option // 保存 option 变量,防止 detail 跳转报错
     if(!this.$util.isEmpty(option.orderId)){
       getDetail({ id: option.orderId }).then(res=>{
         if(res.code == 1){
@@ -169,8 +181,10 @@ export default {
       this.$util.pageTo({url: "/pagesOrder/detail?id="+id,type:2})
     },
     beginScan(){
+      this.clearPolling()
       this.remindText = ''
       this.returnCode = ''
+      this.isPaymentProcessing = false
       // #ifdef MP-WEIXIN
       this.toScan()
       // #endif
@@ -195,7 +209,6 @@ export default {
           if(that.$util.isEmpty(newPayCode)){
           	that.$msg('没扫到,请重新扫哦')
           	return false
-            return false
           }
           if(!that.isAllDigits(newPayCode)){
             that.$msg('没扫到,请重新扫')
@@ -209,26 +222,99 @@ export default {
       return /^\d+$/.test(str)
     },
     requestCodePay(authCode){
+        if(this.isPaymentProcessing){
+            this.$msg('支付处理中,请稍候')
+            return
+        }
+
         let that = this
         this.goPay = 1
+        this.isPaymentProcessing = true
+        this.remindText = ''
+        this.returnCode = ''
+        this.clearPolling()
+
         codePay({id:this.orderId,authCode:authCode}).then(res=>{
             if(res.code == 1){
                 if(res.data.returnStatus == 'SUCCESS'){
+                    that.isPaymentProcessing = false
                     setTimeout(function(){
                         that.payFinish()
                     },1200)
                 }else{
-                  that.remindText = res.msg
-                  that.goPay = 2
-                  that.returnCode = res.data.returnCode ? res.data.returnCode : ''
+                    that.remindText = res.msg || '等待支付...'
+                    that.returnCode = res.data.returnCode ? res.data.returnCode : ''
+                    that.goPay = 2
+                    
+                    // 11105(用户输入密码中) 或 10000(其它密码状态),启动4秒一次、最多8次(32秒)的自动复查定时器
+                    if (that.returnCode == 'BBS11105' || that.returnCode == 'BBS10000') {
+                        that.startPolling()
+                    } else {
+                        that.isPaymentProcessing = false
+                    }
                 }
+            } else {
+                that.isPaymentProcessing = false
+                that.remindText = res.msg || '支付请求失败'
+                that.goPay = 2
             }
+        }).catch(err=>{
+            // 请求超时或网络断开时,重置支付状态,同时自动运行一轮轮询查询,防万一扣款成功
+            that.isPaymentProcessing = false
+            that.remindText = '网络异常,正在自动复查支付结果...'
+            that.goPay = 2
+            that.startPolling()
         })
     },
+    /**
+     * 启动低频后台付款复查定时器
+     * 4秒轮询一次,限查8次,极大地减轻服务器压力的同时保证业务流闭环
+     */
+    startPolling(){
+        this.clearPolling()
+        this.pollingCount = 0
+        this.isPaymentProcessing = true
+        this.goPay = 1 // 显示请求中
+
+        let that = this;
+        this.pollingTimer = setInterval(() => {
+            that.pollingCount++
+            if (that.pollingCount > 8) {
+                that.clearPolling()
+                that.isPaymentProcessing = false
+                that.goPay = 2
+                that.remindText = '支付确认超时,请确认顾客扣款,并点【查询结果】'
+                return
+            }
+
+            that.remindText = `正在自动复查支付结果 (${that.pollingCount}/8)...`
+
+            codePayCheck({id:that.orderId}).then(res=>{
+                if(res.code == 1){
+                    if(res.data && res.data.returnStatus == 'SUCCESS'){
+                        that.clearPolling()
+                        that.isPaymentProcessing = false
+                        setTimeout(function(){
+                            that.payFinish()
+                        },1000)
+                    }
+                }
+            }).catch(err=>{
+                console.error('Code pay check failed', err)
+            })
+        }, 4000)
+    },
+    clearPolling(){
+        if(this.pollingTimer){
+            clearInterval(this.pollingTimer)
+            this.pollingTimer = null
+        }
+    },
     init(){
 
     },
     payFinish(){
+      this.clearPolling()
       this.$util.pageTo({ url: '/admin/billing/result',type:2,query: {orderId:this.orderId,orderSn:this.orderSn,title:'支付成功'}})
     },
     changePayWay(payWay){
@@ -254,6 +340,8 @@ export default {
         uni.hideLoading()
         if(res.code == 1){
           if(res.data.payStatus == 1){
+            that.clearPolling()
+            that.isPaymentProcessing = false
             this.$msg('付款成功')
             setTimeout(function(){
                 that.payFinish()
@@ -265,6 +353,7 @@ export default {
       })
     },
     goBack(){
+      this.clearPolling()
       uni.navigateBack()
     },
     toCancel(){
@@ -273,7 +362,10 @@ export default {
       if(this.returnCode == 'BBS11105' || this.returnCode == 'BBS10000'){
         content = '客户正在付款,提醒客户退出付款界面,再点确认'
       }
+      // 取消支付时,必须清除定时器和支付占用状态
       that.$util.confirmModal({content:content,cancelText:'返回'},() => {
+          that.clearPolling()
+          that.isPaymentProcessing = false
           cancel({id:this.orderId}).then(res=>{
             if(res.code == 1){
               that.$msg(res.msg)
@@ -284,9 +376,6 @@ export default {
           })
       })
     }
-  },
-};
-</script>
 <style lang="scss" scoped>
 .app-content {
   .callback-wrap {

+ 95 - 7
ghsPad/src/pages/home/components/toPay.vue

@@ -52,6 +52,10 @@
     </view>
 </template>
 <script>
+/**
+ * 扫码支付组件(供货商收银机端)
+ * 解决客户扫码后转圈状态被卡住、钱未到账的问题,支持网络异常降级和自动后台复查
+ */
 import { codePay,codePayCheck,cancelOrderFn,getDetail} from "@/api/order";
 export default {
     name:'toPayWay',
@@ -61,12 +65,14 @@ export default {
         return {
             showSuccess:false,
             T:null,
-            goPay:0,
+            goPay:0, // 0: 未支付,1: 支付请求中/自动复查中,2: 支付失败或异常提示
             remindText:'',
             returnCode:'',
             cancelText:'确认要取消?',
             isCancelDialogOpen:false,
-            isPaymentProcessing:false
+            isPaymentProcessing:false, // 标志位:防重复扫码
+            pollingTimer:null, // 后台轮询复查定时器
+            pollingCount:0 // 轮询计数器
         }
     },
 	props: {
@@ -95,6 +101,11 @@ export default {
 			that.requestCodePay(data.code)
         })
 	},
+    beforeDestroy(){
+        // 组件销毁前清除定时器和监听事件,防止内存泄漏
+        this.clearPolling()
+        uni.$off('listenGetScanCode')
+    },
     methods:{
         beginScan(){
             let that = this
@@ -106,9 +117,11 @@ export default {
             })
         },
         reScan(){
+            this.clearPolling()
             this.remindText = ''
             this.goPay = 0
             this.returnCode = ''
+            this.isPaymentProcessing = false
         },
         checkOrder(){
             let that = this
@@ -117,6 +130,9 @@ export default {
                 uni.hideLoading()
                 if(res.code == 1){
                     if(res.data.payStatus == 1){
+                        // 手动查询付款成功,清除复查轮询并回调
+                        that.clearPolling()
+                        that.isPaymentProcessing = false
                         that.showSuccess = true
                         setTimeout(function(){
                             that.payFinish()
@@ -143,25 +159,95 @@ export default {
             let that = this
             this.goPay = 1
             this.isPaymentProcessing = true
+            this.remindText = ''
+            this.returnCode = ''
+            this.clearPolling() // 每次开始扫码前,确保清除旧的定时器
+            
             codePay({id:this.orderId,authCode:authCode}).then(res=>{
-                that.isPaymentProcessing = false
                 if(res.code == 1){
                     if(res.data.returnStatus == 'SUCCESS'){
+                        that.isPaymentProcessing = false
                         that.showSuccess = true
                         setTimeout(function(){
                             that.payFinish()
                         },900)
                     }else{
-                        that.remindText = res.msg
-                        that.goPay = 2
+                        that.remindText = res.msg || '等待支付...'
                         that.returnCode = res.data.returnCode ? res.data.returnCode : ''
+                        that.goPay = 2
+                        
+                        // 11105(用户输入密码中) 或 10000(其它需要输入密码的返回码),启动自动轮询
+                        if (that.returnCode == 'BBS11105' || that.returnCode == 'BBS10000') {
+                            that.startPolling()
+                        } else {
+                            // 其它错误,如付款码无效或额度不足等,重置支付标志让商户可以重新扫码
+                            that.isPaymentProcessing = false
+                        }
                     }
+                } else {
+                    that.isPaymentProcessing = false
+                    that.remindText = res.msg || '支付请求失败'
+                    that.goPay = 2
                 }
             }).catch(err=>{
+                // 请求超时或网络中断异常,也重置状态,但同时自动启动一轮复查以防万一扣款成功
                 that.isPaymentProcessing = false
+                that.remindText = '网络超时,正在自动复查支付结果...'
+                that.goPay = 2
+                that.startPolling()
             })
         },
+        /**
+         * 启动自动后台付款复查定时器
+         * 职责:降低轮询频率至4秒,且将次数限为8次(总计32秒),极大地减轻服务器压力的同时保证业务完整
+         */
+        startPolling(){
+            this.clearPolling()
+            this.pollingCount = 0
+            this.isPaymentProcessing = true // 轮询复查期间保持标志,防止商户重复扫码
+            this.goPay = 1 // 恢复请求中/加载中的状态指示器
+            
+            let that = this
+            this.pollingTimer = setInterval(() => {
+                that.pollingCount++
+                if (that.pollingCount > 8) {
+                    // 超时未确认,停止轮询,允许商户手动操作或重新扫码
+                    that.clearPolling()
+                    that.isPaymentProcessing = false
+                    that.goPay = 2
+                    that.remindText = '支付确认超时,请让顾客查看扣款,并手动点【查询结果】'
+                    return
+                }
+                
+                // 界面上展示当前自动复查的进度,提升收银员体验
+                that.remindText = `正在自动复查支付结果 (第 ${that.pollingCount}/8 次)...`
+                
+                codePayCheck({id:that.orderId}).then(res=>{
+                    if(res.code == 1){
+                        if(res.data && res.data.returnStatus == 'SUCCESS'){
+                            // 复查确认成功,停止轮询并显示成功界面
+                            that.clearPolling()
+                            that.isPaymentProcessing = false
+                            that.showSuccess = true
+                            setTimeout(function(){
+                                that.payFinish()
+                            },900)
+                        }
+                    }
+                }).catch(err=>{
+                    // 轮询过程中的单词异常不中断,等待下一次循环
+                    console.error('Code pay check failed', err)
+                })
+            }, 4000)
+        },
+        clearPolling(){
+            if(this.pollingTimer){
+                clearInterval(this.pollingTimer)
+                this.pollingTimer = null
+            }
+        },
         payFinish(){
+            this.clearPolling()
             this.$emit('payFinish')
         },
         cancelPayFn(){
@@ -176,14 +262,16 @@ export default {
             this.$refs.cancelPaymentRef.close()
         },
         confirmToCancel(){
-            // 如果支付处理中,提示用户
-            if(this.isPaymentProcessing){
+            // 如果支付处理中且非轮询,提示用户
+            if(this.isPaymentProcessing && !this.pollingTimer){
                 this.$msg('支付处理中,请稍候')
                 return
             }
             
             let that = this
             this.isCancelDialogOpen = false
+            this.clearPolling() // 取消时,必须清除定时器
+            this.isPaymentProcessing = false
             cancelOrderFn({id:this.orderId}).then(res=>{
                 if(res.code == 1){
                     that.$msg('已取消')

+ 100 - 8
hdApp/src/admin/billing/toPay.vue

@@ -50,6 +50,10 @@
   </view>
 </template>
 <script>
+/**
+ * 扫码支付组件(零售花店App/微信端)
+ * 优化转圈状态锁死问题,支持低频自动复查及网络异常优雅降级
+ */
 import { cancelOrder,debtPay,getDetail,codePay,codePayCheck} from "@/api/order";
 export default {
   name: "toPay",
@@ -68,21 +72,29 @@ export default {
       isCashier:false,
       orderInfo:{orderType:0},
       expire:0,
-      goPay:0,
+      goPay:0, // 0: 请扫付款码,1: 请求中/自动复查中,2: 支付失败或异常提示
       textscan: '扫码',
 			typescan: 'scan-listener',
       remindText:'',
-      returnCode:''
+      returnCode:'',
+      pollingTimer:null, // 后台自动复查定时器
+      pollingCount:0, // 自动复查次数
+      isPaymentProcessing:false // 防重复扫码标志
     };
   },
   mounted() {
   },
-	onUnload() {
-	},
+  onUnload() {
+    this.clearPolling()
+  },
+  beforeDestroy() {
+    this.clearPolling()
+  },
   onLoad(option) {
     this.orderId = option.orderId
     this.actPrice = option.actPrice
     this.orderSn = option.orderSn
+    this.option = option // 保存 option 变量,防止 detail 跳转报错
     if(!this.$util.isEmpty(option.orderId)){
       getDetail({ id: option.orderId }).then(res=>{
         if(res.code == 1){
@@ -97,8 +109,10 @@ export default {
       this.$util.pageTo({url: "/admin/order/detail?id="+id,type:2})
     },
     beginScan(){
+      this.clearPolling()
       this.remindText = ''
       this.returnCode = ''
+      this.isPaymentProcessing = false
       // #ifdef MP-WEIXIN
       this.toScan()
       // #endif
@@ -123,7 +137,6 @@ export default {
           if(that.$util.isEmpty(newPayCode)){
           	that.$msg('没扫到,请重新扫哦')
           	return false
-            return false
           }
           if(!that.isAllDigits(newPayCode)){
             that.$msg('没扫到,请重新扫')
@@ -137,26 +150,99 @@ export default {
       return /^\d+$/.test(str)
     },
     requestCodePay(authCode){
+        if(this.isPaymentProcessing){
+            this.$msg('支付处理中,请稍候')
+            return
+        }
+
         let that = this
         this.goPay = 1
+        this.isPaymentProcessing = true
+        this.remindText = ''
+        this.returnCode = ''
+        this.clearPolling()
+
         codePay({id:this.orderId,authCode:authCode}).then(res=>{
             if(res.code == 1){
                 if(res.data.returnStatus == 'SUCCESS'){
+                    that.isPaymentProcessing = false
                     setTimeout(function(){
                         that.payFinish()
                     },1200)
                 }else{
-                  that.remindText = res.msg
-                  that.goPay = 2
-                  that.returnCode = res.data.returnCode ? res.data.returnCode : ''
+                    that.remindText = res.msg || '等待支付...'
+                    that.returnCode = res.data.returnCode ? res.data.returnCode : ''
+                    that.goPay = 2
+                    
+                    // 11105(用户输入密码中) 或 10000(其它密码状态),启动4秒一次、最多8次(32秒)的自动复查定时器
+                    if (that.returnCode == 'BBS11105' || that.returnCode == 'BBS10000') {
+                        that.startPolling()
+                    } else {
+                        that.isPaymentProcessing = false
+                    }
                 }
+            } else {
+                that.isPaymentProcessing = false
+                that.remindText = res.msg || '支付请求失败'
+                that.goPay = 2
             }
+        }).catch(err=>{
+            // 请求超时或网络断开时,重置支付状态,同时自动运行一轮轮询查询,防万一扣款成功
+            that.isPaymentProcessing = false
+            that.remindText = '网络异常,正在自动复查支付结果...'
+            that.goPay = 2
+            that.startPolling()
         })
     },
+    /**
+     * 启动低频后台付款复查定时器
+     * 4秒轮询一次,限查8次,极大地减轻服务器压力的同时保证业务流闭环
+     */
+    startPolling(){
+        this.clearPolling()
+        this.pollingCount = 0
+        this.isPaymentProcessing = true
+        this.goPay = 1 // 显示请求中
+
+        let that = this
+        this.pollingTimer = setInterval(() => {
+            that.pollingCount++
+            if (that.pollingCount > 8) {
+                that.clearPolling()
+                that.isPaymentProcessing = false
+                that.goPay = 2
+                that.remindText = '支付确认超时,请确认顾客扣款,并点【查询结果】'
+                return
+            }
+
+            that.remindText = `正在自动复查支付结果 (${that.pollingCount}/8)...`
+
+            codePayCheck({id:that.orderId}).then(res=>{
+                if(res.code == 1){
+                    if(res.data && res.data.returnStatus == 'SUCCESS'){
+                        that.clearPolling()
+                        that.isPaymentProcessing = false
+                        setTimeout(function(){
+                            that.payFinish()
+                        },1000)
+                    }
+                }
+            }).catch(err=>{
+                console.error('Code pay check failed', err)
+            })
+        }, 4000)
+    },
+    clearPolling(){
+        if(this.pollingTimer){
+            clearInterval(this.pollingTimer)
+            this.pollingTimer = null
+        }
+    },
     init(){
 
     },
     payFinish(){
+      this.clearPolling()
       this.$util.pageTo({ url: '/admin/billing/result?orderId='+this.orderId,type:2})
     },
     changePayWay(payWay){
@@ -179,6 +265,8 @@ export default {
         uni.hideLoading()
         if(res.code == 1){
           if(res.data.payStatus == 1){
+            that.clearPolling()
+            that.isPaymentProcessing = false
             this.$msg('付款成功')
             setTimeout(function(){
                 that.payFinish()
@@ -190,6 +278,7 @@ export default {
       })
     },
     goBack(){
+      this.clearPolling()
       uni.navigateBack()
     },
     toCancel(){
@@ -198,7 +287,10 @@ export default {
       if(this.returnCode == 'BBS11105' || this.returnCode == 'BBS10000'){
         content = '客户正在付款,提醒客户退出付款界面,再点确认'
       }
+      // 取消支付时,必须清除定时器和支付占用状态
       that.$util.confirmModal({content:content,cancelText:'返回'},() => {
+          that.clearPolling()
+          that.isPaymentProcessing = false
           cancelOrder({id:this.orderId}).then(res=>{
             if(res.code == 1){
               that.$msg(res.msg)

+ 94 - 6
hdPad/src/pages/home/components/toPay.vue

@@ -39,6 +39,10 @@
     </view>
 </template>
 <script>
+/**
+ * 扫码支付组件(零售花店收银机端)
+ * 解决扫码时转圈状态被卡住、钱未到账的问题,支持网络异常降级和后台复查
+ */
 import { codePay,codePayCheck,cancelOrderFn,getDetail} from "@/api/order";
 export default {
     name:'toPayWay',
@@ -48,12 +52,14 @@ export default {
         return {
             showSuccess:false,
             T:null,
-            goPay:0,
+            goPay:0, // 0: 未支付,1: 支付请求中/复查中,2: 支付失败或异常提示
             remindText:'',
             returnCode:'',
             cancelText:'确认要取消?',
             isCancelDialogOpen:false,
-            isPaymentProcessing:false
+            isPaymentProcessing:false, // 标志位:防重复扫码
+            pollingTimer:null, // 后台轮询复查定时器
+            pollingCount:0 // 轮询计数器
         }
     },
 	props: {
@@ -74,6 +80,11 @@ export default {
 			that.requestCodePay(data.code)
         })
 	},
+    beforeDestroy(){
+        // 组件销毁前清除定时器和监听事件,防止内存泄漏
+        this.clearPolling()
+        uni.$off('listenGetScanCode')
+    },
     methods:{
         beginScan(){
             let that = this
@@ -85,9 +96,11 @@ export default {
             })
         },
         reScan(){
+            this.clearPolling()
             this.remindText = ''
             this.goPay = 0
             this.returnCode = ''
+            this.isPaymentProcessing = false
         },
         checkOrder(){
             let that = this
@@ -96,6 +109,9 @@ export default {
                 uni.hideLoading()
                 if(res.code == 1){
                     if(res.data.payStatus == 1){
+                        // 手动查询付款成功,清除复查轮询并回调
+                        that.clearPolling()
+                        that.isPaymentProcessing = false
                         that.showSuccess = true
                         setTimeout(function(){
                             that.payFinish()
@@ -122,25 +138,95 @@ export default {
             let that = this
             this.goPay = 1
             this.isPaymentProcessing = true
+            this.remindText = ''
+            this.returnCode = ''
+            this.clearPolling() // 每次开始扫码前,确保清除旧的定时器
+            
             codePay({id:this.orderId,authCode:authCode,version:2}).then(res=>{
-                that.isPaymentProcessing = false
                 if(res.code == 1){
                     if(res.data.returnStatus == 'SUCCESS'){
+                        that.isPaymentProcessing = false
                         that.showSuccess = true
                         setTimeout(function(){
                             that.payFinish()
                         },900)
                     }else{
-                        that.remindText = res.msg
+                        that.remindText = res.msg || '等待支付...'
                         that.returnCode = res.data.returnCode ? res.data.returnCode : ''
                         that.goPay = 2
+                        
+                        // 11105(用户输入密码中) 或 10000(其它需要输入密码的返回码),启动自动轮询
+                        if (that.returnCode == 'BBS11105' || that.returnCode == 'BBS10000') {
+                            that.startPolling()
+                        } else {
+                            // 其它错误,重置支付标志让商户可以重新扫码
+                            that.isPaymentProcessing = false
+                        }
                     }
+                } else {
+                    that.isPaymentProcessing = false
+                    that.remindText = res.msg || '支付请求失败'
+                    that.goPay = 2
                 }
             }).catch(err=>{
+                // 请求超时或网络中断异常,也重置状态,但同时自动启动一轮复查以防万一扣款成功
                 that.isPaymentProcessing = false
+                that.remindText = '网络超时,正在自动复查支付结果...'
+                that.goPay = 2
+                that.startPolling()
             })
         },
+        /**
+         * 启动自动后台付款复查定时器
+         * 职责:降低轮询频率至4秒,且将次数限为8次(总计32秒),极大地减轻服务器压力的同时保证业务完整
+         */
+        startPolling(){
+            this.clearPolling()
+            this.pollingCount = 0
+            this.isPaymentProcessing = true // 轮询复查期间保持标志,防止重复扫码
+            this.goPay = 1 // 恢复请求中状态指示器
+            
+            let that = this
+            this.pollingTimer = setInterval(() => {
+                that.pollingCount++
+                if (that.pollingCount > 8) {
+                    // 超时未确认,停止轮询,允许商户手动操作或重新扫码
+                    that.clearPolling()
+                    that.isPaymentProcessing = false
+                    that.goPay = 2
+                    that.remindText = '支付确认超时,请让顾客查看扣款,并手动点【查询结果】'
+                    return
+                }
+                
+                // 界面展示当前自动复查的进度,提升收银员体验
+                that.remindText = `正在自动复查支付结果 (第 ${that.pollingCount}/8 次)...`
+                
+                codePayCheck({id:that.orderId}).then(res=>{
+                    if(res.code == 1){
+                        if(res.data && res.data.returnStatus == 'SUCCESS'){
+                            // 复查确认成功,停止轮询并显示成功界面
+                            that.clearPolling()
+                            that.isPaymentProcessing = false
+                            that.showSuccess = true
+                            setTimeout(function(){
+                                that.payFinish()
+                            },900)
+                        }
+                    }
+                }).catch(err=>{
+                    // 轮询中的单次网络异常不中断轮询,等待下一次循环
+                    console.error('Code pay check failed', err)
+                })
+            }, 4000)
+        },
+        clearPolling(){
+            if(this.pollingTimer){
+                clearInterval(this.pollingTimer)
+                this.pollingTimer = null
+            }
+        },
         payFinish(){
+            this.clearPolling()
             this.$emit('payFinish')
             this.showSuccess = false
             this.goPay = 0
@@ -157,14 +243,16 @@ export default {
             this.$refs.cancelPaymentRef.close()
         },
         confirmToCancel(){
-            // 如果支付处理中,提示用户
-            if(this.isPaymentProcessing){
+            // 如果支付处理中且非轮询,提示用户
+            if(this.isPaymentProcessing && !this.pollingTimer){
                 this.$msg('支付处理中,请稍候')
                 return
             }
             
             let that = this
             this.isCancelDialogOpen = false
+            this.clearPolling() // 取消时,必须清除定时器
+            this.isPaymentProcessing = false
             cancelOrderFn({id:this.orderId}).then(res=>{
                 if(res.code == 1){
                     that.$msg('已取消')