Commit 8e20161446507de3951273e116f4d023f3539c24

Authored by abson
1 parent 61488783

oa/115679 超量倍增 逻辑更改

packageB/pages/zuhegou/index/index.js
@@ -1965,29 +1965,66 @@ Page({ @@ -1965,29 +1965,66 @@ Page({
1965 1965
1966 //看一下剩下的数量有没有满足组合购的要求,以及要不要倍增 1966 //看一下剩下的数量有没有满足组合购的要求,以及要不要倍增
1967 if (this.data.act.is_bz && no_in_arr.length >= this.data.act.zhbuyqty) { 1967 if (this.data.act.is_bz && no_in_arr.length >= this.data.act.zhbuyqty) {
1968 - let zhqty_map=new map();  
1969 - //看一下是几倍  
1970 - var be = parseInt(no_in_arr.length / this.data.act.zhbuyqty); 1968 + var bz_num_ok=0; //超量倍增是否满足
  1969 + var zhqty_len=0; //几个超量倍增
  1970 + var be = parseInt(no_in_arr.length / this.data.act.zhbuyqty); //看一下是几倍
1971 if(this.data.act.is_bzyh && zhqty_bz.length > 0 ){ 1971 if(this.data.act.is_bzyh && zhqty_bz.length > 0 ){
1972 - for(let i=0;i<zhqty_bz.length;i++){  
1973 - let vv=zhqty_bz[i];  
1974 - let num=0;  
1975 - let bz_num=be*vv.zhqty;  
1976 - for(let j=0;j<no_in_arr.length;j++){  
1977 - let ii=no_in_arr[j];  
1978 - if(vv.goods_id===ii.goods_id){  
1979 - num++;  
1980 - zhqty_map.set('num',num);  
1981 - zhqty_map.set('price',ii.price); 1972 + if(zhqty_bz.length>1){
  1973 + zhqty_len=1;
  1974 + aprice += be * aprice;
  1975 + let min_bz_num= Math.min.apply(Math, zhqty_bz.map(function(o) {return o['num']}));
  1976 + let new_arr=zhqty_bz.filter(ii=>{
  1977 + return ii['num']==min_bz_num
  1978 + })
  1979 + // var vv=new_arr[0];
  1980 + var bz_num=be*new_arr[0].zhqty; //超量倍增
  1981 + var num=min_bz_num-new_arr[0].zhqty; //购买数量减去超量
  1982 + bz_num_ok=bz_num-num;
  1983 + if(bz_num_ok <= 0){
  1984 + //超量倍增满足,超量倍增就等于倍数
  1985 + bz_num_ok=bz_num;
  1986 + }else{
  1987 + //超量倍增不满足,倍数要减去多出得
  1988 + be=be-bz_num_ok;
  1989 + bz_num_ok=num;
  1990 + }
  1991 + for(let i=0;i<zhqty_bz.length;i++){
  1992 + var vv=zhqty_bz[i];
  1993 + for(let j=0;j<bz_num_ok;j++){
  1994 + let index= no_in_arr.findIndex(i=>{
  1995 + return vv.goods_id===i.goods_id
  1996 + })
  1997 + no_in_arr.splice(index,1)
  1998 + }
  1999 + }
  2000 + }else{
  2001 + for(let i=0;i<zhqty_bz.length;i++){
  2002 + // var zhqty_flag=true;
  2003 + var vv=zhqty_bz[i];
  2004 + var bz_num=be*vv.zhqty; //超量倍增
  2005 + var num=vv['num']-vv.zhqty; //购买数量减去超量
  2006 + bz_num_ok=bz_num-num;
  2007 + if(bz_num_ok <= 0){
  2008 + //超量倍增满足,超量倍增就等于倍数
  2009 + bz_num_ok=bz_num;
  2010 + }else{
  2011 + //超量倍增不满足,倍数要减去多出得
  2012 + be=be-bz_num_ok;
  2013 + bz_num_ok=num;
1982 } 2014 }
1983 - 2015 + for(let j=0;j<bz_num_ok;j++){
  2016 + let index= no_in_arr.findIndex(i=>{
  2017 + return vv.goods_id===i.goods_id
  2018 + })
  2019 + no_in_arr.splice(index,1)
  2020 + }
1984 } 2021 }
1985 - } 2022 + }
1986 } 2023 }
1987 - if(bz_num <= num){ 2024 + if(!zhqty_len){
  2025 + //多个超量就不用pop了
1988 aprice += be * aprice; 2026 aprice += be * aprice;
1989 - let pop_num=(be * this.data.act.zhbuyqty)-bz_num;  
1990 - console.log(pop_num); 2027 + let pop_num=be * this.data.act.zhbuyqty - bz_num_ok;
1991 for (var m = 0; m < pop_num; m++) { 2028 for (var m = 0; m < pop_num; m++) {
1992 no_in_arr.pop(); 2029 no_in_arr.pop();
1993 } 2030 }
pages/cart/cart/zh_calculate.js
@@ -232,25 +232,66 @@ module.exports = { @@ -232,25 +232,66 @@ module.exports = {
232 } 232 }
233 //看一下剩下的数量有没有满足组合购的要求,以及要不要倍增 233 //看一下剩下的数量有没有满足组合购的要求,以及要不要倍增
234 if (act.is_bz && no_in_arr.length >= act.zhbuyqty) { 234 if (act.is_bz && no_in_arr.length >= act.zhbuyqty) {
235 - //看一下是几倍  
236 - let num = 0;  
237 - let bz_num = 0;  
238 - var be = parseInt(no_in_arr.length / act.zhbuyqty); 235 + var bz_num_ok=0; //超量倍增是否满
  236 + var zhqty_len=0; //几个超量倍增
  237 + var be = parseInt(no_in_arr.length / act.zhbuyqty);//看一下是几倍
239 if (act.is_bzyh && zhqty_bz.length > 0) { 238 if (act.is_bzyh && zhqty_bz.length > 0) {
240 - for (let i = 0; i < zhqty_bz.length; i++) {  
241 - let item = zhqty_bz[i];  
242 - bz_num = be * item.zhqty;  
243 - for (let j = 0; j < no_in_arr.length; j++) {  
244 - let i = no_in_arr[j];  
245 - if (item.goods_id === i.goods_id) {  
246 - num++  
247 - } 239 + if(zhqty_bz.length>1){
  240 + zhqty_len=1;
  241 + aprice += be * aprice;
  242 + let min_bz_num= Math.min.apply(Math, zhqty_bz.map(function(o) {return o['num']}));
  243 + let new_arr=zhqty_bz.filter(ii=>{
  244 + return ii['num']==min_bz_num
  245 + })
  246 + // var vv=new_arr[0];
  247 + var bz_num=be*new_arr[0].zhqty; //超量倍增
  248 + var num=min_bz_num-new_arr[0].zhqty; //购买数量减去超量
  249 + bz_num_ok=bz_num-num;
  250 + if(bz_num_ok <= 0){
  251 + //超量倍增满足,超量倍增就等于倍数
  252 + bz_num_ok=bz_num;
  253 + }else{
  254 + //超量倍增不满足,倍数要减去多出得
  255 + be=be-bz_num_ok;
  256 + bz_num_ok=num;
248 } 257 }
249 - } 258 + for(let i=0;i<zhqty_bz.length;i++){
  259 + var vv=zhqty_bz[i];
  260 + for(let j=0;j<bz_num_ok;j++){
  261 + let index= no_in_arr.findIndex(i=>{
  262 + return vv.goods_id===i.goods_id
  263 + })
  264 + no_in_arr.splice(index,1)
  265 + }
  266 + }
  267 + }else{
  268 + // for(let i=0;i<zhqty_bz.length;i++){
  269 + // var zhqty_flag=true;
  270 + var vv=zhqty_bz[0];
  271 + var bz_num=be*vv.zhqty; //超量倍增
  272 + var num=vv['num']-vv.zhqty; //购买数量减去超量
  273 + bz_num_ok=bz_num-num;
  274 + if(bz_num_ok <= 0){
  275 + //超量倍增满足,超量倍增就等于倍数
  276 + bz_num_ok=bz_num;
  277 + }else{
  278 + //超量倍增不满足,倍数要减去多出得
  279 + be=be-bz_num_ok;
  280 + bz_num_ok=num;
  281 + }
  282 + for(let j=0;j<bz_num_ok;j++){
  283 + let index= no_in_arr.findIndex(i=>{
  284 + return vv.goods_id===i.goods_id
  285 + })
  286 + no_in_arr.splice(index,1)
  287 + }
  288 + // }
  289 + }
250 } 290 }
251 - if (bz_num <= num) { 291 + if (!zhqty_len) {
252 aprice += be * act.zhprice; 292 aprice += be * act.zhprice;
253 - for (var m = 0; m < be * act.zhbuyqty; m++) { 293 + let pop_num=be * act.zhbuyqty - bz_num_ok;
  294 + for (var m = 0; m < pop_num; m++) {
254 no_in_arr.pop(); 295 no_in_arr.pop();
255 } 296 }
256 } 297 }
pages/cart/cart2/zh_calculate.js
@@ -144,25 +144,66 @@ module.exports = { @@ -144,25 +144,66 @@ module.exports = {
144 } 144 }
145 //看一下剩下的数量有没有满足组合购的要求,以及要不要倍增 145 //看一下剩下的数量有没有满足组合购的要求,以及要不要倍增
146 if (act.is_bz && no_in_arr.length >= act.zhbuyqty) { 146 if (act.is_bz && no_in_arr.length >= act.zhbuyqty) {
147 - //看一下是几倍  
148 - let num = 0;  
149 - let bz_num = 0;  
150 - let be = parseInt(no_in_arr.length / act.zhbuyqty); 147 + var bz_num_ok=0; //超量倍增是否满足
  148 + var zhqty_len=0; //几个超量倍增
  149 + let be = parseInt(no_in_arr.length / act.zhbuyqty);//看一下是几倍
151 if (act.is_bzyh && zhqty_bz.length > 0) { 150 if (act.is_bzyh && zhqty_bz.length > 0) {
152 - for (let i = 0; i < zhqty_bz.length; i++) {  
153 - let item = zhqty_bz[i];  
154 - bz_num = be * item.zhqty;  
155 - for (let j = 0; j < no_in_arr.length; j++) {  
156 - let i = no_in_arr[j];  
157 - if (item.goods_id === i.goods_id) {  
158 - num++  
159 - }  
160 - }  
161 - } 151 + if(zhqty_bz.length>1){
  152 + zhqty_len=1;
  153 + aprice += be * aprice;
  154 + let min_bz_num= Math.min.apply(Math, zhqty_bz.map(function(o) {return o['num']}));
  155 + let new_arr=zhqty_bz.filter(ii=>{
  156 + return ii['num']==min_bz_num
  157 + })
  158 + // var vv=new_arr[0];
  159 + var bz_num=be*new_arr[0].zhqty; //超量倍增
  160 + var num=min_bz_num-new_arr[0].zhqty; //购买数量减去超量
  161 + bz_num_ok=bz_num-num;
  162 + if(bz_num_ok <= 0){
  163 + //超量倍增满足,超量倍增就等于倍数
  164 + bz_num_ok=bz_num;
  165 + }else{
  166 + //超量倍增不满足,倍数要减去多出得
  167 + be=be-bz_num_ok;
  168 + bz_num_ok=num;
  169 + }
  170 + for(let i=0;i<zhqty_bz.length;i++){
  171 + var vv=zhqty_bz[i];
  172 + for(let j=0;j<bz_num_ok;j++){
  173 + let index= no_in_arr.findIndex(i=>{
  174 + return vv.goods_id===i.goods_id
  175 + })
  176 + no_in_arr.splice(index,1)
  177 + }
  178 + }
  179 + }else{
  180 + for(let i=0;i<zhqty_bz.length;i++){
  181 + // var zhqty_flag=true;
  182 + var vv=zhqty_bz[i];
  183 + var bz_num=be*vv.zhqty; //超量倍增
  184 + var num=vv['num']-vv.zhqty; //购买数量减去超量
  185 + bz_num_ok=bz_num-num;
  186 + if(bz_num_ok <= 0){
  187 + //超量倍增满足,超量倍增就等于倍数
  188 + bz_num_ok=bz_num;
  189 + }else{
  190 + //超量倍增不满足,倍数要减去多出得
  191 + be=be-bz_num_ok;
  192 + bz_num_ok=num;
  193 + }
  194 + for(let j=0;j<bz_num_ok;j++){
  195 + let index= no_in_arr.findIndex(i=>{
  196 + return vv.goods_id===i.goods_id
  197 + })
  198 + no_in_arr.splice(index,1)
  199 + }
  200 + }
  201 + }
162 } 202 }
163 - if (bz_num <= num) {  
164 - aprice += be * act.zhprice;  
165 - for (var m = 0; m < be * act.zhbuyqty; m++) { 203 + if (!zhqty_len) {
  204 + aprice += be * act.zhprice;
  205 + let pop_num=be * act.zhbuyqty - bz_num_ok;
  206 + for (var m = 0; m < pop_num; m++) {
166 no_in_arr.pop(); 207 no_in_arr.pop();
167 } 208 }
168 } 209 }