From a3e934a428ec8ef51f8cd4ecb8814e828dd2c03e Mon Sep 17 00:00:00 2001 From: yvan.ni Date: Thu, 6 Apr 2023 16:28:09 +0800 Subject: [PATCH] 组合购和阶梯促销的优化 --- packageE/pages/cart/cart2/cart2.js | 19 ++++++++++++++++--- packageE/pages/cart/cart2/zh_calculate.js | 171 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------- pages/cart/cart/ladder_calculate.js | 4 ++-- pages/cart/cart/zh_calculate.js | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------- 4 files changed, 199 insertions(+), 165 deletions(-) diff --git a/packageE/pages/cart/cart2/cart2.js b/packageE/pages/cart/cart2/cart2.js index 2c7c3d6..246b62e 100644 --- a/packageE/pages/cart/cart2/cart2.js +++ b/packageE/pages/cart/cart2/cart2.js @@ -4234,7 +4234,7 @@ Page({ case 7: goods.prom_type = 7; goods.prom_id = g_item.prom_id; - zh_map_count[g_item.prom_id]=1; //汇总一下组合购的活动 + zh_map_count[g_item.prom_id]= (zh_map_count[g_item.prom_id]?zh_map_count[g_item.prom_id]:0)+goods.goods_num; //汇总一下组合购的活动 break default: goods.prom_type = 0; @@ -4320,12 +4320,25 @@ Page({ } - //-- 如果订单中有组合购 --- + //-- 如果订单中有组合购,要统计到倍增的情况 --- if(Object.keys(zh_map_count).length){ var zhlist=[]; + for (var kf in zh_map_count) { - zhlist.push({zhid:kf}); + + var zh_act_th=th.data.zhhe_act_map[kf]; + var ite={zhid:kf,zhnum:1}; + + if(zh_act_th.is_bz){ + if(zh_map_count[kf]>zh_act_th.zhbuyqty){ + ite.zhnum=zh_map_count[kf]/zh_act_th.zhbuyqty; + } + } + + zhlist.push(ite); + } + item.zhlist=zhlist; } diff --git a/packageE/pages/cart/cart2/zh_calculate.js b/packageE/pages/cart/cart2/zh_calculate.js index 79b0db4..00136fe 100644 --- a/packageE/pages/cart/cart2/zh_calculate.js +++ b/packageE/pages/cart/cart2/zh_calculate.js @@ -148,107 +148,118 @@ module.exports = { no_in_arr.pop(); } } + //看一下剩下的数量有没有满足组合购的要求,以及要不要倍增 if (act.is_bz && no_in_arr.length >= act.zhbuyqty) { var bz_num_ok = 0; //超量倍增是否满足 var zhqty_len = 0; //几个超量倍增 var delete_num=0; - let be = parseInt(no_in_arr.length / act.zhbuyqty); //看一下是几倍 - if (act.is_bzyh && zhqty_bz.length > 0) { - if (zhqty_bz.length > 1) { - let zhqty_bz_arr = []; - let zhqty_bz_flag=this.zhqty_bz_fun(zhqty_bz,be,zhqty_bz_arr); - if (zhqty_bz_flag) { - for (let i = 0; i < zhqty_bz.length; i++) { - var vv = zhqty_bz[i]; - for (let j = 0; j < be * vv['zhqty']; j++) { - let index = no_in_arr.findIndex(i => { - return vv.goods_id === i.goods_id - }) - if (index > -1) { - delete_num++ - no_in_arr.splice(index, 1) + + //看一下是几倍 + let be = parseInt(no_in_arr.length / act.zhbuyqty); + //如果有总数控制的时候 + if(act.zh_num){ + var be1=act.zh_num-act.zh_buy_num-1; + if(be1 0) { + if (zhqty_bz.length > 1) { + let zhqty_bz_arr = []; + let zhqty_bz_flag = this.zhqty_bz_fun(zhqty_bz, be, zhqty_bz_arr); + if (zhqty_bz_flag) { + for (let i = 0; i < zhqty_bz.length; i++) { + var vv = zhqty_bz[i]; + for (let j = 0; j < be * vv['zhqty']; j++) { + let index = no_in_arr.findIndex(i => { + return vv.goods_id === i.goods_id + }) + if (index > -1) { + delete_num++ + no_in_arr.splice(index, 1) + } } } - } - } else { - zhqty_len=1; - let min_bz_num = Math.min.apply(Math, zhqty_bz_arr.map(function (o) { - return o['num']; - })); - let new_arr = zhqty_bz_arr.filter(ii => { - return ii['num'] == min_bz_num; - }) - var vv = new_arr[0]; - var bz_num = be * new_arr[0].zhqty; //超量倍增 - var num = min_bz_num - new_arr[0].zhqty; //购买数量减去超量 - bz_num_ok = bz_num - num; - if (bz_num_ok <= 0) { - //超量倍增满足,超量倍增就等于倍数 - bz_num_ok = bz_num; } else { - //超量倍增不满足,倍数要减去多出得 - // be=be-bz_num_ok; - if (num % vv.zhqty == 0) { - be = num / vv.zhqty; + zhqty_len = 1; + let min_bz_num = Math.min.apply(Math, zhqty_bz_arr.map(function (o) { + return o['num']; + })); + let new_arr = zhqty_bz_arr.filter(ii => { + return ii['num'] == min_bz_num; + }) + var vv = new_arr[0]; + var bz_num = be * new_arr[0].zhqty; //超量倍增 + var num = min_bz_num - new_arr[0].zhqty; //购买数量减去超量 + bz_num_ok = bz_num - num; + if (bz_num_ok <= 0) { + //超量倍增满足,超量倍增就等于倍数 + bz_num_ok = bz_num; } else { - be = Math.floor(num / vv.zhqty) + //超量倍增不满足,倍数要减去多出得 + // be=be-bz_num_ok; + if (num % vv.zhqty == 0) { + be = num / vv.zhqty; + } else { + be = Math.floor(num / vv.zhqty) + } + bz_num_ok = be * vv.zhqty; + } + + for (let i = 0; i < zhqty_bz.length; i++) { + let item1 = zhqty_bz[i]; + for (let j = 0; j < be * item1['zhqty']; j++) { + let index = no_in_arr.findIndex(i => { + return item1.goods_id === i.goods_id + }) + if (index > -1) { + // delete_num++ + no_in_arr.splice(index, 1) + } + } } - bz_num_ok = be * vv.zhqty; + aprice += be * aprice; } - - for(let i = 0; i < zhqty_bz.length; i++){ - let item1=zhqty_bz[i]; - for (let j = 0; j < be * item1['zhqty']; j++) { + } else { + var vv = zhqty_bz[0]; + var bz_num = be * vv.zhqty; //超量倍增 + var num = vv['num'] - vv.zhqty; //购买数量减去超量 + if (num > 0) { + bz_num_ok = bz_num - num; + if (bz_num_ok <= 0) { + //超量倍增满足,超量倍增就等于倍数 + bz_num_ok = bz_num; + } else { + //超量倍增不满足,倍数要减去多出得 + // be=be-bz_num_ok; + if (num % vv.zhqty == 0) { + be = num / vv.zhqty; + } else { + be = Math.floor(num / vv.zhqty) + } + bz_num_ok = be * vv.zhqty; + } + for (let j = 0; j < bz_num_ok; j++) { let index = no_in_arr.findIndex(i => { - return item1.goods_id === i.goods_id + return vv.goods_id === i.goods_id }) if (index > -1) { - // delete_num++ + delete_num++ no_in_arr.splice(index, 1) } } - } - aprice += be * aprice; - } - } else { - var vv = zhqty_bz[0]; - var bz_num = be * vv.zhqty; //超量倍增 - var num = vv['num'] - vv.zhqty; //购买数量减去超量 - if (num > 0) { - bz_num_ok = bz_num - num; - if (bz_num_ok <= 0) { - //超量倍增满足,超量倍增就等于倍数 - bz_num_ok = bz_num; } else { - //超量倍增不满足,倍数要减去多出得 - // be=be-bz_num_ok; - if (num % vv.zhqty == 0) { - be = num / vv.zhqty; - } else { - be = Math.floor(num / vv.zhqty) - } - bz_num_ok = be * vv.zhqty; - } - for (let j = 0; j < bz_num_ok; j++) { - let index = no_in_arr.findIndex(i => { - return vv.goods_id === i.goods_id - }) - if (index > -1) { - delete_num++ - no_in_arr.splice(index, 1) - } + zhqty_len = 1; } - } else { - zhqty_len = 1; } } - } - if (!zhqty_len) { - aprice += be * act.zhprice; - let pop_num = be * act.zhbuyqty - delete_num; - for (var m = 0; m < pop_num; m++) { - no_in_arr.pop(); + if (!zhqty_len) { + aprice += be * act.zhprice; + let pop_num = be * act.zhbuyqty - delete_num; + for (var m = 0; m < pop_num; m++) { + no_in_arr.pop(); + } } } diff --git a/pages/cart/cart/ladder_calculate.js b/pages/cart/cart/ladder_calculate.js index a3ef5a2..7f635d9 100644 --- a/pages/cart/cart/ladder_calculate.js +++ b/pages/cart/cart/ladder_calculate.js @@ -107,7 +107,7 @@ module.exports = { all_num += item.cart_num; for (var j = 0; j < item.cart_num; j++) { no_in_arr.push({ - price: item.goods_price,offline_price:item.offline_price,goods_id:item.goods_id,shop_price:item.shop_price + price: item.goods_price,offline_price:item.offline_price,goods_id:item.goods_id,shop_price:item.shop_price,goods_market_price:item.goods_market_price }) } } @@ -123,7 +123,7 @@ module.exports = { if(no_in_arr.length==0) break; let item_j=act.ladder_list[j]; var end=no_in_arr.pop(); - var new_price=parseInt(item_j.discount_field)==1?end.shop_price:end.price; + var new_price = parseInt(item_j.discount_field) == 2?end.goods_market_price:(parseInt(item_j.discount_field) == 1 ? end.shop_price : end.price); aprice+=new_price* parseFloat(item_j.discount)/10; lev++; } diff --git a/pages/cart/cart/zh_calculate.js b/pages/cart/cart/zh_calculate.js index 83c6b2b..27d2900 100644 --- a/pages/cart/cart/zh_calculate.js +++ b/pages/cart/cart/zh_calculate.js @@ -239,105 +239,115 @@ module.exports = { var delete_num = 0; var zhqty_len = 0; //几个超量倍增 var be = parseInt(no_in_arr.length / act.zhbuyqty); //看一下是几倍 - if (act.is_bzyh && zhqty_bz.length > 0) { - if (zhqty_bz.length > 1) { - let zhqty_bz_arr = []; - let zhqty_bz_flag=this.zhqty_bz_fun(zhqty_bz,be,zhqty_bz_arr); - - if (zhqty_bz_flag) { - for (let i = 0; i < zhqty_bz.length; i++) { - var vv = zhqty_bz[i]; - for (let j = 0; j < be * vv['zhqty']; j++) { - let index = no_in_arr.findIndex(i => { - return vv.goods_id === i.goods_id - }) - if (index > -1) { - delete_num++ - no_in_arr.splice(index, 1) + + //如果有总数控制的时候 + if(act.zh_num){ + var be1=act.zh_num-act.zh_buy_num-1; + if(be1 0) { + if (zhqty_bz.length > 1) { + let zhqty_bz_arr = []; + let zhqty_bz_flag=this.zhqty_bz_fun(zhqty_bz,be,zhqty_bz_arr); + + if (zhqty_bz_flag) { + for (let i = 0; i < zhqty_bz.length; i++) { + var vv = zhqty_bz[i]; + for (let j = 0; j < be * vv['zhqty']; j++) { + let index = no_in_arr.findIndex(i => { + return vv.goods_id === i.goods_id + }) + if (index > -1) { + delete_num++ + no_in_arr.splice(index, 1) + } } } - } - } else { - zhqty_len=1; - let min_bz_num = Math.min.apply(Math, zhqty_bz_arr.map(function (o) { - return o['num']; - })); - let new_arr = zhqty_bz_arr.filter(ii => { - return ii['num'] == min_bz_num; - }) - var vv = new_arr[0]; - var bz_num = be * new_arr[0].zhqty; //超量倍增 - var num = min_bz_num - new_arr[0].zhqty; //购买数量减去超量 - bz_num_ok = bz_num - num; - if (bz_num_ok <= 0) { - //超量倍增满足,超量倍增就等于倍数 - bz_num_ok = bz_num; } else { - //超量倍增不满足,倍数要减去多出得 - // be=be-bz_num_ok; - if (num % vv.zhqty == 0) { - be = num / vv.zhqty; + zhqty_len=1; + let min_bz_num = Math.min.apply(Math, zhqty_bz_arr.map(function (o) { + return o['num']; + })); + let new_arr = zhqty_bz_arr.filter(ii => { + return ii['num'] == min_bz_num; + }) + var vv = new_arr[0]; + var bz_num = be * new_arr[0].zhqty; //超量倍增 + var num = min_bz_num - new_arr[0].zhqty; //购买数量减去超量 + bz_num_ok = bz_num - num; + if (bz_num_ok <= 0) { + //超量倍增满足,超量倍增就等于倍数 + bz_num_ok = bz_num; } else { - be = Math.floor(num / vv.zhqty) + //超量倍增不满足,倍数要减去多出得 + // be=be-bz_num_ok; + if (num % vv.zhqty == 0) { + be = num / vv.zhqty; + } else { + be = Math.floor(num / vv.zhqty) + } + bz_num_ok = be * vv.zhqty; + } + + for(let i = 0; i < zhqty_bz.length; i++){ + let item1=zhqty_bz[i]; + for (let j = 0; j < be * item1['zhqty']; j++) { + let index = no_in_arr.findIndex(i => { + return item1.goods_id === i.goods_id + }) + if (index > -1) { + // delete_num++ + no_in_arr.splice(index, 1) + } + } } - bz_num_ok = be * vv.zhqty; + aprice += be * aprice; } - - for(let i = 0; i < zhqty_bz.length; i++){ - let item1=zhqty_bz[i]; - for (let j = 0; j < be * item1['zhqty']; j++) { + } else { + var vv = zhqty_bz[0]; + var bz_num = be * vv.zhqty; //超量倍增 + var num = vv['num'] - vv.zhqty; //购买数量减去超量 + if (num > 0) { + bz_num_ok = bz_num - num; + if (bz_num_ok <= 0) { + //超量倍增满足,超量倍增就等于倍数 + bz_num_ok = bz_num; + } else { + //超量倍增不满足,倍数要减去多出得 + // be=be-bz_num_ok; + if (num % vv.zhqty == 0) { + be = num / vv.zhqty; + } else { + be = Math.floor(num / vv.zhqty) + } + bz_num_ok = be * vv.zhqty; + } + for (let j = 0; j < bz_num_ok; j++) { let index = no_in_arr.findIndex(i => { - return item1.goods_id === i.goods_id + return vv.goods_id === i.goods_id }) if (index > -1) { - // delete_num++ + delete_num++ no_in_arr.splice(index, 1) } } - } - aprice += be * aprice; - } - } else { - var vv = zhqty_bz[0]; - var bz_num = be * vv.zhqty; //超量倍增 - var num = vv['num'] - vv.zhqty; //购买数量减去超量 - if (num > 0) { - bz_num_ok = bz_num - num; - if (bz_num_ok <= 0) { - //超量倍增满足,超量倍增就等于倍数 - bz_num_ok = bz_num; } else { - //超量倍增不满足,倍数要减去多出得 - // be=be-bz_num_ok; - if (num % vv.zhqty == 0) { - be = num / vv.zhqty; - } else { - be = Math.floor(num / vv.zhqty) - } - bz_num_ok = be * vv.zhqty; - } - for (let j = 0; j < bz_num_ok; j++) { - let index = no_in_arr.findIndex(i => { - return vv.goods_id === i.goods_id - }) - if (index > -1) { - delete_num++ - no_in_arr.splice(index, 1) - } + zhqty_len = 1; } - } else { - zhqty_len = 1; } } - } - if (!zhqty_len) { - aprice += be * act.zhprice; - let pop_num = be * act.zhbuyqty - delete_num; - for (var m = 0; m < pop_num; m++) { - no_in_arr.pop(); + if (!zhqty_len) { + aprice += be * act.zhprice; + let pop_num = be * act.zhbuyqty - delete_num; + for (var m = 0; m < pop_num; m++) { + no_in_arr.pop(); + } } } + } //算一下剩余的钱 if (no_in_arr.length) { -- libgit2 0.21.4