Przeglądaj źródła

fix: confirm withdraw transfer directly

root 19 godzin temu
rodzic
commit
73ef945ff5

+ 138 - 36
packageUser/pages/user/cash/cash.js

@@ -1,7 +1,6 @@
 var _request = require('../../../../utils/request.js')
 var util = require('../../../../utils/util.js')
 var MAX_MERCHANT_TRANSFER_CASH = 20000
-var TAKE_CASH_SUBSCRIBE_TEMPLATE_ID = "L073dR84XibBZNxfvTkvTIemd7JAbj5o2Og7-VBAiX8"
 var PENDING_VIRTUAL_RECHARGE_ORDER_KEY = 'pendingVirtualRechargeOrderId'
 Page({
   data: {
@@ -17,7 +16,12 @@ Page({
 	withdraw_num:0,
 	view_withdraw:0,
 	view_fee:0,
-	syncingPendingRecharge:false
+	syncingPendingRecharge:false,
+	submittingTakeCash:false,
+	transferConfirmDialog:false,
+	pendingTakeCash:null,
+	transferConfirming:false,
+	transferCanceling:false
   },
   onLoad: function (options) {
     this.getBalanceInfo()
@@ -165,9 +169,7 @@ Page({
   },
   getBankInfoAndTip(){
   	var that = this
-  	that.requestTakeCashSubscribe(function () {
-  	  that.showWithdrawConfirm()
-  	})
+  	that.showWithdrawConfirm()
   },
   showWithdrawConfirm () {
   	var that = this
@@ -199,9 +201,7 @@ Page({
       var that = this
       console.log('that.data.has_bank',that.data.has_bank)
   //  if (that.data.has_bank) {
-        that.requestTakeCashSubscribe(function () {
-          that.withdrawClick()
-        })
+        that.withdrawClick()
   //  } else {
   //    that.setData({
   //      confirmDialog: false,
@@ -209,24 +209,6 @@ Page({
   //    })
   //  }
     },
-    requestTakeCashSubscribe (done) {
-      if (!wx.requestSubscribeMessage) {
-        done && done()
-        return
-      }
-      wx.requestSubscribeMessage({
-        tmplIds: [TAKE_CASH_SUBSCRIBE_TEMPLATE_ID],
-        success: function (res) {
-          console.log("take cash subscribe message", res)
-        },
-        fail: function (res) {
-          console.log("take cash subscribe message fail", res)
-        },
-        complete: function () {
-          done && done()
-        }
-      })
-    },
     closedDialog () {
       var that = this
       that.setData({
@@ -235,29 +217,149 @@ Page({
     },
     withdrawClick () {
       var that = this
+      if (that.data.submittingTakeCash) {
+        return
+      }
       var url = 'v1/user/takecash'
       var params = {
         amount: that.data.withdraw_num
       }
+      that.setData({
+        submittingTakeCash: true
+      })
       var success = function (res) {
+        that.setData({
+          submittingTakeCash: false
+        })
         if (res.data) {
           that.setData({
             confirmDialog: false
           })
-          // that.data.lockWithdraw = false
+          if (res.data.can_confirm_transfer && res.data.package_info) {
+            that.showTakeCashTransferConfirm(res.data)
+          } else {
+            that.finishTakeCashTransfer('提现成功~')
+          }
+        }
+      }
+      var fail = function () {
+        that.setData({
+          submittingTakeCash: false
+        })
+      }
+      _request.$post(url, params, success, fail)
+    },
+    showTakeCashTransferConfirm (order) {
+      this.setData({
+        pendingTakeCash: order,
+        transferConfirmDialog: true,
+        transferConfirming: false,
+        transferCanceling: false
+      })
+    },
+    confirmTakeCashTransfer () {
+      var that = this
+      var order = that.data.pendingTakeCash || {}
+      if (that.data.transferConfirming) {
+        return
+      }
+      if (!order.package_info) {
+        wx.showToast({
+          title: '提现确认信息缺失,请稍后重试',
+          icon: 'none',
+          duration: 2000
+        })
+        return
+      }
+      if (!wx.canIUse || !wx.canIUse('requestMerchantTransfer')) {
+        wx.showToast({
+          title: '当前微信版本不支持确认收款,请升级微信',
+          icon: 'none',
+          duration: 2000
+        })
+        return
+      }
+      that.setData({
+        transferConfirming: true
+      })
+      wx.requestMerchantTransfer({
+        mchId: String(order.mch_id || ''),
+        appId: String(order.app_id || ''),
+        package: order.package_info,
+        success: function () {
+          that.setData({
+            transferConfirmDialog: false,
+            pendingTakeCash: null,
+            transferConfirming: false
+          })
+          that.finishTakeCashTransfer('确认收款已提交')
+        },
+        fail: function (res) {
+          that.setData({
+            transferConfirming: false
+          })
+          var errMsg = (res && res.errMsg) ? res.errMsg : ''
           wx.showToast({
-            title: '提现成功~',
+            title: errMsg.indexOf('cancel') >= 0 ? '用户取消确认,可继续确认或取消提现' : '确认收款失败,请稍后重试',
             icon: 'none',
-            duration: 2000
-          })
-		  getApp().globalData.withdrawChanged = true
-		  that.refreshBalancePage()
-		  that.getCashTotal()
-          wx.navigateTo({
-            url: '/packageUser/pages/user/withdraw/withdraw'
+            duration: 3000
           })
         }
+      })
+    },
+    cancelTakeCashTransfer () {
+      var that = this
+      var order = that.data.pendingTakeCash || {}
+      if (that.data.transferCanceling) {
+        return
       }
-      _request.$post(url, params, success)
+      if (!order.order_id && !order.id) {
+        that.setData({
+          transferConfirmDialog: false,
+          pendingTakeCash: null
+        })
+        return
+      }
+      that.setData({
+        transferCanceling: true
+      })
+      var params = {
+        order_id: order.order_id || '',
+        id: order.id || ''
+      }
+      var success = function () {
+        that.setData({
+          transferConfirmDialog: false,
+          pendingTakeCash: null,
+          transferCanceling: false
+        })
+        wx.showToast({
+          title: '已取消提现',
+          icon: 'none',
+          duration: 2000
+        })
+        getApp().globalData.withdrawChanged = true
+        that.refreshBalancePage()
+        that.getCashTotal()
+      }
+      var fail = function () {
+        that.setData({
+          transferCanceling: false
+        })
+      }
+      _request.$post('v1/user/takecash/cancel', params, success, fail)
+    },
+    finishTakeCashTransfer (title) {
+      wx.showToast({
+        title: title || '提现成功~',
+        icon: 'none',
+        duration: 2000
+      })
+	  getApp().globalData.withdrawChanged = true
+	  this.refreshBalancePage()
+	  this.getCashTotal()
+      wx.navigateTo({
+        url: '/packageUser/pages/user/withdraw/withdraw'
+      })
     },
 })

+ 11 - 0
packageUser/pages/user/cash/cash.wxml

@@ -35,6 +35,17 @@
       <view class="withdraw" bindtap="confrimClick">确认提现</view>
     </view>
   </view>
+  <!-- 微信零钱收款确认 -->
+  <view class="fund__modal" wx:if="{{transferConfirmDialog}}">
+    <view class="content transfer-content">
+      <view class="doing transfer-title">确认后将转入微信零钱</view>
+      <view class="transfer-actions">
+        <view class="transfer-btn transfer-cancel" bindtap="cancelTakeCashTransfer">取消</view>
+        <view class="transfer-btn transfer-confirm" bindtap="confirmTakeCashTransfer">确认</view>
+        <view class="clean"></view>
+      </view>
+    </view>
+  </view>
   <!-- 未认证提示弹框 -->
   <view class="fund__modal" wx:if="{{identityDialog}}">
     <view class="content">

+ 35 - 1
packageUser/pages/user/cash/cash.wxss

@@ -186,6 +186,40 @@
   font-size: 28rpx;
   padding-bottom: 44rpx;
 }
+.fund__modal .transfer-content {
+  padding: 72rpx 40rpx 40rpx;
+  border-radius: 8rpx;
+  box-sizing: border-box;
+}
+.fund__modal .transfer-title {
+  font-size: 32rpx;
+  color: #4c4c4c;
+  line-height: 48rpx;
+}
+.fund__modal .transfer-actions {
+  width: 100%;
+  margin-top: 56rpx;
+}
+.fund__modal .transfer-btn {
+  float: left;
+  width: 220rpx;
+  height: 76rpx;
+  border-radius: 38rpx;
+  line-height: 76rpx;
+  font-size: 28rpx;
+  text-align: center;
+  box-sizing: border-box;
+}
+.fund__modal .transfer-cancel {
+  border: 1rpx solid #d8d8d8;
+  color: #7f93ae;
+  background: #fff;
+  margin-right: 40rpx;
+}
+.fund__modal .transfer-confirm {
+  color: #fff;
+  background-image: linear-gradient(90deg, #eab86a 0%, #e23232 100%);
+}
 
 .radish-top__btn22{
 	width: 196rpx;
@@ -205,4 +239,4 @@
       right: 20rpx;
       top: 20rpx;
       color: #fff;
-}
+}

+ 138 - 33
packageUser/pages/user/fund/fund.js

@@ -1,5 +1,4 @@
 var _request = require('../../../../utils/request.js')
-var TAKE_CASH_SUBSCRIBE_TEMPLATE_ID = "L073dR84XibBZNxfvTkvTIemd7JAbj5o2Og7-VBAiX8"
 Page({
   data: {
     page: 1,
@@ -16,7 +15,12 @@ Page({
     has_bank:false,
     min_cash:0,
     max_cahs:0,
-	sourceurl:false
+	sourceurl:false,
+	submittingTakeCash:false,
+	transferConfirmDialog:false,
+	pendingTakeCash:null,
+	transferConfirming:false,
+	transferCanceling:false
   },
   onLoad: function (options) {
 	console.log('source',options);
@@ -136,9 +140,7 @@ Page({
   },
   getBankInfoAndTip(){
   	var that = this
-  	that.requestTakeCashSubscribe(function () {
-  	  that.showWithdrawConfirm()
-  	})
+  	that.showWithdrawConfirm()
   },
   showWithdrawConfirm () {
   	var that = this
@@ -215,9 +217,7 @@ Page({
     var that = this
     console.log('that.data.has_bank',that.data.has_bank)
 //  if (that.data.has_bank) {
-      that.requestTakeCashSubscribe(function () {
-        that.withdrawClick()
-      })
+      that.withdrawClick()
 //  } else {
 //    that.setData({
 //      confirmDialog: false,
@@ -225,24 +225,6 @@ Page({
 //    })
 //  }
   },
-  requestTakeCashSubscribe (done) {
-    if (!wx.requestSubscribeMessage) {
-      done && done()
-      return
-    }
-    wx.requestSubscribeMessage({
-      tmplIds: [TAKE_CASH_SUBSCRIBE_TEMPLATE_ID],
-      success: function (res) {
-        console.log("take cash subscribe message", res)
-      },
-      fail: function (res) {
-        console.log("take cash subscribe message fail", res)
-      },
-      complete: function () {
-        done && done()
-      }
-    })
-  },
   closedDialog () {
     var that = this
     that.setData({
@@ -251,27 +233,150 @@ Page({
   },
   withdrawClick () {
     var that = this
+    if (that.data.submittingTakeCash) {
+      return
+    }
     var url = 'v1/user/takecash'
     var params = {
       amount: that.data.cashTotal.available
     }
+    that.setData({
+      submittingTakeCash: true
+    })
     var success = function (res) {
+      that.setData({
+        submittingTakeCash: false
+      })
       if (res.data) {
         that.setData({
           confirmDialog: false
         })
-        // that.data.lockWithdraw = false
+        if (res.data.can_confirm_transfer && res.data.package_info) {
+          that.showTakeCashTransferConfirm(res.data)
+        } else {
+          that.finishTakeCashTransfer('提现成功~')
+        }
+      }
+    }
+    var fail = function () {
+      that.setData({
+        submittingTakeCash: false
+      })
+    }
+    _request.$post(url, params, success, fail)
+  },
+  showTakeCashTransferConfirm (order) {
+    this.setData({
+      pendingTakeCash: order,
+      transferConfirmDialog: true,
+      transferConfirming: false,
+      transferCanceling: false
+    })
+  },
+  confirmTakeCashTransfer () {
+    var that = this
+    var order = that.data.pendingTakeCash || {}
+    if (that.data.transferConfirming) {
+      return
+    }
+    if (!order.package_info) {
+      wx.showToast({
+        title: '提现确认信息缺失,请稍后重试',
+        icon: 'none',
+        duration: 2000
+      })
+      return
+    }
+    if (!wx.canIUse || !wx.canIUse('requestMerchantTransfer')) {
+      wx.showToast({
+        title: '当前微信版本不支持确认收款,请升级微信',
+        icon: 'none',
+        duration: 2000
+      })
+      return
+    }
+    that.setData({
+      transferConfirming: true
+    })
+    wx.requestMerchantTransfer({
+      mchId: String(order.mch_id || ''),
+      appId: String(order.app_id || ''),
+      package: order.package_info,
+      success: function () {
+        that.setData({
+          transferConfirmDialog: false,
+          pendingTakeCash: null,
+          transferConfirming: false
+        })
+        that.finishTakeCashTransfer('确认收款已提交')
+      },
+      fail: function (res) {
+        that.setData({
+          transferConfirming: false
+        })
+        var errMsg = (res && res.errMsg) ? res.errMsg : ''
         wx.showToast({
-          title: '提现成功~',
+          title: errMsg.indexOf('cancel') >= 0 ? '用户取消确认,可继续确认或取消提现' : '确认收款失败,请稍后重试',
           icon: 'none',
-          duration: 2000
-        })
-        wx.navigateTo({
-          url: '/packageUser/pages/user/withdraw/withdraw'
+          duration: 3000
         })
       }
+    })
+  },
+  cancelTakeCashTransfer () {
+    var that = this
+    var order = that.data.pendingTakeCash || {}
+    if (that.data.transferCanceling) {
+      return
+    }
+    if (!order.order_id && !order.id) {
+      that.setData({
+        transferConfirmDialog: false,
+        pendingTakeCash: null
+      })
+      return
+    }
+    that.setData({
+      transferCanceling: true
+    })
+    var params = {
+      order_id: order.order_id || '',
+      id: order.id || ''
+    }
+    var success = function () {
+      that.setData({
+        transferConfirmDialog: false,
+        pendingTakeCash: null,
+        transferCanceling: false
+      })
+      wx.showToast({
+        title: '已取消提现',
+        icon: 'none',
+        duration: 2000
+      })
+      getApp().globalData.withdrawChanged = true
+      that.refreshCashPage()
+      that.getCashTotal()
     }
-    _request.$post(url, params, success)
+    var fail = function () {
+      that.setData({
+        transferCanceling: false
+      })
+    }
+    _request.$post('v1/user/takecash/cancel', params, success, fail)
+  },
+  finishTakeCashTransfer (title) {
+    wx.showToast({
+      title: title || '提现成功~',
+      icon: 'none',
+      duration: 2000
+    })
+    getApp().globalData.withdrawChanged = true
+    this.refreshCashPage()
+    this.getCashTotal()
+    wx.navigateTo({
+      url: '/packageUser/pages/user/withdraw/withdraw'
+    })
   },
   getBanners: function () {
     var that = this

+ 12 - 1
packageUser/pages/user/fund/fund.wxml

@@ -46,6 +46,17 @@
       <view class="withdraw" bindtap="confrimClick">确认提现</view>
     </view>
   </view>
+  <!-- 微信零钱收款确认 -->
+  <view class="fund__modal" wx:if="{{transferConfirmDialog}}">
+    <view class="content transfer-content">
+      <view class="doing transfer-title">确认后将转入微信零钱</view>
+      <view class="transfer-actions">
+        <view class="transfer-btn transfer-cancel" bindtap="cancelTakeCashTransfer">取消</view>
+        <view class="transfer-btn transfer-confirm" bindtap="confirmTakeCashTransfer">确认</view>
+        <view class="clean"></view>
+      </view>
+    </view>
+  </view>
   <!-- 未认证提示弹框 -->
   <view class="fund__modal" wx:if="{{identityDialog}}">
     <view class="content">
@@ -60,4 +71,4 @@
     </view>
   </view>
 
-</view>
+</view>

+ 35 - 1
packageUser/pages/user/fund/fund.wxss

@@ -234,4 +234,38 @@
 .fund__modal .withdraw {
   font-size: 28rpx;
   padding-bottom: 44rpx;
-}
+}
+.fund__modal .transfer-content {
+  padding: 72rpx 40rpx 40rpx;
+  border-radius: 8rpx;
+  box-sizing: border-box;
+}
+.fund__modal .transfer-title {
+  font-size: 32rpx;
+  color: #4c4c4c;
+  line-height: 48rpx;
+}
+.fund__modal .transfer-actions {
+  width: 100%;
+  margin-top: 56rpx;
+}
+.fund__modal .transfer-btn {
+  float: left;
+  width: 220rpx;
+  height: 76rpx;
+  border-radius: 38rpx;
+  line-height: 76rpx;
+  font-size: 28rpx;
+  text-align: center;
+  box-sizing: border-box;
+}
+.fund__modal .transfer-cancel {
+  border: 1rpx solid #d8d8d8;
+  color: #7f93ae;
+  background: #fff;
+  margin-right: 40rpx;
+}
+.fund__modal .transfer-confirm {
+  color: #fff;
+  background-image: linear-gradient(90deg, #eab86a 0%, #e23232 100%);
+}