Răsfoiți Sursa

支付优化

shish 2 ani în urmă
părinte
comite
8b9823d217

+ 15 - 22
hdApp/src/pagesPurchase/gatherPay.vue

@@ -82,31 +82,24 @@ export default {
       })
     },
     confirmWxPayFn () {
-      let currentMiniOpenId = uni.getStorageSync('currentMiniOpenId')
       let that = this
-      if(!this.$util.isEmpty(currentMiniOpenId)){
-        that.weixinPay()
-      }else{
-        //没有miniOpenId补miniOpenId
-        uni.showLoading({mask:true})
-        uni.login({
-          provider: 'weixin',
-          success: res => {
-            postWxCode({ code: res.code }).then(subRes => {
-              uni.hideLoading()
-              if(subRes.data.currentMiniOpenId){
-                let thisMiniOpenId = subRes.data.currentMiniOpenId
-                uni.setStorageSync('currentMiniOpenId',thisMiniOpenId)
-                that.weixinPay()
-              }
-            })
-          }
-        })
-      }
+      uni.showLoading({mask:true})
+      uni.login({
+        provider: 'weixin',
+        success: res => {
+          postWxCode({ code: res.code }).then(subRes => {
+            uni.hideLoading()
+            if(subRes.data.currentMiniOpenId){
+              let thisMiniOpenId = subRes.data.currentMiniOpenId
+              uni.setStorageSync('currentMiniOpenId',thisMiniOpenId)
+              that.weixinPay(thisMiniOpenId)
+            }
+          })
+        }
+      })
     },
-    weixinPay(){
+    weixinPay(currentMiniOpenId){
       let that = this
-      let currentMiniOpenId = uni.getStorageSync('currentMiniOpenId')
       purchaseClearWxPay({ orderSn: this.orderSn,currentMiniOpenId:currentMiniOpenId }).then(res => {
         that.orderSn = res.data.orderSn
         wexinPay(res.data, this.getSuccess, this.getError)

+ 15 - 26
hdApp/src/pagesPurchase/wechatPay.vue

@@ -132,34 +132,23 @@ export default {
     wxPayFn () {
       let that = this
       uni.showLoading({title: '加载中',mask:true})
-      purchaseWxPay({ orderSn: this.orderSn }).then(res => {
-        uni.hideLoading()
-        if(res.code == 1){
-          if(res.data.hasNoMiniOpenId && res.data.hasNoMiniOpenId == 1){
-              //没有miniOpenId,补miniOpenId
-              uni.login({
-                provider: 'weixin',
-                success: res => {
-                  uni.setStorageSync('code', res.code)
-                  postWxCode({ code: res.code }).then(subRes => {
-                    if(subRes.data.currentMiniOpenId){
-                      let currentMiniOpenId = subRes.data.currentMiniOpenId
-                      updateMiniOpenId({miniOpenId:currentMiniOpenId}).then(subRes=>{
-                        if(subRes.code == 1){
-                            that.$util.confirmModal({content:'网络开小差了,请继续',okText:'确认',singer:true},() => {
-                              that.wxPayFn()
-                            })
-                        }
-                      })
-                    }
-                  })
+      uni.login({
+        provider: 'weixin',
+        success: res => {
+          uni.setStorageSync('code', res.code)
+          postWxCode({ code: res.code }).then(subRes => {
+            if(subRes.data.currentMiniOpenId){
+              let currentMiniOpenId = subRes.data.currentMiniOpenId
+              purchaseWxPay({ orderSn: this.orderSn,currentMiniOpenId:currentMiniOpenId }).then(res => {
+                uni.hideLoading()
+                if(res.code == 1){
+                    this.pageId = res.data.id
+                    this.orderSn = res.data.orderSn
+                    wexinPay(res.data, this.getSuccess, this.getError)                         
                 }
               })
-          }else{
-            this.pageId = res.data.id
-            this.orderSn = res.data.orderSn
-            wexinPay(res.data, this.getSuccess, this.getError)
-          }
+            }
+          })
         }
       })
     },

+ 18 - 6
mallApp/src/pages/callback/index.vue

@@ -74,6 +74,7 @@ import AlertModule from "@/components/plugin/alert";
 import wexinPay from "@/utils/pay/wxPay";
 import { getShopUser } from "@/utils/auth";
 import { balancePay, wxPay } from "@/api/order";
+import { postWxCode } from '@/api/mini';
 export default {
   name: "index",
   components: {
@@ -136,13 +137,24 @@ export default {
           this.paySuccess();
       })
     },
-    // 微信支付
     wxPayFn() {
-      let miniOpenId = uni.getStorageSync('miniOpenId')
-      wxPay({ orderSn: this.orderSn, couponId: this.option.couponId,miniOpenId:miniOpenId }).then(res => {
-        this.payCallData = res.data
-        wexinPay(res.data, this.paySuccess, this.payFail)
-        this.orderSn = res.data.orderSn ? res.data.orderSn : ''
+      let that = this
+      uni.showLoading({title: '加载中',mask:true})
+      uni.login({
+        provider: 'weixin',
+        success: res => {
+          postWxCode({ code: res.code }).then(subRes => {
+            uni.hideLoading()
+            if(subRes.data.miniOpenId){
+              let miniOpenId = subRes.data.miniOpenId
+              wxPay({ orderSn: that.orderSn, couponId: that.option.couponId,miniOpenId:miniOpenId }).then(res => {
+                this.payCallData = res.data
+                wexinPay(res.data, that.paySuccess, that.payFail)
+                that.orderSn = res.data.orderSn ? res.data.orderSn : ''
+              })
+            }
+          })
+        }
       })
     },
     paySuccess() {