From 5eb612205b83da421b6870207e6900f735a7b152 Mon Sep 17 00:00:00 2001 From: yvan.ni Date: Thu, 22 Feb 2024 16:09:57 +0800 Subject: [PATCH] 订单促销的取价规则 --- packageE/pages/cart/cart2/cart2.js | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------ packageE/pages/cart/cart2/cart2.wxml | 12 ++++++------ packageE/pages/cart/cart2_inte/cart2_inte.js | 189 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------ packageE/pages/cart/cart2_inte/cart2_inte.wxml | 8 ++++++++ packageE/pages/cart/cart2_pt/cart2_pt.js | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- packageE/pages/cart/cart2_pt/cart2_pt.wxml | 7 +++++++ 6 files changed, 414 insertions(+), 56 deletions(-) diff --git a/packageE/pages/cart/cart2/cart2.js b/packageE/pages/cart/cart2/cart2.js index da76250..5c81ba8 100644 --- a/packageE/pages/cart/cart2/cart2.js +++ b/packageE/pages/cart/cart2/cart2.js @@ -1042,35 +1042,9 @@ Page({ //-- 多促销活动调用接口需要的参数,和商品的购买数量和活动的购买数量的请求参数 -- var dug_cx_arr = []; //获取 限购 和 多活动的促销---2024-2-1 - for (var i = 0; i < carr.length; i++) { - - let item1 = carr[i]; - - //如果有户有点击参与订单促销的话,那么可以参与订单促销的商品的活动都要清理成0,订单促销在使用过程中的重要方法 - if (this.data.can_use_ord_prom[item1.pick_id]) { - //从订单促销的order_prom_map_ck数据结构中获取到可以参与的商品列表 - let gdlist = this.data.order_prom_map_ck[item1.pick_id] ? this.data.order_prom_map_ck[item1.pick_id].goodsList : null; - if (gdlist && gdlist.length) { - //查找商品item1有没有在gdlist中,就要把商品的prom_type清理0 - let f_idx = gdlist.findIndex(function (ele) { - return ele.id == item1.id - }); - if (f_idx != -1) { - //开始变换商品的价格显示 - switch (th.data.show_ord_prom[item1.pick_id]) { - case 1: - carr[i].goods_price = item1.shop_price; - break; - case 2: - carr[i].goods_price = item1.goods_market_price; - break; - } - carr[i].prom_type = 0; - continue; //要跳过 - } - } - } + for (var iv = 0; iv < carr.length; iv++) { + let item1 = carr[iv]; //如果不是活动的时候,不是代发商品的时候,不是赠品的时候,不是阶梯商品拆分的,不是组合购拆分的 if ([1, 2, 4, 6, 8, 9].indexOf(item1.prom_type) == -1 && !item1.whsle_id && !item1.is_gift && !item1.is_ld_split && !item1.is_zh_split) { @@ -1080,7 +1054,7 @@ Page({ }); if (f_idx == -1) { let gd_ite = { - goods_id: carr[i].goods_id, + goods_id: carr[iv].goods_id, goods_num: 1, is_limit_show: 1, is_state: 0 @@ -1091,7 +1065,7 @@ Page({ } if (is_change) { - carr[i].collocationList = null; + carr[iv].collocationList = null; } } //-- 对商品的多促销进行判断 ---2024-2-1-- @@ -1099,9 +1073,46 @@ Page({ await th.buy_pro_group(dug_cx_arr,carr); } } + //在分组的时候,就不要再调用接口,await for (var i = 0; i < carr.length; i++) { var item = carr[i]; + + //如果有户有点击参与订单促销的话,那么可以参与订单促销的商品的活动都要清理成0,订单促销在使用过程中的重要方法 + if (this.data.can_use_ord_prom[item.pick_id]) { + //从订单促销的order_prom_map_ck数据结构中获取到可以参与的商品列表 + let gdlist = this.data.order_prom_map_ck[item.pick_id] ? this.data.order_prom_map_ck[item.pick_id].goodsList : null; + if (gdlist && gdlist.length) { + //查找商品item1有没有在gdlist中,就要把商品的prom_type清理0 + let f_idx = gdlist.findIndex(function (ele) { + return ele.id == item1.id + }); + if (f_idx != -1) { + //开始变换商品的价格显示 + switch (th.data.show_ord_prom[item1.pick_id]) { + case 1: + carr[i].goods_price = item1.shop_price; + break; + case 2: + carr[i].goods_price = item1.goods_market_price; + break; + } + + if(!carr[i].prom_type) carr[i].prom_type=0; + switch (parseInt(carr[i].prom_type)){ + case 4: + carr[i].is_integral_normal = 1; + break; + default: + carr[i].is_pd_normal = 1; + break; + } + carr[i].prom_type = 0; + carr[i].discount_field = th.data.show_ord_prom[item1.pick_id]; + } + } + } + //-- 如果是等级会员注册返回 -- if (is_card_back) { th.data.card_name = th.data.userinfo.card_field; @@ -4950,6 +4961,12 @@ Page({ 'prom_id': th.data.bn_goods.prom_id, //促销活动id }; + //如果有参与非实收的订单促销,那么就相当于是普通购买 + if(th.data.can_use_ord_prom[th.data.bn_pick]){ + goods.is_pd_normal=1; + goods.discount_field= th.data.show_ord_prom[th.data.bn_pick]; + } + if (th.data.bn_goods.whsle_id) { item.is_whsle = 1; item.whsle_id = th.data.bn_goods.whsle_id; @@ -5343,6 +5360,11 @@ Page({ 'store_id': oo.stoid, }; + //订单促销取价规则使用 + if (g_item.discount_field) { + goods.discount_field =g_item.discount_field; + } + if (g_item.is_pd_normal) { goods.is_pd_normal = 1; } @@ -9012,6 +9034,10 @@ Page({ good.shop_price=good.market_price; break; } + + //-- 转成普通商品 --- + good.prom_type=0; + good.prom_id=0; }else{ good=ut.deep_cp(th.data.old_bn_goods); } diff --git a/packageE/pages/cart/cart2/cart2.wxml b/packageE/pages/cart/cart2/cart2.wxml index c61ad0f..8bd8dc8 100644 --- a/packageE/pages/cart/cart2/cart2.wxml +++ b/packageE/pages/cart/cart2/cart2.wxml @@ -355,9 +355,9 @@ - - - 参与订单促销 + + + 参与订单促销 @@ -695,9 +695,9 @@ - - - 参与订单促销 + + + 参与订单促销 diff --git a/packageE/pages/cart/cart2_inte/cart2_inte.js b/packageE/pages/cart/cart2_inte/cart2_inte.js index 2503b41..9822600 100644 --- a/packageE/pages/cart/cart2_inte/cart2_inte.js +++ b/packageE/pages/cart/cart2_inte/cart2_inte.js @@ -85,7 +85,14 @@ Page({ same_ok:1, //同城配送的控制,默认ok bconfig: null, showFold:true, - template_id:[] + template_id:[], + + //-- 订单促销判断积累 ---2024-2-20 + order_prom_map_ck: {}, + //能不能使用订单促销 + can_use_ord_prom:{}, + //存储订单促销的取价,按照门店进行索引 + show_ord_prom:{}, }, @@ -632,6 +639,8 @@ Page({ success: async function (tt) { if (tt.data.code == 0 && tt.data.data && tt.data.data.pageData) { var inte_data = tt.data.data.pageData[0]; + + gd.shop_price_y=gd.shop_price; t.data.data.shop_price = inte_data.addmoney; t.data.data.integral = inte_data.integral; @@ -658,6 +667,9 @@ Page({ + //用深拷贝把商品缓存起来,方便后面使用 + th.data.old_bn_goods=ut.deep_cp(t.data.data); + th.setData({ bn_goods: t.data.data, bn_pickname: gg.pick_name, bn_exp_type: et, index: m_wind, bn_pick: gg.pick_id, bn_t_exp_t: distr_t, bn_exp_type: et,inv_is_post:inte_data.is_post @@ -742,16 +754,23 @@ Page({ var condition = parseFloat(allpice-cut_price).toFixed(2); var ord_prom = null; var is_ord_prom_post = 0; + //---如果有选择优惠券的情况下--- + var quan_price = 0, bn_pick = th.data.bn_pick; if (condition > 0 && th.data.bn_is_order_yh && !th.data.bn_goods.whsle_id) { - await getApp().request.promiseGet("/api/weshop/promorder/getOrderPromotion", { - data: { store_id: os.stoid, orderAmount: condition, user_id: getApp().globalData.user_id } - }).then(res => { - if (res.data.code == 0) { - var data = res.data.data; - ord_prom = data; - } - }) + // await getApp().request.promiseGet("/api/weshop/promorder/getOrderPromotion", { + // data: { store_id: os.stoid, orderAmount: condition, user_id: getApp().globalData.user_id } + // }).then(res => { + // if (res.data.code == 0) { + // var data = res.data.data; + // ord_prom = data; + // } + // }) + + th.set_by_now_ord_prom(th.data.bn_goods); + th.data.order_prom_map_ck[bn_pick].goods_price_all=condition; + ord_prom=await th.get_cur_ord_prom(bn_pick); + if (ord_prom && ord_prom.is_post_temp) { is_ord_prom_post = 1; } @@ -894,8 +913,7 @@ Page({ var wl_txt = "formData.shipping_price"; th.setData({ [wl_txt]: 0, }) } - //---如果有选择优惠券的情况下--- - var quan_price = 0, bn_pick = th.data.bn_pick; + //-----------------支付价,优惠券不减物流----------------- var total_m = (parseFloat(allpice)).toFixed(2); @@ -1281,7 +1299,6 @@ Page({ item.samecity_order_amount=th.data.bn_samecity_order_amount; } - //获取立即购买的商品的信息 var gg = to.get_b_now(); //--商品的房间号-- @@ -1319,6 +1336,15 @@ Page({ 'prom_id': th.data.bn_goods.prom_id, //促销活动id }; + if(th.data.bn_goods.discount_field){ + goods.discount_field=th.data.bn_goods.discount_field; + } + + //如果有参与非实收的订单促销,那么就相当于是普通购买 + if(th.data.can_use_ord_prom[th.data.bn_pick]){ + goods.is_integral_normal=1; + } + if(getApp().globalData.skinface_id){ goods.skinface_id=getApp().globalData.skinface_id; } @@ -1757,7 +1783,146 @@ Page({ var th = this; th.setData({bn_use_commission: !th.data.bn_use_commission}); th.calculatePrice2(); + }, + + //-- 获取订单促销的判断结构 -- + set_by_now_ord_prom(item){ + let pickid=this.data.bn_pick; + let order_prom_map_ck= this.data.order_prom_map_ck; + order_prom_map_ck[pickid]={ + shop_price_all:0, //手店价的累计 + market_price_all:0, //市场价的累计 + goods_price_all:0, //实收价的累计 + no_ord_price:0, //要累计上不参与订单促销的金额 + goodsList:[], + } + + let pk_ord_map=order_prom_map_ck[pickid]; + pk_ord_map.shop_price_all += item.shop_price_y * item.buynum; + pk_ord_map.market_price_all += item.goods_market_price * item.buynum; + + }, + + //获取当前进行中订单促销,同时带入相应的金额判断订单促销是不是运行,同时订单促销的条件不是实收价判断的话,默认的时候,订单促销是不参与运算的 + async get_cur_ord_prom(pickid) { + let ord_prom = null; + let order_prom_map_ck = this.data.order_prom_map_ck[pickid]; + if(!order_prom_map_ck) return null; + + //获取当前进行中的优惠促销 + await getApp().request.promiseGet("/api/weshop/promorder/getPromOrder", { + data: { + store_id: os.stoid, + orderAmount: -1, //-1为不判断金额条件 + user_id: getApp().globalData.user_id + } + }).then(res => { + if (res.data.code == 0) { + ord_prom = res.data.data; + } + }) + + if (!ord_prom) return null; + //用于计算订单促销的金额 + let calculate_price=0; + + let txt1='show_ord_prom['+pickid+']'; + //-- 此时判断活动的金额满足与否 -- + switch (ord_prom.discount_field) { + //实收价的时候 + case 0: + //要先还原 + this.setData({ + [txt1]: 0 + }); + + if (ord_prom.money > order_prom_map_ck.goods_price_all){ + return null; + } + break; + //手店价的时候 + case 1: + if (ord_prom.money > order_prom_map_ck.shop_price_all){ + //要先还原 + this.setData({ + [txt1]: 0 + }); + return null; + } + //要显示订单促销使用的按钮 + this.setData({ + [txt1]: 1 + }); + break; + //市场价的时候 + case 2: + if (ord_prom.money > order_prom_map_ck.market_price_all){ + //要先还原 + this.setData({ + [txt1]: 0 + }); + return null; + } + //要显示订单促销使用的按钮 + this.setData({ + [txt1]: 2 + }); + break; + } + //如果订单促销是不参与订单促销的,那么就直接返回null(订单促销不是实收价的时候) + if(ord_prom.discount_field>0 && !this.data.can_use_ord_prom[pickid]){ + return null; + } + return ord_prom; + }, + + //立即购买的时候,点击订单促销的参与 + set_can_use_ord_prom_now:function (e){ + + if(this.data.submit) return false; + this.setData({ submit: 1,same_ok:1 }); + + let pickid=this.data.bn_pick; + let txt = 'can_use_ord_prom[' + pickid + ']'; + let can_use = this.data.can_use_ord_prom[pickid] ? this.data.can_use_ord_prom[pickid] : 0; + this.setData({ + [txt]: !can_use + }) + + let th=this; + let good=th.data.bn_goods; + + //如果有要参与订单促销的按钮点击后,要修改商品的价格 + if(th.data.can_use_ord_prom[pickid]){ + let discount_field=th.data.show_ord_prom[pickid]; + switch (discount_field){ + case 1: + good.shop_price=good.shop_price_y; + break; + case 2: + good.shop_price=good.market_price; + break; + } + //-- 转成普通商品 --- + good.prom_type=0; + good.prom_id=0; + good.integral=0; + good.discount_field=discount_field; + + }else{ + good=ut.deep_cp(th.data.old_bn_goods); + } + + th.setData({ + bn_goods:good + }) + wx.showLoading({ + title: "处理中.", + mark:true + }) + th.calculatePrice2() } + }); diff --git a/packageE/pages/cart/cart2_inte/cart2_inte.wxml b/packageE/pages/cart/cart2_inte/cart2_inte.wxml index dd18640..b3bce8a 100644 --- a/packageE/pages/cart/cart2_inte/cart2_inte.wxml +++ b/packageE/pages/cart/cart2_inte/cart2_inte.wxml @@ -94,6 +94,14 @@ {{order.store_prom}} + + + + + 参与订单促销 + + + diff --git a/packageE/pages/cart/cart2_pt/cart2_pt.js b/packageE/pages/cart/cart2_pt/cart2_pt.js index 394d22c..dbda90d 100644 --- a/packageE/pages/cart/cart2_pt/cart2_pt.js +++ b/packageE/pages/cart/cart2_pt/cart2_pt.js @@ -90,6 +90,13 @@ Page({ is_no_by: {}, is_by: {}, is_quan_by: {}, + + //-- 订单促销判断积累 ---2024-2-20 + order_prom_map_ck: {}, + //能不能使用订单促销 + can_use_ord_prom:{}, + //存储订单促销的取价,按照门店进行索引 + show_ord_prom:{}, }, @@ -444,7 +451,9 @@ Page({ et = 2; } + t.data.data.shop_price_y=t.data.data.shop_price t.data.data.shop_price = gg.goods_price; + //--如果是普通购买的时候-- if (gg.is_normal == 1) { t.data.data.prom_id = 0; @@ -485,6 +494,8 @@ Page({ } + //用深拷贝把商品缓存起来,方便后面使用 + th.data.old_bn_goods=ut.deep_cp(t.data.data); th.setData({ bn_goods: t.data.data, bn_pickname: gg.pick_name, @@ -568,7 +579,6 @@ Page({ et = th.data.bn_exp_type; } - //-- 计算获得佣金的金额 -- if (getApp().globalData.userInfo.is_distribut && th.data.dis_config && th.data.dis_config.is_yongjin_dk) { @@ -591,6 +601,8 @@ Page({ } + //用深拷贝把商品缓存起来,方便后面使用 + th.data.old_bn_goods=ut.deep_cp(t.data.data); th.setData({ bn_goods: t.data.data, bn_pickname: gg.pick_name, @@ -834,13 +846,17 @@ Page({ if(th.data.bn_is_order_yh && th.data.kt_type != 3 ){ - await getApp().request.promiseGet("/api/weshop/promorder/getOrderPromotion", { - data: { store_id: os.stoid, orderAmount: o_condition, user_id: getApp().globalData.user_id } - }).then(res => { - if (res.data.code == 0) { - ord_prom = res.data.data; - } - }) + // await getApp().request.promiseGet("/api/weshop/promorder/getOrderPromotion", { + // data: { store_id: os.stoid, orderAmount: o_condition, user_id: getApp().globalData.user_id } + // }).then(res => { + // if (res.data.code == 0) { + // ord_prom = res.data.data; + // } + // }) + + th.set_by_now_ord_prom(th.data.bn_goods); + th.data.order_prom_map_ck[bn_pick].goods_price_all=condition; + ord_prom=await th.get_cur_ord_prom(bn_pick); } @@ -2260,6 +2276,142 @@ Page({ th.setData({ open_quan: 0 }); }, + //-- 获取订单促销的判断结构 -- + set_by_now_ord_prom(item){ + let pickid=this.data.bn_pick; + let order_prom_map_ck= this.data.order_prom_map_ck; + order_prom_map_ck[pickid]={ + shop_price_all:0, //手店价的累计 + market_price_all:0, //市场价的累计 + goods_price_all:0, //实收价的累计 + no_ord_price:0, //要累计上不参与订单促销的金额 + goodsList:[], + } + + let pk_ord_map=order_prom_map_ck[pickid]; + pk_ord_map.shop_price_all += item.shop_price_y * item.buynum; + pk_ord_map.market_price_all += item.goods_market_price * item.buynum; + + }, + + //获取当前进行中订单促销,同时带入相应的金额判断订单促销是不是运行,同时订单促销的条件不是实收价判断的话,默认的时候,订单促销是不参与运算的 + async get_cur_ord_prom(pickid) { + let ord_prom = null; + let order_prom_map_ck = this.data.order_prom_map_ck[pickid]; + if(!order_prom_map_ck) return null; + + //获取当前进行中的优惠促销 + await getApp().request.promiseGet("/api/weshop/promorder/getPromOrder", { + data: { + store_id: os.stoid, + orderAmount: -1, //-1为不判断金额条件 + user_id: getApp().globalData.user_id + } + }).then(res => { + if (res.data.code == 0) { + ord_prom = res.data.data; + } + }) + + if (!ord_prom) return null; + //用于计算订单促销的金额 + let calculate_price=0; + + let txt1='show_ord_prom['+pickid+']'; + //-- 此时判断活动的金额满足与否 -- + switch (ord_prom.discount_field) { + //实收价的时候 + case 0: + //要先还原 + this.setData({ + [txt1]: 0 + }); + + if (ord_prom.money > order_prom_map_ck.goods_price_all){ + return null; + } + break; + //手店价的时候 + case 1: + if (ord_prom.money > order_prom_map_ck.shop_price_all){ + //要先还原 + this.setData({ + [txt1]: 0 + }); + return null; + } + //要显示订单促销使用的按钮 + this.setData({ + [txt1]: 1 + }); + break; + //市场价的时候 + case 2: + if (ord_prom.money > order_prom_map_ck.market_price_all){ + //要先还原 + this.setData({ + [txt1]: 0 + }); + return null; + } + //要显示订单促销使用的按钮 + this.setData({ + [txt1]: 2 + }); + break; + } + //如果订单促销是不参与订单促销的,那么就直接返回null(订单促销不是实收价的时候) + if(ord_prom.discount_field>0 && !this.data.can_use_ord_prom[pickid]){ + return null; + } + return ord_prom; + }, + + //立即购买的时候,点击订单促销的参与 + set_can_use_ord_prom_now:function (e){ + + if(this.data.submit) return false; + this.setData({ submit: 1,same_ok:1 }); + + let pickid=this.data.bn_pick; + let txt = 'can_use_ord_prom[' + pickid + ']'; + let can_use = this.data.can_use_ord_prom[pickid] ? this.data.can_use_ord_prom[pickid] : 0; + this.setData({ + [txt]: !can_use + }) + + let th=this; + let good=th.data.bn_goods; + + //如果有要参与订单促销的按钮点击后,要修改商品的价格 + if(th.data.can_use_ord_prom[pickid]){ + let discount_field=th.data.show_ord_prom[pickid]; + switch (discount_field){ + case 1: + good.shop_price=good.shop_price_y; + break; + case 2: + good.shop_price=good.market_price; + break; + } + //-- 转成普通商品 --- + good.prom_type=0; + good.prom_id=0; + good.discount_field=discount_field; + }else{ + good=ut.deep_cp(th.data.old_bn_goods); + } + + th.setData({ + bn_goods:good + }) + wx.showLoading({ + title: "处理中.", + mark:true + }) + th.calculatePrice2() + } + diff --git a/packageE/pages/cart/cart2_pt/cart2_pt.wxml b/packageE/pages/cart/cart2_pt/cart2_pt.wxml index 2cd0b09..c0002b3 100644 --- a/packageE/pages/cart/cart2_pt/cart2_pt.wxml +++ b/packageE/pages/cart/cart2_pt/cart2_pt.wxml @@ -102,6 +102,13 @@ {{order.store_prom}} + + + + + 参与订单促销 + +