From 36ee21ddd8c653bb8bbd79e749d4b0f39dcd8911 Mon Sep 17 00:00:00 2001 From: yvan.ni Date: Thu, 13 Jul 2023 15:12:28 +0800 Subject: [PATCH] pos收银支付的优化 --- packageE/pages/cart/cart2/cart2.js | 48 ++++++++++++++++++++++++++++++++++++++++-------- utils/pay.js | 21 +++++++++++++++++++-- utils/pay2.js | 15 +++++++++++++++ utils/util.js | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 123 insertions(+), 11 deletions(-) diff --git a/packageE/pages/cart/cart2/cart2.js b/packageE/pages/cart/cart2/cart2.js index 5607945..b1d635b 100644 --- a/packageE/pages/cart/cart2/cart2.js +++ b/packageE/pages/cart/cart2/cart2.js @@ -196,6 +196,8 @@ Page({ onLoad: function (t) { + this.data.fir_in=1; + wx.setNavigationBarTitle({ title: "填写订单", }) var th = this; this.setData({ is_b_now: t.is_bnow == undefined ? 0 : t.is_bnow, }); @@ -271,15 +273,46 @@ Page({ //----------子页返回父页触发---------- onShow: function () { - //富友支付取消支付强行回去 - var fy=ut.fy_back("/pages/user/order_list/order_list",1); - if(fy) return false; - - util_pay.set_fir(); var th = this; - th.data.g_cart_q_time = null; + //判断是不是第一次进入 + if(this.data.fir_in){ + this.data.fir_in=0; + }else{ + //富友支付取消支付强行回去 + var fy=ut.fy_back("/pages/user/order_list/order_list",1); + if(fy) return false; + util_pay.set_fir(); + + //-- 通联的第三方支付的返回优化 -- + ut.is_pay_ok("/pages/payment/pay_success/pay_success?type=2&order_sn=" + this.data.ok_order_sn,null,function (){ + //支付信息会先记录着 + if(!th.data.ok_order_sn) return false; + getApp().request.promiseGet("/api/weshop/order/page", + {data:{store_id:os.stoid,parent_sn:th.data.ok_order_sn}}).then(res=>{ + if(ut.ajax_ok(res)){ + var item=res.data.data.pageData[0]; + if(item.pay_status==1){ + //支付支付,返回首页 + ut.m_toast('支付成功'); + setTimeout(()=>{ + getApp().goto("/pages/payment/pay_success/pay_success?type=2&order_sn=" + th.data.ok_order_sn); + },1000) + }else{ + //支付支付,返回首页 + ut.m_toast('支付失败'); + setTimeout(()=>{ + getApp().goto("/pages/index/index/index"); + },1000) + } + } + }) + }); + } + + + th.data.g_cart_q_time = null; if (th.data.isclose == 0) { wx.navigateTo({ url: "/pages/index/index/index" @@ -5183,8 +5216,7 @@ Page({ // order_sn: data.data, //}, 1); - - + th.data.ok_order_sn=data.data; util_pay.pay(data.data, async function () { //app.my_warnning("支付成功",1,th); //setTimeout(function () { diff --git a/utils/pay.js b/utils/pay.js index 85934a7..decaabf 100644 --- a/utils/pay.js +++ b/utils/pay.js @@ -49,6 +49,9 @@ module.exports = { wx.hideLoading(); if(t.data.code==0){ + + var is_pos_pay=t.data.data.is_pos_pay; + //-- 富有的插件支付 -- if(t.data.data.is_fuioupay){ const plugin = requirePlugin('fuiou-pay') getApp().globalData.no_clear=1; @@ -84,12 +87,26 @@ module.exports = { },1000) }) + } + //-- 通联的支付插件 -- + else if(is_pos_pay){ + + var p_data=t.data.data; + delete p_data.is_pos_pay; //清理掉,不然签名不通过 + wx.openEmbeddedMiniProgram({ + appId: 'wxef277996acc166c3', + extraData: p_data, + fail(){ + //-- 取消不支付 -- + i.wx_paying=0; + "function" == typeof a && a(); + } + }) + }else{ i.weixinPay(t.data.data, e, a); } - - }else{ i.wx_paying=0; getApp().confirmBox(t.data.msg); diff --git a/utils/pay2.js b/utils/pay2.js index 632ea14..4ca5573 100644 --- a/utils/pay2.js +++ b/utils/pay2.js @@ -24,6 +24,7 @@ module.exports = { "function" == typeof succ && succ(1); }else{ + var is_pos_pay=t.data.data.is_pos_pay; if(t.data.data.is_fuioupay){ const plugin = requirePlugin('fuiou-pay') getApp().globalData.no_clear=1; @@ -51,6 +52,20 @@ module.exports = { fail(msg) i.wx_paying=0; }) + } + //-- 通联的支付插件 -- + else if(is_pos_pay){ + var p_data=t.data.data; + delete p_data.is_pos_pay; //清理掉,不然签名不通过 + wx.openEmbeddedMiniProgram({ + appId: 'wxef277996acc166c3', + extraData: p_data, + fail(){ + //-- 取消不支付 -- + i.wx_paying=0; + "function" == typeof a && a(); + } + }) }else { i.weixinPay(t.data.data, succ, fail); } diff --git a/utils/util.js b/utils/util.js index d024b94..15b2af5 100644 --- a/utils/util.js +++ b/utils/util.js @@ -799,7 +799,7 @@ module.exports = { return false }, - //优惠促销的数据的格式话 + //-- 优惠促销的数据的格式话 -- format_yh_act(fir_act){ var more_arr = []; if(fir_act){ @@ -875,6 +875,54 @@ module.exports = { return more_arr }, + m_toast(txt){ + wx.showToast({ + title: txt, + icon: 'none', + duration: 2500 + }) + }, + //-- 支付的结果判断是不是完成了,通联支付pos收银的返回 -- + is_pay_ok(back_url,err_url,func){ + if(!err_url){ + err_url="/pages/index/index/index"; + } + let options = wx.getEnterOptionsSync(); + if (options.scene == '1038' && options.referrerInfo.appId=='wxef277996acc166c3') { + let extraData = options.referrerInfo.extraData; + if (!extraData) { + if(func) func(); + } else { + // "支付成功"; + if (extraData.code == 'success') { + this.m_toast("支付成功") + //支付失败 + setTimeout(function () { + wx.redirectTo({ url: back_url}); + },2000) + } + // "支付已取消"; + else if (extraData.code == 'cancel') { + this.m_toast("取消支付") + //支付失败 + setTimeout(function () { + getApp().goto(err_url); + },2000) + } + // "支付失败:" + extraData.errmsg; + else { + this.m_toast("支付失败:" + extraData.errmsg) + //支付失败 + setTimeout(function () { + getApp().goto(err_url); + },2000) + } + + } + + } + }, + unserialize: unserialize, _throttle:_throttle, unserialize_o: unserialize_o, -- libgit2 0.21.4