From 1ca571a40509a7a6cfdf51316025f3692f62122f Mon Sep 17 00:00:00 2001
From: 石广澎 <shiguangpeng@163.com>
Date: 星期五, 12 四月 2024 19:42:14 +0800
Subject: [PATCH] feat(微信支付): 支持通联收银宝代理商模式

---
 pages/pay/scanpay.vue |  137 +++++++++++++++++++++++++--------------------
 1 files changed, 75 insertions(+), 62 deletions(-)

diff --git a/pages/pay/scanpay.vue b/pages/pay/scanpay.vue
index 44c7ec0..15e5350 100644
--- a/pages/pay/scanpay.vue
+++ b/pages/pay/scanpay.vue
@@ -21,7 +21,7 @@
         <view class="mask" @click="showBord"></view>
       </view>
       <view class="u-font-28 color-666 u-m-t-60">閫夋嫨鏀粯鏂瑰紡</view>
-      <u-radio-group v-model="bankCardId" placement="column">
+      <u-radio-group v-model="payWay" placement="column">
         <view v-if="platform == 5" class="u-border-bottom u-p-v-20 u-flex u-row-between">
           <image src="@/static/imgs/pay-zfb.png" class="pay-icon"></image>
           <view class="flex-1">
@@ -114,32 +114,6 @@
       <navigator v-if="isNew" class="reg-btn" :url="'/pages/pay/register?cid='+cid">
         <image src="/static/register-btn.png" mode=""></image>
       </navigator>
-      <!--			<view class="btn">
-        <wx-open-launch-weapp class="wx-app" id="launch-btn" appid="wxfc579973fbdde096"
-          username="gh_3676c3af5dda" path="pages/index/index" env-version="release">
-          <script type="text/wxtag-template">
-            <style>
-              .btn {
-                border: none;
-                position: absolute;
-                top: 0;
-                right: 0;
-                bottom: 0;
-                left: 0;
-                width: 100%;
-                border-radius: 50px;
-                text-align: center;
-                line-height: 100%;
-                color: #BF3B00;
-                font-size: 18px;
-                font-weight: 600;
-                background: linear-gradient(180deg, rgba(253, 222, 95, 1) 0%, rgba(254, 172, 31, 1) 71%, rgba(254, 186, 40, 1) 100%);
-               }
-            </style>
-            <button class="btn">鎵撳紑灏忕▼搴�</button>
-          </script>
-        </wx-open-launch-weapp>
-      </view>-->
     </view>
 
 
@@ -204,8 +178,7 @@
   queryShop,
   queryMyDiscount,
   getScoreWorth,
-  getOpenId,
-  getUserId,
+  userLogin,
   queryScore,
   queryMyUseSweepPayMaxCoupon,
   getWechatConfigInfo,
