From 1a0c81c4ba1287ae041a7fcba42fc2d645ac1698 Mon Sep 17 00:00:00 2001 From: yvan.ni Date: Sun, 25 Jun 2023 20:28:08 +0800 Subject: [PATCH] 优惠促销 多活动的优化 --- packageE/pages/cart/cart2/cart2.js | 2 +- pages/cart/cart/cart.js | 61 ++++++++++++++++++++++++++----------------------------------- utils/more_cx.js | 32 ++++++++++++++++++++++++++++++-- 3 files changed, 57 insertions(+), 38 deletions(-) diff --git a/packageE/pages/cart/cart2/cart2.js b/packageE/pages/cart/cart2/cart2.js index 14a5c9a..1d30700 100644 --- a/packageE/pages/cart/cart2/cart2.js +++ b/packageE/pages/cart/cart2/cart2.js @@ -1109,7 +1109,7 @@ Page({ var c_item = arr[k]; if(!is_change){ //-- 要进行归类一下活动 -- - await m_cx.cart_cx_group(th,arr[k].goods,c_item,1,1,(show_can_cx)=>{ + await m_cx.cart_cx_group(th,arr[k].goods,c_item,0,1,(show_can_cx)=>{ arr[k].show_can_cx=show_can_cx; }) }else{ diff --git a/pages/cart/cart/cart.js b/pages/cart/cart/cart.js index 45dfc29..23f2cd7 100644 --- a/pages/cart/cart/cart.js +++ b/pages/cart/cart/cart.js @@ -57,6 +57,8 @@ Page({ in_zhact_new: {}, //组合购活动在列表中的显示 是多促销互动专用,不能和in_zhact重叠 in_yhact_new: {}, //组合购活动在列表中的显示 是多促销互动专用,不能和in_yhact重叠 + is_cart:1, //标记是购物车计算的时候 + }, //-- 立即购买的时候,获取商品优惠活动,is_state判断是不是单个商品购买, @@ -1922,6 +1924,7 @@ Page({ } } + th.data.pitems=-1; //当数量大于1,且是选择的时候 if (iarr.length > 1 && !a.selected) { @@ -1954,6 +1957,9 @@ Page({ //-- 如果是选中的时候 -- if (!a.selected) { + + th.data.pitems=pitems; + //判断是不是有促销活动 var act = await getApp().get_has_cx_act(gd_info.goods_id); //-- 专门来设置商品订购数量 -- @@ -2004,7 +2010,7 @@ Page({ //判断多店优惠促销次数控制 if (th.data.requestData.length > 1) { if (a.prom_type == 3 && !a.selected) { - pro_off = await th.multiple_stores_pro(pitems, item) + //pro_off = await th.multiple_stores_pro(pitems, item) } } @@ -2162,49 +2168,34 @@ Page({ if (car && car.length > 0) { th.data.in_zhact_gdmap = {}; - //-- 第一次过滤,show_can_cx的还要遍历一遍,确保数据的正确性 -- + //-- show_can_cx的还要遍历一遍,确保数据的正确性 -- var rd_arr = []; + + //确保选择的放在最后一次判断 + var c_ind=-1; + if(th.data.pitems>-1){ + c_ind=th.data.pitems; + th.data.pitems=-1; + } + for (var a = 0; a < car.length; a++) { var ite1 = car[a].goods; - await m_cx.cart_cx_group(th, ite1, car[a], 1, n_ok, (show_can_cx) => { + if(car.length>1 && c_ind>-1 && a==c_ind ){ + rd_arr.push({}); + continue; + } + await m_cx.cart_cx_group(th, ite1, car[a], 0, n_ok, (show_can_cx) => { rd_arr.push(show_can_cx) }) } - //--- 第二次过滤 --- - for (var ui = 0; ui < rd_arr.length; ui++) { - var is_has_no_ok = 0; - var show_can_cx_item = rd_arr[ui]; - for (const per_sh_cx in show_can_cx_item) { - var cx_cur_act = show_can_cx_item[per_sh_cx].cur_act; //每一种活动切换的时候的当前活动 - var aid = cx_cur_act.prom_id; - //-- 就是那些活动未到达条件的时候,才需要重新过滤一遍 -- - if (cx_cur_act.is_no_ok) { - switch (cx_cur_act.prom_type) { - case 3: - if (th.data.in_yhact_new[aid]) { - is_has_no_ok = 1; - } - break; - case 7: - if (th.data.in_zhact_new[aid]) { - is_has_no_ok = 1; - } - break; - } - } - } - - //如果有重复就要重新计算一遍 - if (is_has_no_ok) { - await m_cx.cart_cx_group(th, car[ui].goods, car[ui], 1, n_ok, (show_can_cx) => { - rd_arr[ui] = show_can_cx; + if(car.length>1 && c_ind>-1){ + var ite2 = car[c_ind].goods; + await m_cx.cart_cx_group(th, ite2, car[c_ind], 0, n_ok, (show_can_cx) => { + rd_arr[c_ind]=show_can_cx; }) - } } - - for (var a = 0; a < car.length; a++) { //-- 把活动组装进去 --- var show_can_cx = rd_arr[a]; @@ -4769,7 +4760,7 @@ Page({ for (var ii = 0; ii < car.length; ii++) { if (c_idx == ii) continue; if (car[ii].show_can_cx && Object.keys(car[ii].show_can_cx).length) { - is_has_other = 1; + //is_has_other = 1; break; } } diff --git a/utils/more_cx.js b/utils/more_cx.js index 6bb7bd3..fd88013 100644 --- a/utils/more_cx.js +++ b/utils/more_cx.js @@ -354,7 +354,32 @@ module.exports = { } } + //-- 如果是要控制数量的时候,也就是全选的时候,或者加减号的时候 -- + if(ck_prom_type && is_need_ck_num && !ck_prom_type.is_no_ok){ + var t_pid=ck_prom_type.prom_id; + switch (ck_prom_type.prom_type){ + case 3: + if(!th.data.in_yhact_new[t_pid]) th.data.in_yhact_new[t_pid]=0; + th.data.in_yhact_new[t_pid]++; + break; + case 7: + if(!th.data.in_zhact_new[t_pid]) th.data.in_zhact_new[t_pid]=0; + th.data.in_zhact_new[t_pid]+=ck_prom_type.act_num; + //-- 数组的优化 -- + var nei_gd_map=ck_prom_type.in_zhact_gdmap; + if(nei_gd_map){ + for (var vg in nei_gd_map) { + if (!th.data.in_zhact_gdmap_new[vg]) th.data.in_zhact_gdmap_new[vg] = 0; + th.data.in_zhact_gdmap_new[vg] += nei_gd_map[vg]; + } + } + break; + } + } } + + + func(show_can_cx); return false; } @@ -406,8 +431,11 @@ module.exports = { } } - //goods[i].prom_type=0; - //goods[i].prom_id=0; + if(th.data.is_cart){ + goods[i].prom_type=0; + goods[i].prom_id=0; + } + } //-- 如果活动数量大于1个,那么活动就要排序一下,有商品种类数最多排再前面,降序进行排列 -- if(cx_act_map.length>1){ -- libgit2 0.21.4