pay.js 5.27 KB
var t = getApp(), n = t.request,wx_paying=0;

module.exports = {
    url: "/api/weshop/order/pay/createOrder",
    rechange: function(t, e, a) {
        var i = this;
        n.post(this.url, {
            data: {
                account: t
            },
            success: function(t) {
                i.weixinPay(t.data.result, e, a);
            },
            fail: function() {
                "function" == typeof a && a();
            },
            failStatus: function() {
                "function" == typeof a && a();
            }
        });
    },
    pay: function(t, e, a,sto,type) {

        if(wx_paying) return false;
        wx_paying=1;

        var i = this;
        var dd = {
          parent_sn: t,
          store_id: sto,
          type: 2,
        };
        if (type == 1) dd.type = 1;

        if(getApp().globalData.scene)
            dd.scene=getApp().globalData.scene;

        console.log(dd,'支付场景');

        wx.showLoading();
        n.post(this.url, {
            data: dd,
            success: function(t) {
              console.log('======', t)
                wx.hideLoading();
                if(t.data.code==0){

                    if(t.data.data.is_fuioupay){
                        const plugin = requirePlugin('fuiou-pay')

                        var paramsJson={
                            reqType:"11",//必填 01-商户模式,11-机构模式
                            reqData:t.data.data.reqData,//必填 富友加密参数
                        }
                        console.log(plugin, plugin.fuioupay)
                        plugin.fuioupay(parseInt(t.data.data.amt),paramsJson,function (res){
                          console.log(res);
                            wx_paying=0;
                            getApp().showSuccess("支付成功!", e);

                        },function (error){
                          console.log("插件支付错误",error);
                            //支付失败的时候
                            getApp().confirmBox(error.code+error.message);
                            setTimeout(function(){
                                wx.redirectTo({
                                    url: "/pages/user/order_list/order_list",
                                });
                            },1000)
                            wx_paying=0;
                        })
                    }else{
                        i.weixinPay(t.data.data, e, a);
                    }



                }else{
                    getApp().confirmBox(t.data.msg);
                    setTimeout(function(){
                        wx.redirectTo({
                            url: "/pages/user/order_list/order_list",
                        });
                    },1000)
                    wx_paying=0;
                }
                return false;
            },
            fail: function() {
              console.log('======fail', )
              wx.hideLoading();
                wx_paying=0;
                "function" == typeof a && a();
            },
            failStatus: function() {
                wx.hideLoading();
                wx_paying=0;
                "function" == typeof a && a();
            }
        });
    },
    weixinPay: function(n, e, a) {
	   if(!n) return false;

        getApp().globalData.no_clear=1;

        //有的话用最新的支付方式
       if(n.orderInfo) {
           wx.requestOrderPayment({
               timeStamp: String(n.timeStamp),
               nonceStr: n.nonceStr,
               package: n.packageValue,
               signType: n.signType,
               paySign: n.paySign,
               orderInfo: n.orderInfo, // 需要新增的 订单 信息
               success (n) {
                   wx_paying=0;
                   t.showSuccess("支付成功!", e);
               },
               fail (n) {
                   wx_paying=0;
                   if(!n.errMsg )  {
                       getApp().showWarning("支付失败");
                       "function" == typeof fail && fail();
                       return false;
                   }

                   console.log(n), "requestOrderPayment:fail" == n.errMsg ? t.showWarning("支付失败") : "requestOrderPayment:fail cancel" == n.errMsg ? t.showWarning("您已取消支付") :
                           t.confirmBox("支付失败:" + n.errMsg.substr("requestOrderPayment:fail ".length)),
                   "function" == typeof a && a();
               }
           })

       }else{
           wx.requestPayment({
               timeStamp: String(n.timeStamp),
               nonceStr: n.nonceStr,
               package: n.packageValue,
               signType: n.signType,
               paySign: n.paySign,
               success: function (n) {
                   wx_paying=0;
                   console.log(n), t.showSuccess("支付成功!", e);
               },
               fail: function (n) {
                   wx_paying=0;
                   console.log(n), "requestPayment:fail" == n.errMsg ? t.showWarning("支付失败") : "requestPayment:fail cancel" == n.errMsg ? t.showWarning("您已取消支付") :
                           t.confirmBox("支付失败:" + n.errMsg.substr("requestPayment:fail ".length)),
                   "function" == typeof a && a();
               }
           });
       }








    }
};