@@ -274,28 +247,18 @@
       this.init()
     }
     if (opt.code || opt.auth_code) {
-      let type = this.platform
       let code = opt.code
       if (this.platform == 5) {
         code = opt.auth_code
       }
       this.end++
-      getOpenId({
+      userLogin({
+        platform: this.platform,
         params: {
-          code: opt.code
+          code
         }
       }).then(res => {
-        this.count++
-        if (this.count >= this.end) {
-          uni.hideLoading()
-        }
-        this.token = res.token.accessToken
-        uni.setStorageSync(ACCESSTOKEN, res.token.accessToken)
-        uni.setStorageSync('IS_NEW', res.isNew)
-        this.isNew = res.isNew
-        if (!res.isNew) {
-          this.getUserInfo()
-        }
+        this.getToken(res)
       }).catch(() => {
         uni.hideLoading()
       })
@@ -331,6 +294,19 @@
     this.canReset = true
   },
   methods: {
+    getToken(res){
+      this.count++
+      if (this.count >= this.end) {
+        uni.hideLoading()
+      }
+      this.token = res.token.accessToken
+      uni.setStorageSync(ACCESSTOKEN, res.token.accessToken)
+      uni.setStorageSync('IS_NEW', res.isNew)
+      this.isNew = res.isNew
+      if (!res.isNew) {
+        this.getUserInfo()
+      }
+    },
     radioChange(e, item) {
       this.bordShow = false
       this.payWay = item
@@ -528,27 +504,42 @@
     },
     //璺宠浆钀ラ攢椤甸潰
     toDiscount() {
-      let toDiscount = false
-      //涓嶆槸浼氬憳
-      if (this.isNew) toDiscount = false
-      //娌℃湁绉垎銆佹病鏈変紭鎯犲埜銆佹病鏈夊簵閾轰紭鎯�
-      if (this.integral == 0 && !this.couponInfo && this.discount.shopDiscount == 1) toDiscount = false
       const shopInfo = encodeURIComponent(JSON.stringify(this.shopInfo))
-      //鏈夊簵閾轰紭鎯�
-      if (this.discount.shopDiscount != 1) {
-        toDiscount = true
-      }
-      if (this.payWay == 3 && (this.shopInfo.bank_pay_use_score_flag || this.shopInfo.bank_pay_use_coupon_flag)) { //閾惰鍗℃敮浠�
-        toDiscount = true
-      } else if ((this.shopInfo.use_score_flag && this.shopInfo.app_pay_use_score_flag) || (this.shopInfo.user_coupon_flag && this.shopInfo.app_pay_use_coupon_flag)) {
-        toDiscount = true
+      if (!this.isNew) { //鏄細鍛�
+        if (this.integral > 0 || this.couponInfo) { //鏈変紭鎯犲埜鎴栫Н鍒�
+          if (this.payWay == 3 && (this.shopInfo.bank_pay_use_score_flag || this.shopInfo
+              .bank_pay_use_coupon_flag)) { //閾惰鍗℃敮浠�
+
+            uni.navigateTo({
+              url: `/pages/pay/discountpay?shopInfo=${shopInfo}&integral=${this.integral}&scoreWorth=${this.scoreWorth}&money=${this.money}&payWay=${this.payWay}&bankCardId=${this.bankCardId}`
+            })
+            return false
+          } else if ((this.shopInfo.use_score_flag && this.shopInfo.app_pay_use_score_flag) || (this
+              .shopInfo
+              .user_coupon_flag && this.shopInfo.app_pay_use_coupon_flag)) {
+            uni.navigateTo({
+              url: `/pages/pay/discountpay?shopInfo=${shopInfo}&integral=${this.integral}&scoreWorth=${this.scoreWorth}&money=${this.money}&payWay=${this.payWay}&bankCardId=${this.bankCardId}`
+            })
+            return false
+          } else if (this.discount.shopDiscount != 1) {
+            uni.navigateTo({
+              url: `/pages/pay/discountpay?shopInfo=${shopInfo}&integral=${this.integral}&scoreWorth=${this.scoreWorth}&money=${this.money}&payWay=${this.payWay}&bankCardId=${this.bankCardId}`
+            })
+            return false
+          } else {
+            return true
+          }
+        } else if (this.discount.shopDiscount != 1) {
+          uni.navigateTo({
+            url: `/pages/pay/discountpay?shopInfo=${shopInfo}&integral=${this.integral}&scoreWorth=${this.scoreWorth}&money=${this.money}&payWay=${this.payWay}&bankCardId=${this.bankCardId}`
+          })
+          return false
+        } else {
+          return true
+        }
       } else {
-        toDiscount = false
+        return true
       }
-      uni.navigateTo({
-        url: `/pages/pay/discountpay?shopInfo=${shopInfo}&integral=${this.integral}&scoreWorth=${this.scoreWorth}&money=${this.money}&payWay=${this.payWay}&bankCardId=${this.bankCardId}`
-      })
-      return toDiscount
     },
     //纭鏀粯
     pay() {
@@ -606,7 +597,7 @@
     },
     // 寰俊鏀粯
     wxPay(res) {
-      setTimeout(() => {
+      /*setTimeout(() => {
         wx.chooseWXPay({
           timestamp: res.timeStamp, // 鏀粯绛惧悕鏃堕棿鎴�
           nonceStr: res.nonceStr, // 鏀粯绛惧悕闅忔満涓诧紝涓嶉暱浜� 32 浣�
@@ -621,6 +612,28 @@
             })
           }
         });
+      }, 200)*/
+
+      setTimeout(() => {
+        WeixinJSBridge.invoke(
+            'getBrandWCPayRequest', {
+              "appId": res.appId, //鍏紬鍙稩D锛岀敱鍟嗘埛浼犲叆
+              "timeStamp": res.timeStamp, //鏃堕棿鎴筹紝鑷�1970骞翠互鏉ョ殑绉掓暟
+              "nonceStr": res.nonceStr, //闅忔満涓�
+              "package": res.package,
+              "signType": res.signType, //寰俊绛惧悕鏂瑰紡锛�
+              "paySign": res.paySign //寰俊绛惧悕
+            },
+            (res) => {
+              if (res.err_msg == "get_brand_wcpay_request:ok") {
+                // 浣跨敤浠ヤ笂鏂瑰紡鍒ゆ柇鍓嶇杩斿洖,寰俊鍥㈤槦閮戦噸鎻愮ず锛�
+                //res.err_msg灏嗗湪鐢ㄦ埛鏀粯鎴愬姛鍚庤繑鍥瀘k锛屼絾骞朵笉淇濊瘉瀹冪粷瀵瑰彲闈犮��
+                uni.navigateTo({
+                  url: `/pages/pay/paySuccess?orderId=${this.orderId}&youHuiInfo=${JSON
+                      .stringify(this.youHuiInfo)}`
+                })
+              }
+            });
       }, 200)
     },
     //鏀粯瀹濇敮浠�

--
Gitblit v1.9.1