Commit 1a0c81c4ba1287ae041a7fcba42fc2d645ac1698

Authored by yvan.ni
1 parent a3406cf1

优惠促销 多活动的优化

packageE/pages/cart/cart2/cart2.js
... ... @@ -1109,7 +1109,7 @@ Page({
1109 1109 var c_item = arr[k];
1110 1110 if(!is_change){
1111 1111 //-- 要进行归类一下活动 --
1112   - await m_cx.cart_cx_group(th,arr[k].goods,c_item,1,1,(show_can_cx)=>{
  1112 + await m_cx.cart_cx_group(th,arr[k].goods,c_item,0,1,(show_can_cx)=>{
1113 1113 arr[k].show_can_cx=show_can_cx;
1114 1114 })
1115 1115 }else{
... ...
pages/cart/cart/cart.js
... ... @@ -57,6 +57,8 @@ Page({
57 57 in_zhact_new: {}, //组合购活动在列表中的显示 是多促销互动专用,不能和in_zhact重叠
58 58 in_yhact_new: {}, //组合购活动在列表中的显示 是多促销互动专用,不能和in_yhact重叠
59 59  
  60 + is_cart:1, //标记是购物车计算的时候
  61 +
60 62 },
61 63  
62 64 //-- 立即购买的时候,获取商品优惠活动,is_state判断是不是单个商品购买,
... ... @@ -1922,6 +1924,7 @@ Page({
1922 1924 }
1923 1925 }
1924 1926  
  1927 + th.data.pitems=-1;
1925 1928 //当数量大于1,且是选择的时候
1926 1929 if (iarr.length > 1 && !a.selected) {
1927 1930  
... ... @@ -1954,6 +1957,9 @@ Page({
1954 1957  
1955 1958 //-- 如果是选中的时候 --
1956 1959 if (!a.selected) {
  1960 +
  1961 + th.data.pitems=pitems;
  1962 +
1957 1963 //判断是不是有促销活动
1958 1964 var act = await getApp().get_has_cx_act(gd_info.goods_id);
1959 1965 //-- 专门来设置商品订购数量 --
... ... @@ -2004,7 +2010,7 @@ Page({
2004 2010 //判断多店优惠促销次数控制
2005 2011 if (th.data.requestData.length > 1) {
2006 2012 if (a.prom_type == 3 && !a.selected) {
2007   - pro_off = await th.multiple_stores_pro(pitems, item)
  2013 + //pro_off = await th.multiple_stores_pro(pitems, item)
2008 2014 }
2009 2015 }
2010 2016  
... ... @@ -2162,49 +2168,34 @@ Page({
2162 2168 if (car && car.length > 0) {
2163 2169 th.data.in_zhact_gdmap = {};
2164 2170  
2165   - //-- 第一次过滤,show_can_cx的还要遍历一遍,确保数据的正确性 --
  2171 + //-- show_can_cx的还要遍历一遍,确保数据的正确性 --
2166 2172 var rd_arr = [];
  2173 +
  2174 + //确保选择的放在最后一次判断
  2175 + var c_ind=-1;
  2176 + if(th.data.pitems>-1){
  2177 + c_ind=th.data.pitems;
  2178 + th.data.pitems=-1;
  2179 + }
  2180 +
2167 2181 for (var a = 0; a < car.length; a++) {
2168 2182 var ite1 = car[a].goods;
2169   - await m_cx.cart_cx_group(th, ite1, car[a], 1, n_ok, (show_can_cx) => {
  2183 + if(car.length>1 && c_ind>-1 && a==c_ind ){
  2184 + rd_arr.push({});
  2185 + continue;
  2186 + }
  2187 + await m_cx.cart_cx_group(th, ite1, car[a], 0, n_ok, (show_can_cx) => {
2170 2188 rd_arr.push(show_can_cx)
2171 2189 })
2172 2190 }
2173 2191  
2174   - //--- 第二次过滤 ---
2175   - for (var ui = 0; ui < rd_arr.length; ui++) {
2176   - var is_has_no_ok = 0;
2177   - var show_can_cx_item = rd_arr[ui];
2178   - for (const per_sh_cx in show_can_cx_item) {
2179   - var cx_cur_act = show_can_cx_item[per_sh_cx].cur_act; //每一种活动切换的时候的当前活动
2180   - var aid = cx_cur_act.prom_id;
2181   - //-- 就是那些活动未到达条件的时候,才需要重新过滤一遍 --
2182   - if (cx_cur_act.is_no_ok) {
2183   - switch (cx_cur_act.prom_type) {
2184   - case 3:
2185   - if (th.data.in_yhact_new[aid]) {
2186   - is_has_no_ok = 1;
2187   - }
2188   - break;
2189   - case 7:
2190   - if (th.data.in_zhact_new[aid]) {
2191   - is_has_no_ok = 1;
2192   - }
2193   - break;
2194   - }
2195   - }
2196   - }
2197   -
2198   - //如果有重复就要重新计算一遍
2199   - if (is_has_no_ok) {
2200   - await m_cx.cart_cx_group(th, car[ui].goods, car[ui], 1, n_ok, (show_can_cx) => {
2201   - rd_arr[ui] = show_can_cx;
  2192 + if(car.length>1 && c_ind>-1){
  2193 + var ite2 = car[c_ind].goods;
  2194 + await m_cx.cart_cx_group(th, ite2, car[c_ind], 0, n_ok, (show_can_cx) => {
  2195 + rd_arr[c_ind]=show_can_cx;
2202 2196 })
2203   - }
2204 2197 }
2205 2198  
2206   -
2207   -
2208 2199 for (var a = 0; a < car.length; a++) {
2209 2200 //-- 把活动组装进去 ---
2210 2201 var show_can_cx = rd_arr[a];
... ... @@ -4769,7 +4760,7 @@ Page({
4769 4760 for (var ii = 0; ii < car.length; ii++) {
4770 4761 if (c_idx == ii) continue;
4771 4762 if (car[ii].show_can_cx && Object.keys(car[ii].show_can_cx).length) {
4772   - is_has_other = 1;
  4763 + //is_has_other = 1;
4773 4764 break;
4774 4765 }
4775 4766 }
... ...
utils/more_cx.js
... ... @@ -354,7 +354,32 @@ module.exports = {
354 354 }
355 355 }
356 356  
  357 + //-- 如果是要控制数量的时候,也就是全选的时候,或者加减号的时候 --
  358 + if(ck_prom_type && is_need_ck_num && !ck_prom_type.is_no_ok){
  359 + var t_pid=ck_prom_type.prom_id;
  360 + switch (ck_prom_type.prom_type){
  361 + case 3:
  362 + if(!th.data.in_yhact_new[t_pid]) th.data.in_yhact_new[t_pid]=0;
  363 + th.data.in_yhact_new[t_pid]++;
  364 + break;
  365 + case 7:
  366 + if(!th.data.in_zhact_new[t_pid]) th.data.in_zhact_new[t_pid]=0;
  367 + th.data.in_zhact_new[t_pid]+=ck_prom_type.act_num;
  368 + //-- 数组的优化 --
  369 + var nei_gd_map=ck_prom_type.in_zhact_gdmap;
  370 + if(nei_gd_map){
  371 + for (var vg in nei_gd_map) {
  372 + if (!th.data.in_zhact_gdmap_new[vg]) th.data.in_zhact_gdmap_new[vg] = 0;
  373 + th.data.in_zhact_gdmap_new[vg] += nei_gd_map[vg];
  374 + }
  375 + }
  376 + break;
  377 + }
  378 + }
357 379 }
  380 +
  381 +
  382 +
358 383 func(show_can_cx);
359 384 return false;
360 385 }
... ... @@ -406,8 +431,11 @@ module.exports = {
406 431 }
407 432 }
408 433  
409   - //goods[i].prom_type=0;
410   - //goods[i].prom_id=0;
  434 + if(th.data.is_cart){
  435 + goods[i].prom_type=0;
  436 + goods[i].prom_id=0;
  437 + }
  438 +
411 439 }
412 440 //-- 如果活动数量大于1个,那么活动就要排序一下,有商品种类数最多排再前面,降序进行排列 --
413 441 if(cx_act_map.length>1){
... ...