Commit f8d339ccdba0cfbc2fd9c5435e61890ef635ac42

Authored by yvan.ni
1 parent 40bae0e5

组合购的bug优化

packageB/pages/zuhegou/index/index.js
... ... @@ -2221,105 +2221,113 @@ Page({
2221 2221 var delete_num = 0;
2222 2222 var zhqty_len = 0; //几个超量倍增
2223 2223 var be = parseInt(no_in_arr.length / this.data.act.zhbuyqty); //看一下是几倍
2224   - if (this.data.act.is_bzyh && zhqty_bz.length > 0) {
2225   - if (zhqty_bz.length > 1) {
2226   - let zhqty_bz_arr = [];
2227   - let zhqty_bz_flag = this.zhqty_bz_fun(zhqty_bz, be, zhqty_bz_arr);
2228   -
2229   - if (zhqty_bz_flag) {
2230   - for (let i = 0; i < zhqty_bz.length; i++) {
2231   - var vv = zhqty_bz[i];
2232   - for (let j = 0; j < be * vv['zhqty']; j++) {
2233   - let index = no_in_arr.findIndex(i => {
2234   - return vv.goods_id === i.goods_id
2235   - })
2236   - if (index > -1) {
2237   - delete_num++
2238   - no_in_arr.splice(index, 1)
  2224 + //如果有总数控制的时候
  2225 + if(this.data.act.zh_num){
  2226 + var be1=this.data.act.zh_num-this.data.act.zh_buy_num-1;
  2227 + if(be1<be) be=be1;
  2228 + }
  2229 + if(be){
  2230 + if (this.data.act.is_bzyh && zhqty_bz.length > 0) {
  2231 + if (zhqty_bz.length > 1) {
  2232 + let zhqty_bz_arr = [];
  2233 + let zhqty_bz_flag = this.zhqty_bz_fun(zhqty_bz, be, zhqty_bz_arr);
  2234 +
  2235 + if (zhqty_bz_flag) {
  2236 + for (let i = 0; i < zhqty_bz.length; i++) {
  2237 + var vv = zhqty_bz[i];
  2238 + for (let j = 0; j < be * vv['zhqty']; j++) {
  2239 + let index = no_in_arr.findIndex(i => {
  2240 + return vv.goods_id === i.goods_id
  2241 + })
  2242 + if (index > -1) {
  2243 + delete_num++
  2244 + no_in_arr.splice(index, 1)
  2245 + }
2239 2246 }
2240 2247 }
2241   - }
2242   - } else {
2243   - zhqty_len = 1;
2244   - let min_bz_num = Math.min.apply(Math, zhqty_bz_arr.map(function (o) {
2245   - return o['num'];
2246   - }));
2247   - let new_arr = zhqty_bz_arr.filter(ii => {
2248   - return ii['num'] == min_bz_num;
2249   - })
2250   - var vv = new_arr[0];
2251   - var bz_num = be * new_arr[0].zhqty; //超量倍增
2252   - var num = min_bz_num - new_arr[0].zhqty; //购买数量减去超量
2253   - bz_num_ok = bz_num - num;
2254   - if (bz_num_ok <= 0) {
2255   - //超量倍增满足,超量倍增就等于倍数
2256   - bz_num_ok = bz_num;
2257 2248 } else {
2258   - //超量倍增不满足,倍数要减去多出得
2259   - // be=be-bz_num_ok;
2260   - if (num % vv.zhqty == 0) {
2261   - be = num / vv.zhqty;
  2249 + zhqty_len = 1;
  2250 + let min_bz_num = Math.min.apply(Math, zhqty_bz_arr.map(function (o) {
  2251 + return o['num'];
  2252 + }));
  2253 + let new_arr = zhqty_bz_arr.filter(ii => {
  2254 + return ii['num'] == min_bz_num;
  2255 + })
  2256 + var vv = new_arr[0];
  2257 + var bz_num = be * new_arr[0].zhqty; //超量倍增
  2258 + var num = min_bz_num - new_arr[0].zhqty; //购买数量减去超量
  2259 + bz_num_ok = bz_num - num;
  2260 + if (bz_num_ok <= 0) {
  2261 + //超量倍增满足,超量倍增就等于倍数
  2262 + bz_num_ok = bz_num;
2262 2263 } else {
2263   - be = Math.floor(num / vv.zhqty)
  2264 + //超量倍增不满足,倍数要减去多出得
  2265 + // be=be-bz_num_ok;
  2266 + if (num % vv.zhqty == 0) {
  2267 + be = num / vv.zhqty;
  2268 + } else {
  2269 + be = Math.floor(num / vv.zhqty)
  2270 + }
  2271 + bz_num_ok = be * vv.zhqty;
2264 2272 }
2265   - bz_num_ok = be * vv.zhqty;
2266   - }
2267 2273  
2268   - for (let i = 0; i < zhqty_bz.length; i++) {
2269   - let item1 = zhqty_bz[i];
2270   - for (let j = 0; j < be * item1['zhqty']; j++) {
  2274 + for (let i = 0; i < zhqty_bz.length; i++) {
  2275 + let item1 = zhqty_bz[i];
  2276 + for (let j = 0; j < be * item1['zhqty']; j++) {
  2277 + let index = no_in_arr.findIndex(i => {
  2278 + return item1.goods_id === i.goods_id
  2279 + })
  2280 + if (index > -1) {
  2281 + // delete_num++
  2282 + no_in_arr.splice(index, 1)
  2283 + }
  2284 + }
  2285 + }
  2286 + aprice += be * aprice;
  2287 + }
  2288 + } else {
  2289 + var vv = zhqty_bz[0];
  2290 + var bz_num = be * vv.zhqty; //超量倍增
  2291 + var num = vv['num'] - vv.zhqty; //购买数量减去超量
  2292 + if (num > 0) {
  2293 + bz_num_ok = bz_num - num;
  2294 + if (bz_num_ok <= 0) {
  2295 + //超量倍增满足,超量倍增就等于倍数
  2296 + bz_num_ok = bz_num;
  2297 + } else {
  2298 + //超量倍增不满足,倍数要减去多出得
  2299 + // be=be-bz_num_ok;
  2300 + if (num % vv.zhqty == 0) {
  2301 + be = num / vv.zhqty;
  2302 + } else {
  2303 + be = Math.floor(num / vv.zhqty)
  2304 + }
  2305 + bz_num_ok = be * vv.zhqty;
  2306 + }
  2307 + for (let j = 0; j < bz_num_ok; j++) {
2271 2308 let index = no_in_arr.findIndex(i => {
2272   - return item1.goods_id === i.goods_id
  2309 + return vv.goods_id === i.goods_id
2273 2310 })
2274 2311 if (index > -1) {
2275   - // delete_num++
  2312 + delete_num++
2276 2313 no_in_arr.splice(index, 1)
2277 2314 }
2278 2315 }
2279   - }
2280   - aprice += be * aprice;
2281   - }
2282   - } else {
2283   - var vv = zhqty_bz[0];
2284   - var bz_num = be * vv.zhqty; //超量倍增
2285   - var num = vv['num'] - vv.zhqty; //购买数量减去超量
2286   - if (num > 0) {
2287   - bz_num_ok = bz_num - num;
2288   - if (bz_num_ok <= 0) {
2289   - //超量倍增满足,超量倍增就等于倍数
2290   - bz_num_ok = bz_num;
2291 2316 } else {
2292   - //超量倍增不满足,倍数要减去多出得
2293   - // be=be-bz_num_ok;
2294   - if (num % vv.zhqty == 0) {
2295   - be = num / vv.zhqty;
2296   - } else {
2297   - be = Math.floor(num / vv.zhqty)
2298   - }
2299   - bz_num_ok = be * vv.zhqty;
2300   - }
2301   - for (let j = 0; j < bz_num_ok; j++) {
2302   - let index = no_in_arr.findIndex(i => {
2303   - return vv.goods_id === i.goods_id
2304   - })
2305   - if (index > -1) {
2306   - delete_num++
2307   - no_in_arr.splice(index, 1)
2308   - }
  2317 + zhqty_len = 1;
2309 2318 }
2310   - } else {
2311   - zhqty_len = 1;
2312 2319 }
2313 2320 }
2314   - }
2315   - if (!zhqty_len) {
2316   - //多个超量就不用pop了
2317   - aprice += be * aprice;
2318   - let pop_num = be * this.data.act.zhbuyqty - delete_num;
2319   - for (var m = 0; m < pop_num; m++) {
2320   - no_in_arr.pop();
  2321 + if (!zhqty_len) {
  2322 + //多个超量就不用pop了
  2323 + aprice += be * aprice;
  2324 + let pop_num = be * this.data.act.zhbuyqty - delete_num;
  2325 + for (var m = 0; m < pop_num; m++) {
  2326 + no_in_arr.pop();
  2327 + }
2321 2328 }
2322 2329 }
  2330 +
2323 2331 }
2324 2332  
2325 2333 //算一下剩余的钱
... ...
pages/cart/cart/cart.js
... ... @@ -550,7 +550,7 @@ Page({
550 550 }
551 551  
552 552 //-- 如果有优惠促销,和阶梯促销,要看下有没有组合购,搭配购,看一下优惠促销和阶梯促销谁是指定商品参与的 --
553   - if(item.prom_type==3 || item.prom_type==10){
  553 + if(item.prom_type==0 || item.prom_type==3 || item.prom_type==10){
554 554  
555 555 var c_prom_type=0;
556 556 var c_prom_id=0;
... ... @@ -569,6 +569,7 @@ Page({
569 569 if(zh_fd && zh_fd.length){
570 570 c_prom_type=zh_fd[0].prom_type;
571 571 c_prom_id=zh_fd[0].act_id;
  572 + return;
572 573 }
573 574  
574 575 //-- 先看一下有没有搭配购 --
... ... @@ -578,6 +579,7 @@ Page({
578 579 if(dp_fd && dp_fd.length){
579 580 c_prom_type=dp_fd[0].prom_type;
580 581 c_prom_id=dp_fd[0].act_id;
  582 + return;
581 583 }
582 584  
583 585 //-- 先看一下有没有指定优惠促销 --
... ... @@ -587,6 +589,7 @@ Page({
587 589 if(yh_fd && yh_fd.length){
588 590 c_prom_type=yh_fd[0].prom_type;
589 591 c_prom_id=yh_fd[0].act_id;
  592 + return;
590 593 }
591 594  
592 595 //-- 先看一下有没有指定阶梯促销 --
... ...