From 8e20161446507de3951273e116f4d023f3539c24 Mon Sep 17 00:00:00 2001 From: abson Date: Tue, 28 Dec 2021 16:37:29 +0800 Subject: [PATCH] oa/115679 超量倍增 逻辑更改 --- packageB/pages/zuhegou/index/index.js | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------ pages/cart/cart/zh_calculate.js | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------- pages/cart/cart2/zh_calculate.js | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------- 3 files changed, 169 insertions(+), 50 deletions(-) diff --git a/packageB/pages/zuhegou/index/index.js b/packageB/pages/zuhegou/index/index.js index ce91880..181e4db 100644 --- a/packageB/pages/zuhegou/index/index.js +++ b/packageB/pages/zuhegou/index/index.js @@ -1965,29 +1965,66 @@ Page({ //看一下剩下的数量有没有满足组合购的要求,以及要不要倍增 if (this.data.act.is_bz && no_in_arr.length >= this.data.act.zhbuyqty) { - let zhqty_map=new map(); - //看一下是几倍 - var be = parseInt(no_in_arr.length / this.data.act.zhbuyqty); + var bz_num_ok=0; //超量倍增是否满足 + var zhqty_len=0; //几个超量倍增 + var be = parseInt(no_in_arr.length / this.data.act.zhbuyqty); //看一下是几倍 if(this.data.act.is_bzyh && zhqty_bz.length > 0 ){ - for(let i=0;i1){ + zhqty_len=1; + aprice += be * aprice; + let min_bz_num= Math.min.apply(Math, zhqty_bz.map(function(o) {return o['num']})); + let new_arr=zhqty_bz.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; + bz_num_ok=num; + } + for(let i=0;i{ + return vv.goods_id===i.goods_id + }) + no_in_arr.splice(index,1) + } + } + }else{ + for(let i=0;i{ + return vv.goods_id===i.goods_id + }) + no_in_arr.splice(index,1) + } } - } + } } - if(bz_num <= num){ + if(!zhqty_len){ + //多个超量就不用pop了 aprice += be * aprice; - let pop_num=(be * this.data.act.zhbuyqty)-bz_num; - console.log(pop_num); + let pop_num=be * this.data.act.zhbuyqty - bz_num_ok; for (var m = 0; m < pop_num; m++) { no_in_arr.pop(); } diff --git a/pages/cart/cart/zh_calculate.js b/pages/cart/cart/zh_calculate.js index 517f016..be68219 100644 --- a/pages/cart/cart/zh_calculate.js +++ b/pages/cart/cart/zh_calculate.js @@ -232,25 +232,66 @@ module.exports = { } //看一下剩下的数量有没有满足组合购的要求,以及要不要倍增 if (act.is_bz && no_in_arr.length >= act.zhbuyqty) { - //看一下是几倍 - let num = 0; - let bz_num = 0; - var be = parseInt(no_in_arr.length / act.zhbuyqty); + var bz_num_ok=0; //超量倍增是否满 + var zhqty_len=0; //几个超量倍增 + var be = parseInt(no_in_arr.length / act.zhbuyqty);//看一下是几倍 if (act.is_bzyh && zhqty_bz.length > 0) { - for (let i = 0; i < zhqty_bz.length; i++) { - let item = zhqty_bz[i]; - bz_num = be * item.zhqty; - for (let j = 0; j < no_in_arr.length; j++) { - let i = no_in_arr[j]; - if (item.goods_id === i.goods_id) { - num++ - } + if(zhqty_bz.length>1){ + zhqty_len=1; + aprice += be * aprice; + let min_bz_num= Math.min.apply(Math, zhqty_bz.map(function(o) {return o['num']})); + let new_arr=zhqty_bz.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; + bz_num_ok=num; } - } + for(let i=0;i{ + return vv.goods_id===i.goods_id + }) + no_in_arr.splice(index,1) + } + } + }else{ + // for(let i=0;i{ + return vv.goods_id===i.goods_id + }) + no_in_arr.splice(index,1) + } + // } + } } - if (bz_num <= num) { + if (!zhqty_len) { aprice += be * act.zhprice; - for (var m = 0; m < be * act.zhbuyqty; m++) { + let pop_num=be * act.zhbuyqty - bz_num_ok; + for (var m = 0; m < pop_num; m++) { no_in_arr.pop(); } } diff --git a/pages/cart/cart2/zh_calculate.js b/pages/cart/cart2/zh_calculate.js index 8fa478a..3fbf171 100644 --- a/pages/cart/cart2/zh_calculate.js +++ b/pages/cart/cart2/zh_calculate.js @@ -144,25 +144,66 @@ module.exports = { } //看一下剩下的数量有没有满足组合购的要求,以及要不要倍增 if (act.is_bz && no_in_arr.length >= act.zhbuyqty) { - //看一下是几倍 - let num = 0; - let bz_num = 0; - let be = parseInt(no_in_arr.length / act.zhbuyqty); + var bz_num_ok=0; //超量倍增是否满足 + var zhqty_len=0; //几个超量倍增 + let be = parseInt(no_in_arr.length / act.zhbuyqty);//看一下是几倍 if (act.is_bzyh && zhqty_bz.length > 0) { - for (let i = 0; i < zhqty_bz.length; i++) { - let item = zhqty_bz[i]; - bz_num = be * item.zhqty; - for (let j = 0; j < no_in_arr.length; j++) { - let i = no_in_arr[j]; - if (item.goods_id === i.goods_id) { - num++ - } - } - } + if(zhqty_bz.length>1){ + zhqty_len=1; + aprice += be * aprice; + let min_bz_num= Math.min.apply(Math, zhqty_bz.map(function(o) {return o['num']})); + let new_arr=zhqty_bz.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; + bz_num_ok=num; + } + for(let i=0;i{ + return vv.goods_id===i.goods_id + }) + no_in_arr.splice(index,1) + } + } + }else{ + for(let i=0;i{ + return vv.goods_id===i.goods_id + }) + no_in_arr.splice(index,1) + } + } + } } - if (bz_num <= num) { - aprice += be * act.zhprice; - for (var m = 0; m < be * act.zhbuyqty; m++) { + if (!zhqty_len) { + aprice += be * act.zhprice; + let pop_num=be * act.zhbuyqty - bz_num_ok; + for (var m = 0; m < pop_num; m++) { no_in_arr.pop(); } } -- libgit2 0.21.4