Explorar el Código

fix: stabilize mini program payment flows

root hace 1 día
padre
commit
8996d6da27

+ 5 - 1
component/currency/currency.js

@@ -19,7 +19,11 @@ Component({
   },
   methods: {
     updata () {
-      var val = util.formatMoney(this.data.value / 100, this.data.symbol, 2)
+      var amount = Number(this.data.value)
+      if (isNaN(amount)) {
+        amount = 0
+      }
+      var val = util.formatMoney(amount / 100, this.data.symbol, 2)
       this.setData({
         price: val
       })

+ 11 - 3
packageUser/pages/user/cash/cash.js

@@ -69,6 +69,15 @@ Page({
     }
     _request.$get(url, params, success)
   },
+  refreshBalancePage () {
+    this.setData({
+      page: 1,
+      list: [],
+      more: true
+    })
+    this.getBalanceInfo()
+    this.getBalanceList()
+  },
   getDetail (val) {
     var id = val.currentTarget.dataset.val
     wx.navigateTo({
@@ -201,10 +210,9 @@ Page({
             icon: 'none',
             duration: 2000
           })
-		  that.getBalanceInfo()
-		  that.getBalanceList()
+		  getApp().globalData.withdrawChanged = true
+		  that.refreshBalancePage()
 		  that.getCashTotal()
-		  that.getWithDrawlimit()
           wx.navigateTo({
             url: '/packageUser/pages/user/withdraw/withdraw'
           })

+ 48 - 4
packageUser/pages/user/cashDetail/cashDetail.js

@@ -6,6 +6,16 @@ function formatTransferStateText (state) {
   }
   return state || ''
 }
+function normalizeTransferDetail (data) {
+  data = data || {}
+  data.count = Number(data.count) || 0
+  data.ctime = data.ctime || data.created_at || 0
+  data.source_name = data.source_name || '提现'
+  data.relate_id = data.relate_id || data.order_id || data.id || ''
+  data.remark = data.remark || data.state_cn || ''
+  data.transfer_state_text = formatTransferStateText(data.transfer_state || data.state_cn)
+  return data
+}
 Page({
   data: {
     detail: {},
@@ -13,8 +23,12 @@ Page({
     confirmedTransfer: false
   },
   onLoad: function (options) {
-    rid = options.id
-    this.getRadish()
+    rid = options.id || options.cash_id || options.balance_id || options.rid || options.order_id
+    if (rid) {
+      this.getRadish()
+      return
+    }
+    this.getLatestWithdrawRecord()
   },
   getRadish () {
     var that = this
@@ -22,17 +36,47 @@ Page({
     var params = {
     }
     var success = function (res) {
-      var data = res.data
+      var data = normalizeTransferDetail(res.data)
       if (that.data.confirmedTransfer) {
         data.can_confirm_transfer = false
       }
-      data.transfer_state_text = formatTransferStateText(data.transfer_state)
       that.setData({
         detail: data
       })
     }
     _request.$get(url, params, success)
   },
+  getLatestWithdrawRecord () {
+    var that = this
+    var url = 'v1/user/takecash/flow'
+    var params = {
+      page: 1,
+      per_page: 1
+    }
+    var success = function (res) {
+      var list = (res.data && res.data.list) || []
+      if (list.length > 0) {
+        that.setData({
+          detail: normalizeTransferDetail(list[0])
+        })
+        return
+      }
+      wx.showToast({
+        title: '暂无提现记录',
+        icon: 'none',
+        duration: 2000
+      })
+      wx.redirectTo({
+        url: '/packageUser/pages/user/withdraw/withdraw'
+      })
+    }
+    var fail = function () {
+      wx.redirectTo({
+        url: '/packageUser/pages/user/withdraw/withdraw'
+      })
+    }
+    _request.$get(url, params, success, fail)
+  },
   confirmMerchantTransfer () {
     var that = this
     var detail = that.data.detail || {}

+ 16 - 2
packageUser/pages/user/withdraw/withdraw.js

@@ -24,10 +24,13 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-    this.getCashTotal()
-    this.getCashList()
+    this.refreshCashList()
   },
   onShow () {
+    if (getApp().globalData.withdrawChanged) {
+      getApp().globalData.withdrawChanged = false
+      this.refreshCashList()
+    }
   },
   onPullDownRefresh: function () {
     this.setData({
@@ -47,6 +50,16 @@ Page({
       this.getCashList()
     }
   },
+  refreshCashList () {
+    this.setData({
+      page: 1,
+      cashList: [],
+      cashList_more: true,
+      cashList_change: false
+    })
+    this.getCashTotal()
+    this.getCashList()
+  },
   getCashTotal () {
     var that = this
     var url = 'v1/user/cash/balance/info'
@@ -136,6 +149,7 @@ Page({
         })
         var confirmedTransferIds = that.data.confirmedTransferIds || {}
         confirmedTransferIds[item.id] = true
+        getApp().globalData.withdrawChanged = true
         that.setData({
           page: 1,
           cashList_more: true,

+ 60 - 22
pages/pay/pay.js

@@ -2,6 +2,11 @@ var __request = require('../../utils/request.js')
 var _handle = require('../../utils/handle.js')
 var validator = require('../../utils/validator.js')
 
+function toNumber (val) {
+  var num = Number(val)
+  return isNaN(num) ? 0 : num
+}
+
 Page({
   data: {
     orderId: 0,
@@ -31,7 +36,8 @@ Page({
     total:0,
     yunfei:0,
 	_yunfei:0,
-    payFlag:false,
+	    payFlag:false,
+	    payCompleted:false,
     useBalance:false,
 	useCash:true,
     afterdec:0,//使用提货券扣除后的总额
@@ -50,7 +56,7 @@ Page({
 	unquan_silver:0,//不能使用提货券抵扣的银豆
 	
 	//20240314使用新接口获取相关扣除
-	payQueryData:{}
+		payQueryData:null
   },
   onLoad: function (options) {
     this.data.orderId = options.orderId;
@@ -86,9 +92,11 @@ Page({
 		}
 	}
   	
-  	this.setData({
-      payFlag: false
-    })
+    if (!this.data.payCompleted) {
+      this.setData({
+        payFlag: false
+      })
+    }
   },
   inputPwd: function (e) {
     this.setData({
@@ -112,17 +120,30 @@ Page({
     var url = "v1/order/" + that.data.orderId;
     var params = {}
 	var check_has_unuse_quan = false;
-    var success = function (val) {
-      if (val.data && val.data.product && !val.data.product.robo_balance_price) {
+	    var success = function (val) {
+	      val.data = val.data || {}
+	      val.data.product_list = val.data.product_list || []
+	      val.data.pay_way = val.data.pay_way || ''
+	      val.data.total_price = toNumber(val.data.total_price)
+	      val.data.freight = toNumber(val.data.freight)
+	      val.data.dis_amount = toNumber(val.data.dis_amount)
+	      val.data.coupon_price = toNumber(val.data.coupon_price)
+	      val.data.paied_cash = toNumber(val.data.paied_cash)
+	      val.data.paied_silver = toNumber(val.data.paied_silver)
+	      val.data.total_silver = toNumber(val.data.total_silver)
+	      if (val.data && val.data.product && !val.data.product.robo_balance_price) {
         that.setData({
           curPayway: 'weixinpay'
         })
       }
       
       var total = 0;
-		for(var i in val.data.product_list){
-			if(!val.data.product_list[i].send) total = total + (val.data.product_list[i].price * val.data.product_list[i].count)
-		}
+			for(var i in val.data.product_list){
+				val.data.product_list[i].price = toNumber(val.data.product_list[i].price)
+				val.data.product_list[i].count = toNumber(val.data.product_list[i].count)
+				val.data.product_list[i].silver = toNumber(val.data.product_list[i].silver)
+				if(!val.data.product_list[i].send) total = total + (val.data.product_list[i].price * val.data.product_list[i].count)
+			}
 	  
 	  var canusebalance = 0;
 	  var nousebalance = 0;
@@ -456,8 +477,8 @@ Page({
     })
   },
   toPay: function (e) {
-  	if(this.data.payFlag){
-  		wx.showToast({
+    if(this.data.payFlag || this.data.payCompleted){
+      wx.showToast({
         title: '支付中,请稍后...',
         icon: 'none',
         duration: 2000
@@ -654,36 +675,48 @@ Page({
 	          'signType': val.data.pay_data.signType,
 	          'paySign': val.data.pay_data.paySign,
 	          'success':function(res){
+	            that.setData({
+	              payCompleted: true
+	            })
 	            wx.showToast({
 	              title: '支付成功',
 	              icon: 'success',
 	              duration: 1000
 	            })
-	            wx.navigateTo({
+	            wx.redirectTo({
 	              // url:  '/packageUser/pages/user/orders/orders'
 	              url:  '/pages/projects/project-success/project-success?id=' + that.data.orderId
 	            })
-	            
-	            
 	          },
 	          'fail':function(res){
+	            if (res && res.errMsg && (res.errMsg.indexOf('已支付') > -1 || res.errMsg.indexOf('paid') > -1)) {
+	              that.setData({
+	                payCompleted: true
+	              })
+	              wx.redirectTo({
+	                url:  '/pages/projects/project-success/project-success?id=' + that.data.orderId
+	              })
+	              return
+	            }
 							that.setData({
 					      payFlag: false
 					    })
 					that.getOrderInfo()
 	          }
 	        })
+	        return
 	      } else {
 	        that.setData({
-	          pay: val.data
+	          pay: val.data,
+	          payCompleted: true
 	        });
 	        wx.redirectTo({
 	          // url: '/packageUser/pages/user/orders/orders'
 	          url:  '/pages/projects/project-success/project-success?id=' + that.data.orderId
 	        })
-	        
+	        return
 	      }
-	      
+
 	      that.setData({
 		      payFlag: false
 		    })
@@ -825,10 +858,15 @@ Page({
 		'use_balance':that.data.useCash, //是否使用余额
 		'pick_way':that.data.receivetype, //自提方式
      }
-     var success = function (res) {
-		that.setData({
-		  payQueryData:res.data
-		})
+	     var success = function (res) {
+			var data = res.data || {}
+			data.PaySilver = toNumber(data.PaySilver)
+			data.PayCoupon = toNumber(data.PayCoupon)
+			data.PayBalance = toNumber(data.PayBalance)
+			data.ShouldPay = toNumber(data.ShouldPay)
+			that.setData({
+			  payQueryData:data
+			})
      }
      __request.$post(url, params, success)
    }