|
|
@@ -1,5 +1,12 @@
|
|
|
var _request = require('../../../../utils/request.js')
|
|
|
+var appConfig = require('../../../../utils/config.js')
|
|
|
var PENDING_VIRTUAL_RECHARGE_ORDER_KEY = 'pendingVirtualRechargeOrderId'
|
|
|
+var RECHARGE_WXPAY = 'recharge_wxpay'
|
|
|
+
|
|
|
+function isCashVrPayEnabled () {
|
|
|
+ return appConfig.cashVrPay === true
|
|
|
+}
|
|
|
+
|
|
|
Page({
|
|
|
|
|
|
/**
|
|
|
@@ -25,7 +32,11 @@ Page({
|
|
|
this.getCashTotal()
|
|
|
},
|
|
|
onShow: function () {
|
|
|
- this.syncPendingVirtualRecharge()
|
|
|
+ if (isCashVrPayEnabled()) {
|
|
|
+ this.syncPendingVirtualRecharge()
|
|
|
+ } else {
|
|
|
+ wx.removeStorageSync(PENDING_VIRTUAL_RECHARGE_ORDER_KEY)
|
|
|
+ }
|
|
|
},
|
|
|
getCashTotal () {
|
|
|
var that = this
|
|
|
@@ -48,25 +59,8 @@ Page({
|
|
|
},
|
|
|
createRecharge () {
|
|
|
var that = this
|
|
|
- var url = 'v1/virtual_pay/recharge'
|
|
|
var price = parseFloat(that.data.price)
|
|
|
var money = Math.round(price * 100)
|
|
|
- var params = {
|
|
|
- count: money
|
|
|
- }
|
|
|
- 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)
|
|
|
- }
|
|
|
- }
|
|
|
- var fail = function () {
|
|
|
- that.setData({
|
|
|
- lock: false
|
|
|
- })
|
|
|
- }
|
|
|
if (!price || isNaN(price)) {
|
|
|
wx.showToast({
|
|
|
title: '充值金额不能为空',
|
|
|
@@ -79,7 +73,7 @@ Page({
|
|
|
icon: 'none',
|
|
|
duration: 2000
|
|
|
})
|
|
|
- } else if (money % 100 !== 0) {
|
|
|
+ } else if (isCashVrPayEnabled() && money % 100 !== 0) {
|
|
|
wx.showToast({
|
|
|
title: '虚拟支付需输入整数元',
|
|
|
icon: 'none',
|
|
|
@@ -90,9 +84,123 @@ Page({
|
|
|
that.setData({
|
|
|
lock: true
|
|
|
})
|
|
|
- _request.$post(url, params, success, fail)
|
|
|
+ if (isCashVrPayEnabled()) {
|
|
|
+ that.createVirtualRecharge(money)
|
|
|
+ } else {
|
|
|
+ that.createWxRecharge(money)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ createWxRecharge (money) {
|
|
|
+ var that = this
|
|
|
+ var url = 'v1/recas_order/generate'
|
|
|
+ var params = {
|
|
|
+ count: money,
|
|
|
+ payway: RECHARGE_WXPAY
|
|
|
+ }
|
|
|
+ var success = function (res) {
|
|
|
+ if (res.data) {
|
|
|
+ that.wxRechargeClick(res.data)
|
|
|
+ } else {
|
|
|
+ that.setData({
|
|
|
+ lock: false
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var fail = function () {
|
|
|
+ that.setData({
|
|
|
+ lock: false
|
|
|
+ })
|
|
|
+ }
|
|
|
+ _request.$post(url, params, success, fail)
|
|
|
+ },
|
|
|
+ wxRechargeClick (order) {
|
|
|
+ var that = this
|
|
|
+ var url = 'v1/pay'
|
|
|
+ var params = {
|
|
|
+ order_id: order.order_id,
|
|
|
+ pay_way: order.pay_way || RECHARGE_WXPAY
|
|
|
+ }
|
|
|
+ var success = function (res) {
|
|
|
+ var payData = res.data && res.data.pay_data
|
|
|
+ if (!payData) {
|
|
|
+ that.setData({
|
|
|
+ lock: false
|
|
|
+ })
|
|
|
+ wx.showToast({
|
|
|
+ title: '支付参数异常',
|
|
|
+ icon: 'none',
|
|
|
+ duration: 2000
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ wx.requestPayment({
|
|
|
+ timeStamp: payData.timeStamp,
|
|
|
+ nonceStr: payData.nonceStr,
|
|
|
+ package: payData.package,
|
|
|
+ signType: payData.signType,
|
|
|
+ paySign: payData.paySign,
|
|
|
+ success: function () {
|
|
|
+ getApp().globalData.rechargeChanged = true
|
|
|
+ that.getCashTotal()
|
|
|
+ wx.showToast({
|
|
|
+ title: '充值成功',
|
|
|
+ icon: 'success',
|
|
|
+ duration: 1000
|
|
|
+ })
|
|
|
+ setTimeout(function () {
|
|
|
+ that.backAfterRecharge()
|
|
|
+ }, 1000)
|
|
|
+ },
|
|
|
+ fail: function (err) {
|
|
|
+ var errMsg = err && err.errMsg ? err.errMsg : ''
|
|
|
+ if (errMsg.indexOf('cancel') >= 0 || errMsg.indexOf('取消') >= 0) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '用户取消支付',
|
|
|
+ icon: 'none',
|
|
|
+ duration: 2000
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: '支付失败',
|
|
|
+ icon: 'none',
|
|
|
+ duration: 2000
|
|
|
+ })
|
|
|
+ }
|
|
|
+ that.setData({
|
|
|
+ lock: false
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ var fail = function () {
|
|
|
+ that.setData({
|
|
|
+ lock: false
|
|
|
+ })
|
|
|
+ }
|
|
|
+ _request.$post(url, params, success, fail)
|
|
|
+ },
|
|
|
+ createVirtualRecharge (money) {
|
|
|
+ var that = this
|
|
|
+ var url = 'v1/virtual_pay/recharge'
|
|
|
+ var params = {
|
|
|
+ count: money
|
|
|
+ }
|
|
|
+ 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)
|
|
|
}
|
|
|
}
|
|
|
+ var fail = function () {
|
|
|
+ that.setData({
|
|
|
+ lock: false
|
|
|
+ })
|
|
|
+ }
|
|
|
+ _request.$post(url, params, success, fail)
|
|
|
},
|
|
|
rechargeClick (payData) {
|
|
|
var that = this
|