zh_calculate.js
32.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
var regeneratorRuntime = require('../../../../utils/runtime.js');
module.exports = {
//主要的作用,就是把组合购多余的商品进行拆分,
//如果没有达成组合购的要求,所有的商品都打回原价购买
fir_set_arr: function (c_item, th) {
//组合活动,以及组合活动从表的商品
let zh_prom_goods = c_item.zh_prom_goods;
let goods = c_item.goods; //一个门店中所有的商品
let tfeel = 0,
cut_price = 0,
offline_price = 0,
offline_num = 0;
let txt_ite = c_item.need_list;
//多个活动要拿来循环一下
for (let i in zh_prom_goods) {
let title = ""; //提示语;
//其中的一个活动
let act_item = zh_prom_goods[i];
let act_goos = act_item.gdlist;
let act = act_item.act;
if (!act) continue;
let all_num = 0; //商品数量之和
let all_price0 = 0; //商品数量之和
let aprice = 0; //达到活动条件的购买价格
let need_to_buy = 0;
let all_zhqty = 0; //所有商品要求起购数之和
let no_in_arr = []; //剩余的未加入组合购
let out_arr = []; //超出活动限购的商品放入
let zhqty_bz = []; //超量
//-- 寻找一下 --
function get_num2(ite) {
for (let v2 in goods) {
var vh = goods[v2];
if (vh.goods_id == ite.goods_id) {
return vh;
}
}
return 0;
}
for (let j in act_goos) {
let item = act_goos[j];
let item_j = goods.find(function (ele) {
console.log('ele', ele);
if (ele.prom_type==7) {
return ele.goods_id == act_goos[j].goods_id;
}else{
return false
}
})
//-- 如果有找到的话 --
if (item_j) {
act_goos[j].num = item_j.goods_num;
act_goos[j].goods_price = item_j.goods_price;
var cart_num = item.cart_num = item_j.goods_num;
var zh_b_num = item_j.promgoodsbuynum;
if (item.buyqty > 0) {
var key = item.goods_id + "." + act.id;
var cbuy = item.buyqty - zh_b_num;
if (th.data.in_zhact_gdmap[key]) {
var cbuy = item.buyqty - zh_b_num - th.data.in_zhact_gdmap[key];
}
//当可买的数量为0
if (cbuy <= 0) {
item.num = 0;
out_arr.push({
price: item.goods_price,
offline_price: item.offline_price,
goods_id: item.goods_id,
num: cart_num
})
} else {
if (cbuy >= cart_num) item.num = cart_num;
else {
item.num = cbuy;
out_arr.push({
price: item.goods_price,
offline_price: item.offline_price,
goods_id: item.goods_id,
num: cart_num - cbuy
})
}
}
}
all_num += item.num;
//当有起购数的控制的时候
if (item.zhqty) {
zhqty_bz.push(item);
all_zhqty += item.zhqty;
if (item.num < item.zhqty) {
need_to_buy += item.zhqty - item.num;
}
if (item.num > item.zhqty) {
for (let i = 0; i < item.num - item.zhqty; i++) {
no_in_arr.push({
price: item.goods_price,
goods_id: item.goods_id,
offline_price: item_j.offline_price
})
}
}
} else {
for (let j = 0; j < item.num; j++) {
no_in_arr.push({
price: item.goods_price,
goods_id: item.goods_id,
offline_price: item_j.offline_price
})
}
}
} else {
if (item.zhqty) {
title = "必买商品未加购,下单立享【" + act.zhprice + "元任选" + act.zhbuyqty + "件】";
need_to_buy += item.zhqty;
}
}
}
//当满足组合的要求:总数要满足,起购数要满足
if (act && all_num >= act.zhbuyqty && !need_to_buy) {
//商品的列表
for (var u in act_goos) {
var ite = act_goos[u];
if (ite.buyqty > 0 && ite.num > 0) {
var key = ite.goods_id + "." + act.id;
if (th.data.in_zhact_gdmap[key]) {
th.data.in_zhact_gdmap[key] += ite.num;
} else {
th.data.in_zhact_gdmap[key] = ite.num;
}
}
}
function sortData(a, b) {
return a.price - b.price
}
if (no_in_arr.length > 0) no_in_arr.sort(sortData);
aprice = act.zhprice;
if (act.zhbuyqty > all_zhqty) {
for (let n = 0; n < act.zhbuyqty - all_zhqty; n++) {
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.zh_num){
var be1= parseInt(act.zh_num-act.zh_buy_num)-1;
if(be1<be) be=be1;
}
if(be) {
if (act.is_bzyh && zhqty_bz.length > 0) {
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['be'];
}));
let new_arr = zhqty_bz_arr.filter(ii => {
return ii['be'] == min_bz_num;
})
be = new_arr[0].be;
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)
}
}
}
aprice += be * aprice;
}
}
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();
}
}
}
}
let goods_map = {};
//算一下剩余的商品
if (no_in_arr.length) {
for (let ii in no_in_arr) {
let item = no_in_arr[ii];
if (item.offline_price) {
offline_price += item.price - item.offline_price;
offline_num += 1;
}
if (goods_map[item.goods_id]) {
var num = goods_map[item.goods_id];
goods_map[item.goods_id] = ++num;
} else {
goods_map[item.goods_id] = 1;
}
}
}
//超量的部分也要计算一下
if (out_arr.length) {
for (var m in out_arr) {
var item = out_arr[m];
if (item.offline_price) {
offline_price += (item.price - item.offline_price) * item.num;
offline_num += item.num;
}
if (goods_map[item.goods_id]) {
var num = goods_map[item.goods_id];
num += item.num
goods_map[item.goods_id] = num;
} else {
goods_map[item.goods_id] = item.num;
}
}
}
//-- 暂存的数组 --
var temp_arr=[];
if (Object.keys(goods_map).length) {
//这里就开始拆分提交订单时的列表
for (let j in goods_map) {
//map中存的就是商品的数量
let num = goods_map[j];
//找到相应的商品
let idx = goods.findIndex(function (ele) {
return ele.goods_id == j;
})
goods[idx].goods_num -= num;
let new_g = JSON.parse(JSON.stringify(goods[idx]));
if(new_g.more_cx) delete new_g.more_cx;
//多余的商品如果活动不参与订单促销,那么变成普通商品的也不能参与订单促销,2024-2-26
if(!act.is_orderyh){
new_g.is_no_order_yh=1;
}
new_g.goods_num = num;
new_g.prom_type = 0;
new_g.prom_id = 0;
new_g.is_zh_split = 1; //-- 是组合购拆分出去的 --
//暂时存储一下
temp_arr.push(new_g);
//如果商品的数量已经为空了
if (goods[idx].goods_num <= 0) {
goods.splice(idx, 1);
}
}
}
var ls=-1;
//-- 只统计是参与活动的商品 --
for (var ij in goods) {
var iter = goods[ij];
if (iter.prom_type != 7 || iter.prom_id != act.id) {
continue;
}
goods[ij].is_act_last=0;
all_price0 += iter.goods_num * iter.goods_price;
ls= parseInt(ij);
}
//-- 要在特定的位置插入商品 --
if(temp_arr){
for(var gh=0;gh<temp_arr.length;gh++){
var idx=gh+ls+1;
goods.splice(idx, 0,temp_arr[gh]);
}
ls+=temp_arr.length;
}
goods[ls].is_act_last=1;
//-- 活动的条件已经满足 --
c_item.zh_prom_goods[act.id].is_has_zh = 1;
c_item.is_has_zh = 1;
c_item.zh_prom_goods[act.id].actual_price = aprice;
c_item.zh_prom_goods[act.id].cut_price = all_price0 - aprice;
//-- 设置还需要购买多少件,享受活动,前段显示 --
let need_to = c_item.need_list;
let index = this.find_need_to(need_to, act);
if (index > -1) {
need_to.splice(index, 1);
txt_ite = need_to
}
} else {
goods[goods.length-1].is_act_last=1;
for (let ii in goods) {
let item = goods[ii];
if (item.prom_type != 7) continue;
if (item.prom_id != act.id) continue;
if (item.offline_price) {
offline_price += item.goods_price - item.offline_price;
offline_num += 1;
}
//多余的商品如果活动不参与订单促销,那么变成普通商品的也不能参与订单促销,2024-2-26
if(!act.is_orderyh){
item.is_no_order_yh=1;
}
item.prom_type = 0;
item.prom_id = 0;
}
if (act.zhbuyqty - all_num > need_to_buy) {
need_to_buy = act.zhbuyqty - all_num;
}
//-- 设置还需要购买多少件享受活动,前端显示 --
let need_to = c_item.need_list;
let index = this.find_need_to(need_to, act);
if (title == '') title = "再买" + need_to_buy + "件,下单立享【" + act.zhprice + "元任选" + act.zhbuyqty + "件】";
if (index != -1) {
need_to[index].title = title;
} else {
if (!need_to) need_to = [];
let it = {
id: act.id,
pickup_id: c_item.pickup_id,
title: title
};
need_to.push(it);
}
txt_ite = need_to;
}
tfeel += aprice;
cut_price += all_price0 - aprice;;
}
c_item.zh_all_price = tfeel;
c_item.zh_cut_price = cut_price;
if (c_item.is_offline == 1) {
c_item.offline_price += offline_price;
c_item.offline_num += offline_num;
} else {
c_item.is_offline == 1;
c_item.offline_price = offline_price;
c_item.offline_num = offline_num;
}
},
//筛选组合购,纯粹的数组按活动id分组
find_split: function (arr) {
//过滤只有团购的商品
let oarr = arr.goods.filter(function (ele) {
return ele.prom_type == 7
})
if (!oarr || oarr.length == 0) return null;
//看一下有多少个不同的团购
let map = {},
dest = [];
for (let i = 0; i < oarr.length; i++) {
let ai = oarr[i];
let index = map[ai.prom_id]
if (!index) {
dest.push({
prom_id: ai.prom_id,
act: ai.act,
data: [ai]
});
map[ai.prom_id] = dest.length; //存储下标
} else {
let dj = dest[index - 1];
dj.data.push(ai);
}
}
return dest;
},
find_need_to: function (list, iter) {
if (!list || list.length <= 0) return -1;
for (var i in list) {
var item = list[i];
if (item.id == iter.id) {
return i;
}
}
return -1;
},
//-- 平摊组合购的价格 --
calc_zh_split_price: async function (c_arr, th) {
//-- 循环处理 --
for (var k in c_arr) {
var cart_item = c_arr[k]; //就是每一单的意思
var ord_goods = c_arr[k].goods; //就是每一单的从表的意思
var zh_prom_goods = cart_item.zh_prom_goods; //一单中所有的组合购的集合
var item_map = {};
for (let i in zh_prom_goods) {
let item = zh_prom_goods[i];
let prom_id = i;
//如果这个活动还没有达到要求,继续下一个计算
if (!item.is_has_zh) continue;
//过滤出相应组合购活动的商品
let glist = ord_goods.filter(function (ele) {
return ele.prom_type == 7 && ele.prom_id == i;
})
var all_good_price = 0;
var post_gd = [];
for (let j in glist) {
let item = glist[j];
all_good_price += item.goods_price * item.goods_num;
var gitem = {
goods_id: item.goods_id,
goods_num: item.goods_num,
goods_price: item.goods_price
}
post_gd.push(gitem);
}
//要进行优惠的计算
if (all_good_price - item.actual_price) {
if (cart_item.prom_pt_json) {
cart_item.prom_pt_json.push({
"zhprom_id": prom_id,
"dis": (all_good_price - item.actual_price).toFixed(2),
"ispt": 0
})
} else {
cart_item.prom_pt_json = [{
"zhprom_id": prom_id,
"dis": (all_good_price - item.actual_price).toFixed(2),
"ispt": 0
}];
}
}
//-- 如果系统要平摊到单品 --
var pt_data = {
'prom_id': prom_id,
'dis': parseFloat(all_good_price - item.actual_price).toFixed(2),
'goods': post_gd
}
var pt_res = null;
await getApp().request.promisePost("/api/weshop/order/getGoodsSplit", {
is_json: 1,
data: pt_data
}).then(res => {
if (res.data.code == 0) {
pt_res = res.data.data;
}
})
if (pt_res) {
for (var io in glist) {
var goods_id = glist[io].goods_id;
item_map[goods_id] = {};
//平摊赋值
item_map[goods_id].account_fir = th.arr_get_goods(goods_id, pt_res).fisrt_account;
item_map[goods_id].account_yu_fir = th.arr_get_goods(goods_id, pt_res).fisrt_account_yu;
if (!th.data.ispt_goods) {
item_map[goods_id].account = item_map[goods_id].account_fir;
item_map[goods_id].account_yu = item_map[goods_id].account_yu_fir;
}
}
}
}
//--------循环计算商品是不是包邮,是不是使用优惠券,此时循环是商品从表-----------
for (var jj = 0; jj < ord_goods.length; jj++) {
if (ord_goods[jj].is_gift) continue;
if (ord_goods[jj].prom_type == 7 && item_map[ord_goods[jj].goods_id]) {
ord_goods[jj].account_fir = item_map[ord_goods[jj].goods_id].account_fir;
ord_goods[jj].account_yu_fir = item_map[ord_goods[jj].goods_id].account_yu_fir;
ord_goods[jj].account = item_map[ord_goods[jj].goods_id].account;
ord_goods[jj].account_yu = item_map[ord_goods[jj].goods_id].account_yu;
}
}
}
},
zhqty_bz_fun(zhqty_bz,be,zhqty_bz_arr){
let zhqty_bz_flag =true;
for(let i=0;i<zhqty_bz.length;i++){
let item=zhqty_bz[i];
let bz_num = be * item['zhqty']; //超量倍增
let num = item['num'] - item['zhqty']; //购买数量减去超量
if (bz_num > num) {
zhqty_bz_flag=false;
var be=0;
if (num % vv.zhqty == 0) {
be = num / vv.zhqty;
} else {
be = Math.floor(num / vv.zhqty)
}
item.be=item;
zhqty_bz_arr.push(item);
// zhqty_bz.splice(i,1)
}
}
return zhqty_bz_flag;
},
//-- 判断组合购有没有满足,只有在检查的时候,要用新的 ---
ch_zh_ok(act,gdlist,c_goods,th,item_act_map,is_need_ck_num){
//-- 寻找一下 --
function get_num(ite) {
for (let v1 in c_goods) {
var vh = c_goods[v1];
if (vh.goods_id == ite.goods_id) {
return vh;
}
}
return 0;
}
var goods =gdlist;
var all_num=0;
var need_to_buy=0;
var all_zhqty=0;
//-- 是综合考虑到组合购的总数量和限购数量 --
var min_can_buy=-1;
var aid=act.id;
let no_in_arr = []; //剩余的未加入组合购
let out_arr = []; //超出活动限购的商品放入
//-- 判断组合购的总数量是不是到了 --
if(act.zh_num>0){
//如果是在全选的情况下,那么就需要in_zhact_new来控制数量
var need_ck=0;
if(is_need_ck_num){
need_ck=th.data.in_zhact_new[aid]?th.data.in_zhact_new[aid]:0;
}
if(need_ck+act.zh_buy_num>=act.zh_num ){
return false;
}else{
min_can_buy= act.zh_num-act.zh_buy_num-need_ck;
}
}
//-- 判断组合购的限购是不是到了 --
if(act.buy_limit>0){
var need_ck0=0;
if(is_need_ck_num){
need_ck0=th.data.in_zhact_new[aid]?th.data.in_zhact_new[aid]:0;
}
var min_can_buy0=0;
if(need_ck+item_act_map.buyed>=act.buy_limit ){
return false;
}else{
min_can_buy0=act.buy_limit-item_act_map.buyed-need_ck;
}
if(min_can_buy>0){
if(min_can_buy0<min_can_buy) min_can_buy=min_can_buy0;
}else{
min_can_buy=min_can_buy0;
}
}
for (var i in goods) {
var item = goods[i];
var cart_num = get_num(item).goods_num;
var zh_b_num = get_num(item).zh_b_num;
if (!cart_num) {
if (item.zhqty) {
need_to_buy += item.zhqty;
}
continue;
}
item.cart_num = cart_num;
//-- 当商品有购买的时候,以及有限购的时候 --
if (item.buyqty > 0) {
var cbuy = item.buyqty - zh_b_num;
var key = item.goods_id + "." + act.id;
if (is_need_ck_num && th.data.in_zhact_gdmap_new[key]) {
var cbuy = item.buyqty - zh_b_num - th.data.in_zhact_gdmap_new[key];
}
//当可买的数量为0
if (cbuy <= 0) {
item.num = 0;
out_arr.push({
goods_id: item.goods_id,
num: cart_num
})
} else {
if (cbuy >= cart_num) item.num = cart_num;
else {
item.num = cbuy;
out_arr.push({
goods_id: item.goods_id,
num: cart_num - cbuy
})
}
}
} else {
item.num = cart_num;
}
if (item.num) {
all_num += item.num;
//当有起购数的控制的时候
if (item.zhqty) {
all_zhqty += item.zhqty;
if (item.num < item.zhqty) {
need_to_buy += item.zhqty - item.num;
}
if (item.num > item.zhqty) {
for (let i = 0; i < item.num - item.zhqty; i++) {
no_in_arr.push({
goods_id: item.goods_id,
})
}
}
}
else {
for (let j = 0; j < item.num; j++) {
no_in_arr.push({
goods_id: item.goods_id,
})
}
}
} else {
if (item.zhqty) {
need_to_buy += item.zhqty;
}
}
}
//当满足组合的要求:总数要满足,起购数要满足
if (all_num >= act.zhbuyqty && !need_to_buy) {
//默认数量是1
var act_num=1;
function sortData(a, b) {
return a.price - b.price
}
if (no_in_arr.length > 0) no_in_arr.sort(sortData);
if (act.zhbuyqty > all_zhqty) {
for (let n = 0; n < act.zhbuyqty - all_zhqty; n++) {
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 (min_can_buy>0) {
var be1 = min_can_buy - 1;
if (be1 < be) be = be1;
}
if(be) {
if (act.is_bzyh && zhqty_bz.length > 0) {
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['be'];
}));
let new_arr = zhqty_bz_arr.filter(ii => {
return ii['be'] == min_bz_num;
})
//-- 要看一下倍数还有没有 ---
be = new_arr[0].be;
//如果有总数控制的时候
if (min_can_buy>0) {
var be1 = min_can_buy - 1;
if (be1 < be) be = be1;
}
if(be){
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) {
no_in_arr.splice(index, 1)
}
}
}
act_num+=be;
}
}
}
if (!zhqty_len) {
let pop_num = be * act.zhbuyqty - delete_num;
for (var m = 0; m < pop_num; m++) {
no_in_arr.pop();
}
act_num+=be;
}
}
}
//-- 参与活动的金额要返回回去 --
item_act_map.act_num=act_num;
let goods_map = {};
//算一下剩余的商品
if (no_in_arr.length) {
for (let ii in no_in_arr) {
let item = no_in_arr[ii];
if (goods_map[item.goods_id]) {
var num = goods_map[item.goods_id];
goods_map[item.goods_id] = ++num;
} else {
goods_map[item.goods_id] = 1;
}
}
}
//超量的部分也要计算一下
if (out_arr.length) {
for (var m in out_arr) {
if (goods_map[item.goods_id]) {
var num = goods_map[item.goods_id];
num += item.num
goods_map[item.goods_id] = num;
} else {
goods_map[item.goods_id] = item.num;
}
}
}
//-- 组合购的商品限购的数组控制 --
var in_zhact_gdmap={};
//商品的列表
for (var u in goods) {
var ite = goods[u];
var cart_num = get_num(ite).goods_num;
if (ite.buyqty > 0 && cart_num > 0) {
var key = ite.goods_id + "." + act.id;
if(goods_map[ite.goods_id]){
cart_num-=goods_map[ite.goods_id];
}
if(cart_num>0){
if (in_zhact_gdmap[key]) {
in_zhact_gdmap[key] += ite.num;
} else {
in_zhact_gdmap[key] = ite.num;
}
}
}
}
item_act_map.in_zhact_gdmap=in_zhact_gdmap;
return true;
}
return false;
}
}