From d70192cc750e095df2b9d10833446d6305eef685 Mon Sep 17 00:00:00 2001 From: yvan.ni Date: Fri, 27 Oct 2023 13:50:04 +0800 Subject: [PATCH] 购买流程的优化 --- packageC/pages/presell/cart/cart2.js | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ packageC/pages/presell/cart/cart2_pre.js | 204 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------- 2 files changed, 344 insertions(+), 22 deletions(-) diff --git a/packageC/pages/presell/cart/cart2.js b/packageC/pages/presell/cart/cart2.js index d9162cd..df8f483 100644 --- a/packageC/pages/presell/cart/cart2.js +++ b/packageC/pages/presell/cart/cart2.js @@ -1226,8 +1226,170 @@ Page({ }, + + //-- 服务卡项的支付的下一步 -- + submitForm_card_next: async function() { + + if (this.data.is_summit_ing == 1) return false; //--提交中退出-- + this.data.is_summit_ing = 1; + var th = this,pdata = new Array(); + + var item = { + 'user_id': to.globalData.user_id, + 'account': th.data.formData.order_amount, //使用余额 + 'store_id': oo.stoid, //商家 + 'list': new Array(), + }; + + //判断是不是购物车购买还是立即购买 + var gg = getApp().globalData.service_now; + if (!gg.pick_id) { + getApp().showWarning("未找到门店"); + return false; + } + var goods = { + 'card_id': th.data.bn_goods.id, + 'itemid': th.data.bn_goods.erpItemID, + 'qty': gg.goods_num, + 'price': th.data.bn_goods.money, + // 'price': th.data.formData.order_amount, + 'pickup_id': gg.pick_id, + 'pickup_keyid': gg.keyid, + 'prom_type': this.data.postdata.prom_type, //促销活动类型 + 'prom_id': this.data.postdata.prom_id, //促销活动id + }; + + if(this.data.postdata.prom_type == 1) { + goods.price = this.data.postdata.prom_price; + }; + + if(getApp().globalData.skinface_id){ + goods.skinface_id=getApp().globalData.skinface_id; + } + + if(this.data.postdata && this.data.postdata.is_pd_normal==1){ + goods.is_pd_normal=1; + } + + + //--导购分享过来的id-- + if (gg.guide_id) { + goods.guide_id = gg.guide_id; + goods.guide_type = gg.guide_type; + //调用接口判断是不是会员 + await getApp().request.promiseGet("/api/weshop/shoppingGuide/getId/" + oo.stoid + "/" + gg.guide_id, {}).then( + res => { + if (res.data.code == 0) { + goods.guide_name = res.data.data.salesman; + goods.guide_sn = res.data.data.salesman_no; + } + }) + } + + if(gg.groupchat_id){ + goods.groupchat_id=gg.groupchat_id + } + item.list.push(goods); + + pdata = item; + var str = JSON.stringify(pdata); + console.log("支付数据"); + console.log(str); + //return false; + wx.showLoading({ + title: "加载中" + }); + wx.request({ + url: oo.url + '/api/weshop/recharge/saveRecharge', + data: str, + method: 'POST', + header: { + 'content-type': 'application/json' + }, // 设置请求的 header + success: function(res) { + + wx.hideLoading(); + if (res.statusCode == 200) { + var data = res.data; + if (data.code == 0) { + th.data.order_id = data.data.order_id; + // console.log('myyyyyyyyyyyyyyyyyy', data.data); + if (th.data.is_cart) { + var list = th.data.cartlist_y; + for (var i = 0; i < list.length; i++) { + //删除购物车 + a.delete("/api/weshop/cartService/del/" + oo.stoid + "/" + list[i].id, {}); + } + } + var order_amount = pdata.account; + //要进行判断,如果是用微信支付,就要跳转到支付界面 + if (order_amount > 0) { + th.setData({ + isclose: 0 + }); + + t_pay.set_pay_url("/api/weshop/order/pay/createRechargeOrder") + t_pay.pay( + { + parentSn: data.data.order_sn, + store_id: oo.stoid + },function (){ + wx.showToast({ + title: '购买成功', + icon: 'success', + duration: 2000 + }); + setTimeout(function () { + wx.reLaunch({ + url: "/pages/payment/pay_success/pay_success?card=1&order_id=" + th.data.order_id, + }) + }, 1000) + + },function (e){ + + console.log('kkkkkkk'); + + wx.showToast({ + title: e, + icon: 'none', + duration: 2000 + }); + + setTimeout(function () { + wx.reLaunch({ + url: "/pages/user/order_list/order_list?index=2&tabindex=1", + }) + }, 1000) + + } + ) + } + } else { + th.data.is_summit_ing = 0; //是否提交中 + getApp().confirmBox(data.msg); + } + } else { + th.data.is_summit_ing = 0; //是否提交中 + console.log("index.js wx.request CheckCallUser statusCode" + res.statusCode); + } + }, + fail: function() { + th.data.is_summit_ing = 0; //是否提交中 + wx.hideLoading(); + console.log("index.js wx.request CheckCallUser fail"); + }, + complete: function() {} + }) + }, + //--------------------提交订单----------------------- async submitForm(t) { + + if(th.data.fwk==1){ + this.submitForm_card_next(); + return false; + } + var sub_value = t; if (this.data.is_summit_ing == 1) return false; //--提交中退出-- diff --git a/packageC/pages/presell/cart/cart2_pre.js b/packageC/pages/presell/cart/cart2_pre.js index d47431b..e7315ff 100644 --- a/packageC/pages/presell/cart/cart2_pre.js +++ b/packageC/pages/presell/cart/cart2_pre.js @@ -3,6 +3,7 @@ var t = getApp(), app = t, a = t.request, ut = require("../../../../utils/util.j var os = t.globalData.setting; var regeneratorRuntime = require('../../../../utils/runtime.js'); var util_pay = require("../../../../utils/pay.js"); +const t_pay = require("../../../utils/pay2.js"); Page({ data: { @@ -239,7 +240,7 @@ Page({ t.data.data.shop_price = prelist.presell_money; th.setData({ bn_goods: t.data.data, bn_pickname: gg.pick_name, prelist: prelist, act: act, - bn_pick: gg.pick_id, bn_t_exp_t: distr_t, bn_exp_type: et + bn_pick: gg.pick_id, bn_t_exp_t: distr_t, bn_exp_type: et,fwk:1 }); //计算价格 th.calculatePrice2(); @@ -813,7 +814,163 @@ Page({ }, - // -- 支付的下一步 -- + + //-- 服务卡项的支付的下一步 -- + submitForm_card_next: async function() { + + if (this.data.is_summit_ing == 1) return false; //--提交中退出-- + this.data.is_summit_ing = 1; + var th = this,pdata = new Array(); + + var item = { + 'user_id': to.globalData.user_id, + 'account': th.data.formData.order_amount, //使用余额 + 'store_id': oo.stoid, //商家 + 'list': new Array(), + }; + + //判断是不是购物车购买还是立即购买 + var gg = getApp().globalData.service_now; + if (!gg.pick_id) { + getApp().showWarning("未找到门店"); + return false; + } + var goods = { + 'card_id': th.data.bn_goods.id, + 'itemid': th.data.bn_goods.erpItemID, + 'qty': gg.goods_num, + 'price': th.data.bn_goods.money, + // 'price': th.data.formData.order_amount, + 'pickup_id': gg.pick_id, + 'pickup_keyid': gg.keyid, + 'prom_type': this.data.postdata.prom_type, //促销活动类型 + 'prom_id': this.data.postdata.prom_id, //促销活动id + }; + + if(this.data.postdata.prom_type == 1) { + goods.price = this.data.postdata.prom_price; + }; + + if(getApp().globalData.skinface_id){ + goods.skinface_id=getApp().globalData.skinface_id; + } + + if(this.data.postdata && this.data.postdata.is_pd_normal==1){ + goods.is_pd_normal=1; + } + + + //--导购分享过来的id-- + if (gg.guide_id) { + goods.guide_id = gg.guide_id; + goods.guide_type = gg.guide_type; + //调用接口判断是不是会员 + await getApp().request.promiseGet("/api/weshop/shoppingGuide/getId/" + oo.stoid + "/" + gg.guide_id, {}).then( + res => { + if (res.data.code == 0) { + goods.guide_name = res.data.data.salesman; + goods.guide_sn = res.data.data.salesman_no; + } + }) + } + + if(gg.groupchat_id){ + goods.groupchat_id=gg.groupchat_id + } + item.list.push(goods); + + pdata = item; + var str = JSON.stringify(pdata); + console.log("支付数据"); + console.log(str); + //return false; + wx.showLoading({ + title: "加载中" + }); + wx.request({ + url: oo.url + '/api/weshop/recharge/saveRecharge', + data: str, + method: 'POST', + header: { + 'content-type': 'application/json' + }, // 设置请求的 header + success: function(res) { + + wx.hideLoading(); + if (res.statusCode == 200) { + var data = res.data; + if (data.code == 0) { + th.data.order_id = data.data.order_id; + // console.log('myyyyyyyyyyyyyyyyyy', data.data); + if (th.data.is_cart) { + var list = th.data.cartlist_y; + for (var i = 0; i < list.length; i++) { + //删除购物车 + a.delete("/api/weshop/cartService/del/" + oo.stoid + "/" + list[i].id, {}); + } + } + var order_amount = pdata.account; + //要进行判断,如果是用微信支付,就要跳转到支付界面 + if (order_amount > 0) { + th.setData({ + isclose: 0 + }); + + t_pay.set_pay_url("/api/weshop/order/pay/createRechargeOrder") + t_pay.pay( + { + parentSn: data.data.order_sn, + store_id: oo.stoid + },function (){ + wx.showToast({ + title: '购买成功', + icon: 'success', + duration: 2000 + }); + setTimeout(function () { + wx.reLaunch({ + url: "/pages/payment/pay_success/pay_success?card=1&order_id=" + th.data.order_id, + }) + }, 1000) + + },function (e){ + + console.log('kkkkkkk'); + + wx.showToast({ + title: e, + icon: 'none', + duration: 2000 + }); + + setTimeout(function () { + wx.reLaunch({ + url: "/pages/user/order_list/order_list?index=2&tabindex=1", + }) + }, 1000) + + } + ) + } + } else { + th.data.is_summit_ing = 0; //是否提交中 + getApp().confirmBox(data.msg); + } + } else { + th.data.is_summit_ing = 0; //是否提交中 + console.log("index.js wx.request CheckCallUser statusCode" + res.statusCode); + } + }, + fail: function() { + th.data.is_summit_ing = 0; //是否提交中 + wx.hideLoading(); + console.log("index.js wx.request CheckCallUser fail"); + }, + complete: function() {} + }) + }, + + // -- 商品支付的下一步 -- submitForm_next: async function (t) { if (this.data.is_summit_ing == 1) return false; //--提交中退出-- this.data.is_summit_ing = 1; @@ -1029,14 +1186,11 @@ Page({ setTimeout(function () { th.setData({ isclose: 0 }); - var url = "/packageC/pages/presell/cart/cart?order_sn=" + data.data; wx.reLaunch({ url: url }) - - }, 1000) } }); @@ -1060,29 +1214,35 @@ Page({ }) }, - //--------------------提交订单----------------------- submitForm: function (t) { var th = this; //如果是部分定金,商家不同意退定金, if (this.data.act.presell_type != 1 && !this.data.act.is_refundmoney && !th.agree_no_ref) { - wx.showModal({ - content: ' 预售商品不允许退定金!是否继续下单?', - showCancel: true,//是否显示取消按钮 - cancelText: "我在想想",//默认是“取消” - confirmText: "继续下单",//默认是“确定” - success: function (res) { - if (res.cancel) { - //点击取消,默认隐藏弹框 - } else { - th.setData({ agree_no_ref: 1 }) - th.submitForm_next(t) - } - }, - }) - + wx.showModal({ + content: ' 预售商品不允许退定金!是否继续下单?', + showCancel: true,//是否显示取消按钮 + cancelText: "我在想想",//默认是“取消” + confirmText: "继续下单",//默认是“确定” + success: function (res) { + if (res.cancel) { + //点击取消,默认隐藏弹框 + } else { + th.setData({ agree_no_ref: 1 }) + if(th.data.fwk==1){ + th.submitForm_card_next(t) + }else{ + th.submitForm_next(t) + } + } + }, + }) } else { - this.submitForm_next(t); + if(th.data.fwk==1){ + th.submitForm_card_next(t) + }else{ + th.submitForm_next(t) + } } }, -- libgit2 0.21.4