Quellcode durchsuchen

fix: reconcile pending virtual recharge

root vor 1 Tag
Ursprung
Commit
57aa59e3c9
2 geänderte Dateien mit 91 neuen und 8 gelöschten Zeilen
  1. 35 1
      packageUser/pages/user/cash/cash.js
  2. 56 7
      packageUser/pages/user/recharge/recharge.js

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

@@ -2,6 +2,7 @@ var _request = require('../../../../utils/request.js')
 var util = require('../../../../utils/util.js')
 var MAX_MERCHANT_TRANSFER_CASH = 20000
 var TAKE_CASH_SUBSCRIBE_TEMPLATE_ID = "pmQeRrQUpBvt2jgDF4XwSEfDd7n2Gnyk8k_au1G6wP8"
+var PENDING_VIRTUAL_RECHARGE_ORDER_KEY = 'pendingVirtualRechargeOrderId'
 Page({
   data: {
     page: 1,
@@ -15,7 +16,8 @@ Page({
 	fee:0,
 	withdraw_num:0,
 	view_withdraw:0,
-	view_fee:0
+	view_fee:0,
+	syncingPendingRecharge:false
   },
   onLoad: function (options) {
     this.getBalanceInfo()
@@ -23,6 +25,7 @@ Page({
 	// this.getCashTotal()
   },
   onShow () {
+    this.syncPendingVirtualRecharge()
     if (getApp().globalData.rechargeChanged) {
       getApp().globalData.rechargeChanged = false
       this.refreshBalancePage()
@@ -82,6 +85,37 @@ Page({
     this.getBalanceInfo()
     this.getBalanceList()
   },
+  syncPendingVirtualRecharge () {
+    var that = this
+    if (that.data.syncingPendingRecharge) {
+      return
+    }
+    var url = 'v1/virtual_pay/recharge/sync_pending'
+    var success = function (res) {
+      that.setData({
+        syncingPendingRecharge: false
+      })
+      if (res.data && res.data.synced_count > 0) {
+        wx.removeStorageSync(PENDING_VIRTUAL_RECHARGE_ORDER_KEY)
+        getApp().globalData.rechargeChanged = false
+        wx.showToast({
+          title: '充值成功',
+          icon: 'success',
+          duration: 1000
+        })
+        that.refreshBalancePage()
+      }
+    }
+    var fail = function () {
+      that.setData({
+        syncingPendingRecharge: false
+      })
+    }
+    that.setData({
+      syncingPendingRecharge: true
+    })
+    _request.$get(url, {}, success, fail)
+  },
   getDetail (val) {
     var id = val.currentTarget.dataset.val
     wx.navigateTo({

+ 56 - 7
packageUser/pages/user/recharge/recharge.js

@@ -1,4 +1,5 @@
 var _request = require('../../../../utils/request.js')
+var PENDING_VIRTUAL_RECHARGE_ORDER_KEY = 'pendingVirtualRechargeOrderId'
 Page({
 
   /**
@@ -8,6 +9,7 @@ Page({
     price: '',
     cashTotal: 0,
     lock: false,
+    syncingPendingRecharge: false,
 	source:''
   },
   /**
@@ -22,6 +24,9 @@ Page({
 	  }
     this.getCashTotal()
   },
+  onShow: function () {
+    this.syncPendingVirtualRecharge()
+  },
   getCashTotal () {
     var that = this
     var url = 'v1/user/cash/balance/info'
@@ -51,6 +56,9 @@ Page({
     }
     var success = function (res) {
       if (res.data) {
+        if (res.data.order_id) {
+          wx.setStorageSync(PENDING_VIRTUAL_RECHARGE_ORDER_KEY, res.data.order_id)
+        }
         that.rechargeClick(res.data)
       }
     }
@@ -118,14 +126,20 @@ Page({
       },
       fail: function (err) {
         console.error('requestVirtualPayment fail', err)
-        that.setData({
-          lock: false
-        })
-        wx.showModal({
-          confirmColor: '#eab86a',
-          content: (err && (err.errMsg || err.err_code || err.errCode)) ? ('虚拟支付调起失败:' + (err.errMsg || err.err_code || err.errCode)) : '虚拟支付调起失败',
-          showCancel: false
+        var errMsg = err && (err.errMsg || err.err_code || err.errCode) ? (err.errMsg || err.err_code || err.errCode) : ''
+        if (errMsg.indexOf('cancel') >= 0 || errMsg.indexOf('取消') >= 0) {
+          wx.removeStorageSync(PENDING_VIRTUAL_RECHARGE_ORDER_KEY)
+          that.setData({
+            lock: false
+          })
+          return
+        }
+        wx.showToast({
+          title: '支付结果确认中',
+          icon: 'none',
+          duration: 1500
         })
+        that.waitRechargePaid(payData.order_id, 0)
       }
     })
   },
@@ -134,6 +148,7 @@ Page({
     var url = 'v1/virtual_pay/recharge/status'
     var success = function (res) {
       if (res.data && res.data.state === 1) {
+        wx.removeStorageSync(PENDING_VIRTUAL_RECHARGE_ORDER_KEY)
         getApp().globalData.rechargeChanged = true
         that.getCashTotal()
         wx.showToast({
@@ -167,6 +182,40 @@ Page({
     }
     _request.$get(url, { order_id: oid }, success, fail)
   },
+  syncPendingVirtualRecharge () {
+    var that = this
+    if (that.data.syncingPendingRecharge) {
+      return
+    }
+    var pendingOrderId = wx.getStorageSync(PENDING_VIRTUAL_RECHARGE_ORDER_KEY)
+    var url = 'v1/virtual_pay/recharge/sync_pending'
+    var success = function (res) {
+      that.setData({
+        syncingPendingRecharge: false
+      })
+      if (res.data && res.data.synced_count > 0) {
+        wx.removeStorageSync(PENDING_VIRTUAL_RECHARGE_ORDER_KEY)
+        getApp().globalData.rechargeChanged = true
+        that.getCashTotal()
+        wx.showToast({
+          title: '充值成功',
+          icon: 'success',
+          duration: 1000
+        })
+      } else if (pendingOrderId) {
+        that.waitRechargePaid(pendingOrderId, 0)
+      }
+    }
+    var fail = function () {
+      that.setData({
+        syncingPendingRecharge: false
+      })
+    }
+    that.setData({
+      syncingPendingRecharge: true
+    })
+    _request.$get(url, {}, success, fail)
+  },
   backAfterRecharge () {
     var that = this
     that.setData({