promotions.js
36.4 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
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
function clone(myObj)
{
if(typeof(myObj) != 'object') return myObj;
if(myObj == null) return myObj;
var myNewObj = new Object();
for(var i in myObj) myNewObj[i] = clone(myObj[i]);
return myNewObj;
}
/**
* 促销方案计算
*/
var PromotionUtil =
{
cartId : 0, //购物车id
myOrderCount : 0, //本月已下单数量
/**
* 当前起作用的促销方案列表
*/
activeCommodityPromotionList : new Array(),
/**
* 行销列表
*/
activeMarketPromotionList: new Array(),
/**
* 满足条件的行销的没有赠品的列表
*/
fitMarketNoGiftPromotions : new Array(),
/**
* 满足条件的促销的没有赠品的列表
*/
fitCommodityNoGiftPromotions : new Array(),
/**
* 满足条件的有赠品的行销列表
*/
fitMarketHasGiftPromotions : new Array(),
/**
* 满足条件的有赠品的促销列表
*/
fitCommodityHasGiftPromotions : new Array(),
/**
* 主商品原记录
*/
srcMainGoodsList : new Array(),
/**
* outlets商品列表
*/
srcOutletsGoodsList : new Array(),
/**
* outlets促销设置
*/
outletsPromotionList: new Array(),
/**
* 赠品
*/
srcGiftGoodsList : new Array(),
/**
* 购物车中的主商品,用于计算的变量存储
*/
mainGoodsList : new Array(),
/**
* 促销商品的总金额
*/
promotionProductAmount : 0,
/**
* 当前的系统时间,使用秒数来描述
*/
curSysTime : 0,
/**
* vip的正常商品折扣
*/
vipCommonDiscount : 1,
/**
* vip的促销品折扣
*/
vipPromotionDiscount : 1,
/**
* vip等级
*/
curVipLevel : 0,
/**
* 是否已经有促销方案在促销方案组中。
*/
exitInPromotionGroup : 0,
/**
* 促销方案已经选择的赠品数量
*/
promotionSelGiftIds : new Array(),
/**
* VIP折扣信息
*/
vipDiscountInfo : "",
/**
* 活动共节省金额
*/
totalActSave : 0,
/**
* 订单信息
*/
orderInfo : {
//商品总数量
goodsCount: 0,
//总金额
totalCost: 0.0,
//运费
trafficFee : 0,
//使用的优惠券
couponCode : null,
//获得的优惠券
getCoupons : null,
//可获去的yoho币的数量
getyohoCoinNum: 0,
//outlets商品的花费
outletsCost:0.0
},
/**
* 更新产品数量
*/
updateGoodsNum : function(goodsInCardId, curNum, isOutlets){
this.exitInPromotionGroup = 0;
if(isOutlets) {
this.srcOutletsGoodsList[goodsInCardId]['num'] = curNum;
} else {
this.srcMainGoodsList[goodsInCardId]['num'] = curNum;
}
this.showResultInCart();
},
/**
* 删除一个商品
*/
delGoods: function(goodsInCardId, isGift, isOutlets){
if(isGift == 0){
if(isOutlets) {
this.srcOutletsGoodsList[goodsInCardId]['status'] = 0;
} else {
this.srcMainGoodsList[goodsInCardId]['status'] = 0;
}
} else {
this.srcGiftGoodsList[goodsInCardId]['status'] = 0;
}
},
/**
* 计算outlets的花费
*/
calcOutletsCost : function(){
var outletsCost = 0;
for(var i in this.srcOutletsGoodsList){
outletsCost += this.srcOutletsGoodsList[i]['last_price'] * this.srcOutletsGoodsList[i]['num'] ;
}
for(var i in this.outletsPromotionList) {
if(this.outletsPromotionList[i]['fit_money'] < outletsCost) {
outletsCost = 0;
for(var j in this.srcOutletsGoodsList) {
outletsCost += this.valDeal(this.srcOutletsGoodsList[j]['last_price'] * this.outletsPromotionList[i]['discount']) * this.srcOutletsGoodsList[j]['num'];
}
}
}
this.orderInfo.outletsCost = outletsCost;
return outletsCost;
},
/**
* 初始化订单信息
*/
initOrderInfo : function(){
// window.console && console.log(this.srcMainGoodsList)
//取得原数据,在促销方案计算过程中并不修改原数据,以防止重复计算时出错。
this.mainGoodsList = clone(this.srcMainGoodsList);
// this.giftGoodsList = clone(this.srcGiftGoodsList);
this.totalActSave = 0;
//清空计算的符合条件的促销方案
this.fitCommodityHasGiftPromotions = new Array();
this.fitCommodityNoGiftPromotions = new Array();
this.fitMarketHasGiftPromotions = new Array();
this.fitMarketNoGiftPromotions = new Array();
},
/**
* 执行促销方案
*/
exePromotions : function(){
this.filterFitPromotions(1); //计算促销的
this.filterFitPromotions(2); //计算行销的
// window.console && console.log(this.activeMarketPromotionList);
this.calcOrderFee();
freeGoods = this.calcThanks();
if(freeGoods != null){
//总价减去免单价格
this.orderInfo.totalCost = this.orderInfo.totalCost - this.valDeal(freeGoods["last_price"]);
this.totalActSave += freeGoods["sale_price"];
this.showFreeGoods(freeGoods, 1);
} else {
this.showFreeGoods(freeGoods, 0);
}
// window.console && console.log(this.orderInfo.totalCost);
},
checkCoinCoupon : function () {
//window.console && console.log(this.mainGoodsList);
for(var i in this.mainGoodsList){
var goodsInCart = this.mainGoodsList[i];
//如果是删除的商品,则不再计算。
if(goodsInCart['status'] == 0){
continue;
}
if((parseInt(goodsInCart['is_promotion']) % 2) != 0 ){
// $('#canUseYohocoin').val(0);
// $('#canUseCoupon').val(0);
break;
}
}
},
/**
* 显示免单商品
*/
showFreeGoods : function (freeGoods, isShow){
if($('#trFreeGoodsTitle').length>0) {
//购物车页面设置
if(isShow == 1) {
var goodsInfo = $('#mainGoodsInfo' + freeGoods["id"]).html();
$('#tdFreeGoods').html(goodsInfo);
$('#freeSrcPrice').html(QGlobal.Viewhelper.formatMoney(freeGoods["goods_price"]));
$('#freePrice').html("-" + QGlobal.Viewhelper.formatMoney(freeGoods["goods_price"]));
$('#trFreeGoodsTitle').show();
$('#trFreeGoods').show();
} else {
$('#trFreeGoodsTitle').hide();
$('#trFreeGoods').hide();
}
} else {
//结算页面设置
if(isShow == 1) {
// $('#canUseYohocoin').val(0);
// $('#canUseCoupon').val(0);
} else {
$('#canUseYohocoin').val(1);
$('#canUseCoupon').val(1);
}
}
},
/**
* 筛选满足条件的促销并记录
*/
filterFitPromotions : function(promotionType){
var curPromotionList = null;
if(promotionType == 1){
curPromotionList = this.activeCommodityPromotionList;
}else{
curPromotionList = this.activeMarketPromotionList;
}
// window.console && console.log(curPromotionList);
for(var i in curPromotionList){
var curPromotion = curPromotionList[i];
//检查时间段
if(!this.checkTimeSpan(curPromotion)){
continue;
}
var fitGoodsList = Array();
var fitGoodsCount = 0;
var fitGoodsTotalCost = 0;
//标记符合条件的商品
for(var i in this.mainGoodsList){
var goodsInCart = this.mainGoodsList[i];
//如果是删除的商品,则不再计算。
if(goodsInCart['status'] == 0){
continue;
}
//如果是已经参数促销的,就不再参与
if(promotionType==1)
{
if(goodsInCart['inCommodity']==1){
continue;
}
}else{
if(goodsInCart['inMarket']==1){
continue;
}
}
//判断是否为全场
if(curPromotion['fit_all_goods'] == 'Y'){
fitGoodsList.push(goodsInCart['id']);
fitGoodsCount += goodsInCart['num'];
fitGoodsTotalCost += Math.ceil(goodsInCart['last_price']) * goodsInCart['num'];
continue;
}
//判断是否属于某个品牌
if(curPromotion['brand_id'] != ""){
if((','+curPromotion['brand_ids']+',').indexOf(',' + goodsInCart['brand_id'] + ',')>-1){
// window.console && console.log(curPromotion['brand_ids'] + goodsInCart['brand_id']);
fitGoodsList.push(goodsInCart['id']);
fitGoodsCount += goodsInCart['num'];
fitGoodsTotalCost += Math.ceil(goodsInCart['last_price']) * goodsInCart['num'];
continue;
}
}
//判断是否属于某个分类
if(curPromotion['sort_ids'] != ""){
var sortScopIds = ',' + curPromotion['sort_ids'] + ',';
if(sortScopIds.indexOf(',' + goodsInCart['max_sort_id'] + ',')>-1 ||
sortScopIds.indexOf(',' + goodsInCart['middle_sort_id'] + ',')>-1 ||
sortScopIds.indexOf(',' + goodsInCart['small_sort_id']+ ',')>-1 )
{
fitGoodsList.push(goodsInCart['id']);
fitGoodsCount += goodsInCart['num'];
fitGoodsTotalCost += Math.ceil(goodsInCart['last_price']) * goodsInCart['num'];
continue;
}
}
//判断是否在商品列表中,inArray函数需要转换类型。
if(jQuery.inArray(Number(goodsInCart['erp_product_id']),curPromotion['goodsScope']) > -1){
fitGoodsList.push(goodsInCart['id']);
fitGoodsCount += goodsInCart['num'];
fitGoodsTotalCost += Math.ceil(goodsInCart['last_price']) * goodsInCart['num'];
continue;
}
}
curPromotion['fitGoodsIds'] = fitGoodsList;
// console.log("fitGoodsCount" + fitGoodsCount + ',condition_type:' + curPromotion["condition_type"] + ',' + curPromotion['num']);
// console.log(curPromotion);
// console.log("fitGoodsTotalCost" + fitGoodsTotalCost + ',' + curPromotion['total_cost']);
//分条件判断此促销方案是否符合
if((curPromotion["condition_type"] == 1 && Number(fitGoodsCount)>=Number(curPromotion['num'])) ||
(curPromotion["condition_type"]==2 && Number(fitGoodsTotalCost)>=Number(curPromotion['total_cost']))){
// window.console && console.log(curPromotion);
var promotionGroup = ""; //如,61,62,63,需要按照顺序
if(promotionType==2 && promotionGroup.indexOf(','+curPromotion["id"]+',')>-1){
if(this.exitInPromotionGroup == 0){
this.exitInPromotionGroup = 1;
} else {
continue;
}
}
if(this.promotionSelGiftIds[promotionType] == undefined){
this.promotionSelGiftIds[promotionType] = new Array();
}
if(this.promotionSelGiftIds[promotionType][curPromotion["id"]] == undefined){
this.promotionSelGiftIds[promotionType][curPromotion["id"]] = new Array();
}
//this.promotionSelGiftNum[promotionType][] = 0;
//满足促销方案
this.calcPromotion(curPromotion, promotionType);
//标记符合条件的商品,如果进行标记,则不能参加那种分级促销的活动,比如满100送袜子,满200送裤子(使用促销组)等。
//如果不标记,则在设置促销的时候,注意别有重合商品
for(var i in curPromotion['fitGoodsIds']){
if(promotionType==2 && promotionGroup.indexOf(','+curPromotion["id"]+',')>-1) {
continue;
}
if(promotionType == 1){
//促销的
// window.console && console.log(curPromotion['fitGoodsIds'][i]);
this.mainGoodsList[curPromotion['fitGoodsIds'][i]]['inCommodity'] = 1;
}else{
//行销的
this.mainGoodsList[curPromotion['fitGoodsIds'][i]]['inMarket'] = 1;
}
}
}
}
},
/**
* 记录符合的促销方案列表
*/
setFitPromotions : function(fitPromotion, promotionType, isHasGift){
if(promotionType == 1) {
if(isHasGift) {
this.fitCommodityHasGiftPromotions[fitPromotion["id"]] = fitPromotion;
} else {
this.fitCommodityNoGiftPromotions[fitPromotion["id"]] = fitPromotion;
}
}else{
if(isHasGift) {
this.fitMarketHasGiftPromotions[fitPromotion["id"]] = fitPromotion;
} else {
this.fitMarketNoGiftPromotions[fitPromotion["id"]] = fitPromotion;
}
}
},
/**
* 检查优惠券
*/
checkCoupon : function(couponInfo){
// window.console && console.log(this.mainGoodsList);
//{"couponid":14,"couponCode":"14","coupupCode":"14","startDate":"2011-06-26 00:00:00","endDate":"2011-08-15 00:00:00","money":140,"discount":"B","createTime":"2011-06-27 04:50:56","remark":"\u51ed\u8be5\u5238\u53ef\u5728\u7f8e\u7279\u65af\u90a6\u5a01\u6709\u8d27\u5e97\u94fa\u5185\u4efb\u610f\u8d2d\u4e70MTEE\u4e00\u4ef6","brands":"167,","productSorts":"","couponPic":"\/Upfile\/Pro_Act\/2011\/6\/201162745013.jpg"}
//验证有效期
if(couponInfo["isCanUse"] == 0){
return "您的优惠券不可使用"
}
if(this.curSysTime<couponInfo["startDate"]){
return "您的优惠券还没有到使用期";
}
if(this.curSysTime>(couponInfo["endDate"] + 86400)){
return "您的优惠券已经超过了有效期";
}
var commonGoodscost = this.orderInfo.totalCost - this.orderInfo.outletsCost - this.promotionProductAmount;
//验证使用的金额限制
if(couponInfo["discount"] == "B"){
//b券有使用金额的限制。
if(commonGoodscost < couponInfo["fitAmount"]){
return "您的订单金额未达到优惠券的使用限额(OUTLET商品不参与任何优惠券活动)";
}
}
//验证优惠券的金额不能超过outlets之外商品的总额
if(couponInfo["money"] > commonGoodscost) {
return "该优惠券超过了使用限额";
}
if(couponInfo["productSorts"] != "") {
var fitSort = 0;
for(var i in this.mainGoodsList) {
var goodsInCart = this.mainGoodsList[i];
//如果是删除的商品,则不再计算。
if(goodsInCart['status'] == 0){
continue;
}
if(((','+couponInfo["productSorts"]+',').indexOf(',' + goodsInCart['max_sort_id'] + ',') > -1) || ((','+couponInfo["productSorts"]+',').indexOf(',' + goodsInCart['middle_sort_id'] + ',') > -1) || ((','+couponInfo["productSorts"]+',').indexOf(',' + goodsInCart['small_sort_id'] + ',') > -1)) {
fitSort = 1;
}
}
if(fitSort == 0) {
return "订单中的商品不满足此优惠券的使用条件";
}
}
if(couponInfo["brands"] != ""){
var fitBrand = 0;
for(var i in this.mainGoodsList){
var goodsInCart = this.mainGoodsList[i];
//如果是删除的商品,则不再计算。
if(goodsInCart['status'] == 0){
continue;
}
if((','+couponInfo["brands"]+',').indexOf(',' + goodsInCart['brand_id'] + ',')>-1){
fitBrand = 1;
}
}
if(fitBrand == 0){
return "订单中不存在适用此优惠券的品牌商品";
}
}
return "";
},
/**
* 对数值的处理,目前先用取整
*/
valDeal : function(val){
return Math.ceil(val);
},
/**
* 计算促销方案
*/
calcPromotion : function(curPromotion, promotionType){
//window.console && console.log('---');
//window.console && console.log(curPromotion);
//window.console && console.log('---');
//分优惠类型计算优惠
switch(parseInt(curPromotion['favorable_type_id'])) //必须转成数字,否则不起作用
{
case 1: //免运费
this.orderInfo.trafficFee = 0;
curPromotion['resultText'] = ',运费:0.00元';
curPromotion['saveCost'] = 15;
this.setFitPromotions(curPromotion, promotionType, 0);
break;
case 2: //现金折扣
var tempCurAmount = 0.0;
//计算参与促销的商品总价
for(var i in curPromotion['fitGoodsIds']){
var goodsIncartId = curPromotion['fitGoodsIds'][i];
tempCurAmount += this.mainGoodsList[goodsIncartId]['last_price'] * this.mainGoodsList[goodsIncartId]['num'];
}
//计算折扣后的价格
for(var i in curPromotion['fitGoodsIds']){
var goodsIncartId = curPromotion['fitGoodsIds'][i];
this.mainGoodsList[goodsIncartId]['last_price'] = this.mainGoodsList[goodsIncartId]['last_price']-this.mainGoodsList[goodsIncartId]['last_price']*curPromotion['cash_discount']/tempCurAmount;
}
curPromotion['resultText'] = ',可获得' + curPromotion['cash_discount'] + "元现金折扣";
curPromotion['saveCost'] = curPromotion['cash_discount'];
this.totalActSave += parseInt(curPromotion['cash_discount']);
this.setFitPromotions(curPromotion, promotionType, 0);
break;
case 3: //送优惠券
//Promotion.orderInfo.couponCode[] = curPromotion['coupon_code'];
curPromotion["resultText"] = ",优惠券会在30日后赠送给您";
this.setFitPromotions(curPromotion, promotionType, 0);
break;
case 4: //赠品
this.setFitPromotions(curPromotion, promotionType, 1);
break;
case 5: //送yoho币
this.orderInfo.getyohoCoinNum += curPromotion['yoho_coin'];
curPromotion['resultText'] = '可获得' + curPromotion['yoho_coin'] + "个YOHO币";
this.setFitPromotions(curPromotion, promotionType, 0);
break;
case 6: //商品打折
var saveCost = 0.0;
for(var i in curPromotion['fitGoodsIds']){
var goodsIncartId = curPromotion['fitGoodsIds'][i];
saveCost += this.mainGoodsList[goodsIncartId]['num'] * (this.mainGoodsList[goodsIncartId]['last_price'] - this.valDeal(this.mainGoodsList[goodsIncartId]['last_price'] * curPromotion['discount']));
this.mainGoodsList[goodsIncartId]['last_price'] = this.mainGoodsList[goodsIncartId]['last_price'] * curPromotion['discount'];
}
curPromotion['saveCost'] = QGlobal.Viewhelper.formatMoney(saveCost,0);
curPromotion['resultText'] = ',获得' + QGlobal.Viewhelper.formatMoney(saveCost, 0) + "元优惠";
this.totalActSave += parseInt(this.totalActSave) + parseInt(saveCost);
// window.console && console.log('cur total:' + this.totalActSave);
this.setFitPromotions(curPromotion, promotionType, 0);
break;
}
},
/**
* 计算订单的费用:订单总金额和送的yoho币
*/
calcOrderFee : function(){
var tempTotalCost = 0.0;
var tempGetCoinNum = 0;
//循环主商品
for(var i in this.mainGoodsList){
// window.console && console.log(this.mainGoodsList[i]);
if(this.mainGoodsList[i]['status']==0){
continue;
}
tempTotalCost += Math.ceil(this.mainGoodsList[i]['last_price']) * this.mainGoodsList[i]['num'];
tempGetCoinNum += parseInt(this.mainGoodsList[i]['get_yohocoin_num']);
}
//循环赠品
for(var i in this.srcGiftGoodsList){
if(this.srcGiftGoodsList[i]['status']==0){
continue;
}
tempTotalCost += this.srcGiftGoodsList[i]['last_price'] * this.srcGiftGoodsList[i]['num'];
tempGetCoinNum += parseInt(this.srcGiftGoodsList[i]['get_yohocoin_num']);
}
//计算outlets
var outletsCost = this.calcOutletsCost();
this.orderInfo.totalCost = tempTotalCost + outletsCost;
this.orderInfo.getyohoCoinNum = tempGetCoinNum;
},
/**
* 计算原有商品的总价
*/
calcSrcOrderGoodsFee : function(){
var tempTotalCost = 0.0;
var tempGetCoinNum = 0;
this.initOrderInfo(); //初始化商品
//循环主商品
for(var i in this.srcMainGoodsList){
if(this.mainGoodsList[i]['status']==0){
continue;
}
tempTotalCost += this.mainGoodsList[i]['last_price'] * this.mainGoodsList[i]['num'];
tempGetCoinNum += parseInt(this.srcMainGoodsList[i]['get_yohocoin_num']);
}
//循环赠品
for(var i in this.srcGiftGoodsList){
if(this.srcGiftGoodsList[i]['status']==0){
continue;
}
tempTotalCost += this.srcGiftGoodsList[i]['last_price'] * this.srcGiftGoodsList[i]['num'];
tempGetCoinNum += parseInt(this.srcGiftGoodsList[i]['get_yohocoin_num']);
}
//计算outlets
var outletsCost = this.calcOutletsCost();
return tempTotalCost + outletsCost;
},
/**
* 判断时段
*/
checkTimeSpan :function(curPromotion){
var sysTime = this.getSystemTime();
if(curPromotion['start_timespan']< sysTime < curPromotion['end_timespan']){
return true;
}
return true;
},
/**
* 获取购物车中的商品数量
*/
getGoodsNumInCart : function(){
var num = 0;
for(var i in this.srcMainGoodsList){
var goodsInCart = this.srcMainGoodsList[i];
if(goodsInCart['status'] != 0){
num++;
}
}
for(var i in this.srcOutletsGoodsList) {
var goodsInCart = this.srcOutletsGoodsList[i];
if(goodsInCart['status'] != 0){
num++;
}
}
return num;
},
/**
* 检查用户选择的赠品
*/
checkSelGift : function(){
// window.console && console.log(this.promotionSelGiftIds);
if(this.fitCommodityHasGiftPromotions.length ==0 && this.fitMarketHasGiftPromotions.length==0){
return true;
}
for(var i in this.fitMarketHasGiftPromotions){
if(this.promotionSelGiftIds[2][this.fitMarketHasGiftPromotions[i]["id"]] != undefined && this.promotionSelGiftIds[2][this.fitMarketHasGiftPromotions[i]["id"]].length>0){
return true;
}
}
for(var i in this.fitCommodityHasGiftPromotions){
// window.console && console.log(this.fitCommodityHasGiftPromotions[i]);
if(this.promotionSelGiftIds[1][this.fitCommodityHasGiftPromotions[i]["id"]] != undefined && this.promotionSelGiftIds[1][this.fitCommodityHasGiftPromotions[i]["id"]].length>0){
return true;
}
}
return false;
},
/**
* 显示没有促销的
*/
showNoPromotionResultInCart:function(){
tempTotalCost = 0;
tempGetCoinNum = 0;
for(var i in this.mainGoodsList){
if(this.mainGoodsList[i]['status']==0){
continue;
}
tempTotalCost += Math.ceil(this.mainGoodsList[i]['last_price']) * this.mainGoodsList[i]['num'];
tempGetCoinNum += parseInt(this.mainGoodsList[i]['get_yohocoin_num']);
}
freeGoods = this.calcThanks();
if(freeGoods != null){
//总价减去免单价格
tempTotalCost = tempTotalCost - this.valDeal(freeGoods["last_price"]);
this.showFreeGoods(freeGoods, 1);
} else {
this.showFreeGoods(freeGoods, 0);
}
var strTotalCost = QGlobal.Viewhelper.formatMoney(tempTotalCost);
$('#commonTotalCost').html(strTotalCost);
$('#commonGetCoinsnum').html(tempGetCoinNum);
},
/**
* 显示结果
*/
showResultInCart : function() {
this.initOrderInfo(); //先初始化商品信息
var strSrcGoodsCost = QGlobal.Viewhelper.formatMoney(this.calcSrcOrderGoodsFee());
$('#totalSrcAmount').html(strSrcGoodsCost);
this.showPromotionResultInCart();
},
/**
* 计算VIP,需要根据不同的vip类型进行计算。
*/
calcVip : function(){
if(this.curVipLevel > 0) {
//是VIP,需要判断订单
if(this.myOrderCount > 7) {
//如果是结算页,则提示,否则不提示
if($("#noVipSaveTip").length>0){
$("#noVipSaveTip").show();
}
}
if(this.myOrderCount > 9 ) {
return;
}
for(var i in this.mainGoodsList){
// window.console && console.log("-src:-" + this.mainGoodsList[i]['last_price'] + "---");
if(this.mainGoodsList[i]['status']==0){
continue;
}
if(this.mainGoodsList[i]['is_special'] == 'N' && this.mainGoodsList[i]['vip_discount_type'] == 1 && this.curVipLevel>0){ //非特价品普通折扣商品,执行普通折扣
this.mainGoodsList[i]['last_price'] = this.mainGoodsList[i]['last_price'] * this.vipCommonDiscount;
} else if(this.mainGoodsList[i]['vip_discount_type'] == 2 && this.mainGoodsList[i]['is_special'] == 'N' && this.curVipLevel>0) {
//非特价VIP折扣商品,享受VIP折扣
this.mainGoodsList[i]['last_price'] = this.mainGoodsList[i]['last_price'] * this.mainGoodsList[i]['vip_discount'];
} else if(this.mainGoodsList[i]['vip_discount_type'] == 4 && this.mainGoodsList[i]['is_special'] == 'N' && this.curVipLevel>0){
//享受vip价格
this.mainGoodsList[i]['last_price'] = this.mainGoodsList[i]['vip_price'];
}
}
}
switch(this.curVipLevel)
{
case -1:
this.vipDiscountInfo = "普通会员,无折扣";
break;
case 0:
this.vipDiscountInfo = "普通会员,无折扣";
break;
case 1:
this.vipDiscountInfo = "银卡会员,普通商品" + this.vipCommonDiscount * 10 + "折";
break;
case 2:
this.vipDiscountInfo = "金卡会员,普通商品" + this.vipCommonDiscount * 10 + "折";
break;
case 3:
this.vipDiscountInfo = "白金会员,普通商品" + this.vipCommonDiscount * 10 + "折";
break;
}
$('#spanVipInfo').html(this.vipDiscountInfo);
if(this.curVipLevel == -1) {
$('#loginCalcNotice').show();
} else {
$('#loginCalcNotice').hide();
}
},
/**
* 计算促销标记的商品
*/
calcPromotionProduct : function() {
this.promotionProductAmount = 0;
for(var i in this.mainGoodsList) {
if(this.mainGoodsList[i]['status']==0){
continue;
}
if(this.mainGoodsList[i]['is_promotion'] == 65) {
this.promotionProductAmount += this.mainGoodsList[i]['last_price'] * this.mainGoodsList[i]['num'] ;
}
}
//目前的促销是满300减60
if(this.promotionProductAmount >= 300) {
for(var i in this.mainGoodsList) {
if(this.mainGoodsList[i]['status']==0){
continue;
}
if(this.mainGoodsList[i]['is_promotion'] == 65) {
this.mainGoodsList[i]['last_price'] = this.mainGoodsList[i]['last_price'] - this.mainGoodsList[i]['last_price'] * 60 / this.promotionProductAmount;
}
}
this.totalActSave += 60;
this.promotionProductAmount = this.promotionProductAmount - 60;
}
},
/**
* 计算感恩节的免单
*/
calcThanks : function() {
var free_goods_in_cart = null;
var min_price = 1000000;
var count = 0;
for(var i in this.mainGoodsList){
if(this.mainGoodsList[i]['status']==0){
continue;
}
if(this.mainGoodsList[i]["is_promotion"] == 51){
//感恩节活动商品
count += parseInt(this.mainGoodsList[i]["num"]);
if(parseFloat(this.mainGoodsList[i]["last_price"]) < parseFloat(min_price)){
min_price = this.mainGoodsList[i]["last_price"];
free_goods_in_cart = this.mainGoodsList[i];
}
}
}
if(count >2){
//window.console && console.log(free_goods_in_cart["last_price"]);
return free_goods_in_cart;
}
return null;
},
printClacResult : function(){
window.console && console.log('---------start------');
$str = "";
for(var i in this.mainGoodsList) {
$str += this.mainGoodsList[i]["erp_sku_id"] + ':' + this.mainGoodsList[i]["last_price"] + ","
}
window.console && console.log($str);
window.console && console.log('---------end------');
},
/**
* 显示促销方案计算结果
*/
showPromotionResultInCart : function(){
//初始化界面
if(this.getGoodsNumInCart() == 0){
$('#btnNpreSettle').hide();
}else{
$('#btnNpreSettle').show();
}
//初始化变量
this.exitInPromotionGroup = 0;
this.promotionSelGiftIds = new Array();
//计算vip
this.calcVip();
//计算专区商品
this.calcPromotionProduct();
//计算结果
this.exePromotions();
//赠品栏控制
this.showGiftTableTitle();
var giftNum = 0;
//清除已经不满足条件的赠品
for(var j in this.srcGiftGoodsList){
if((this.srcGiftGoodsList[j]['promotion_type'] == 1 && this.fitCommodityHasGiftPromotions[this.srcGiftGoodsList[j]['promotion_id']] == undefined)
|| (this.srcGiftGoodsList[j]['promotion_type'] == 2 && this.fitMarketHasGiftPromotions[this.srcGiftGoodsList[j]['promotion_id']] == undefined))
{
//需要删除
// $('#trDetail' + this.srcGiftGoodsList[j]['id']).remove();
// this.srcGiftGoodsList[j]['status'] = 0;
cart.onlyRemove(this.srcGiftGoodsList[j]['id'], this.cartId , 'N', 1);
} else {
giftNum ++;
}
}
if(giftNum<1){
$('#trCommonGift').hide();
}
var outletsNum = 0;
for(var k in this.srcOutletsGoodsList) {
if(this.srcOutletsGoodsList[k]['status'] != 0) {
outletsNum += this.srcOutletsGoodsList[k]['num'];
}
}
if(outletsNum<1) {
if($('#outletsBanner') != undefined) {
$('#outletsBanner').hide();
}
}
//清空原来的显示
$('#noGiftPromotions').empty();
//显示公式
$('#actSaveInfo').html(QGlobal.Viewhelper.formatMoney(this.totalActSave));
//显示促销方案列表
/* console.log(this.fitMarketNoGiftPromotions);
console.log(this.fitCommodityNoGiftPromotions);
console.log(this.fitMarketHasGiftPromotions);
console.log(this.fitCommodityHasGiftPromotions); */
this.showPromotionCartPic();
//显示不带赠品的
var strNoGiftHtml = this.getVipDiscountHtml();
strNoGiftHtml += this.getNoGiftPromotionHtml(this.fitCommodityNoGiftPromotions, 1);
strNoGiftHtml += this.getNoGiftPromotionHtml(this.fitMarketNoGiftPromotions, 2);
$('#noGiftPromotions').append(strNoGiftHtml);
//显示有赠品的
$('#commonGiftList').empty();
// $('#cartBanner').hide(); //把促销banner隐藏
this.showHasGiftPromotionHtml(this.fitCommodityHasGiftPromotions, 1);
this.showHasGiftPromotionHtml(this.fitMarketHasGiftPromotions, 2);
var strTotalCost = QGlobal.Viewhelper.formatMoney(this.orderInfo.totalCost);
$('#commonTotalCost').html(strTotalCost);
$('#commonGetCoinsnum').html(this.orderInfo.getyohoCoinNum);
if($('#cartBanner').attr('src') == ""){
$('#cartBanner').hide();
}
$('#totalFinalAmount').html(strTotalCost);
},
/**
* 显示促销方案在购物车的图片
*/
showPromotionCartPic : function(){
$('#promotionPicList').html('');
for(var i in this.fitMarketNoGiftPromotions) {
var promotionInfo = this.fitMarketNoGiftPromotions[i];
this.dispPromotionPicInCart(promotionInfo);
}
for(var i in this.fitCommodityNoGiftPromotions) {
var promotionInfo = this.fitCommodityNoGiftPromotions[i];
this.dispPromotionPicInCart(promotionInfo);
}
for(var i in this.fitMarketHasGiftPromotions){
var promotionInfo = this.fitMarketHasGiftPromotions[i];
this.dispPromotionPicInCart(promotionInfo);
}
for(var i in this.fitCommodityHasGiftPromotions){
var promotionInfo = this.fitCommodityHasGiftPromotions[i];
this.dispPromotionPicInCart(promotionInfo);
}
},
dispPromotionPicInCart : function(promotionInfo){
if($.trim(promotionInfo['cart_pic_url']) != ''){
var imgUrl = QGlobal.Common.QGetImages(promotionInfo['cart_pic_url'], 'source', 'promotionCartImg');
if(imgUrl == '') {
return;
}
var imgHtml = '<img src="' + imgUrl + '"/>';
// window.console && console.log(imgHtml);
$('#promotionPicList').append('<br/>' + imgHtml);
}
},
/**
* 决定是否显示赠品栏
*/
showGiftTableTitle : function(){
var giftCount = 0;
for(var i in this.srcGiftGoodsList){
if(this.srcGiftGoodsList[i]['status'] == 1){
giftCount ++;
}
}
if(giftCount > 0){
$('#trCommonGift').show();
}
else{
$('#trCommonGift').hide();
}
},
/**
* 在订单填写页面显示促销方案
*/
showPromotionInOrder:function(){
//初始化数据
this.initOrderInfo();
//计算VIP
this.calcVip();
//计算专区商品
this.calcPromotionProduct();
//计算促销,行销
this.exePromotions();
// window.console && console.log(this.orderInfo.totalCost);
//显示节省费用的订单
this.setPromotionHtmlInOrder(this.fitCommodityNoGiftPromotions);
this.setPromotionHtmlInOrder(this.fitMarketNoGiftPromotions);
var shopping_cost = $('#shipping_cost').val();
var strTotalCost = QGlobal.Viewhelper.formatMoney(this.orderInfo.totalCost + parseInt(shopping_cost));
var strSrcGoodsCost = QGlobal.Viewhelper.formatMoney(this.calcSrcOrderGoodsFee());
$('#orderTotalCost').html(strSrcGoodsCost); //这次显示商品总价
$('#totalSrcAmount').html(strSrcGoodsCost);
$('#finalTotalCost').html(strTotalCost);
$('#totalFinalAmount').html(strTotalCost);
$('#srcGoodsTotalCost').val(this.orderInfo.totalCost);
$('#srcMainGoodsTotalCost').val(this.orderInfo.totalCost - this.orderInfo.outletsCost );
// $('#srcGoodsTotalCost').html(this.orderInfo.totalCost);
$('#spanShippingFee').html(shopping_cost);
$('#actSaveInfo').html(QGlobal.Viewhelper.formatMoney(this.totalActSave));
//检查是否可以用优惠券和YOHO币
this.checkCoinCoupon();
},
/**
* 在订单填写页显示促销方案列表
*/
setPromotionHtmlInOrder : function(promotionList){
// window.console && console.log(promotionList);
for(var i in promotionList){
var promotionInfo = promotionList[i];
if(promotionInfo['favorable_type_id']==2 || promotionInfo['favorable_type_id']==6){
// $('#promotionSaveList').append('<p class="alright">' + promotionInfo['name'] + ":-" + promotionInfo['saveCost'] +'元' + '</p>');
}
if(promotionInfo['favorable_type_id'] == 1){
//免运费
$('#hasShoppingCost').hide();
// $('#noShoppingCost').html('参与:"' + promotionInfo['name'] + '"免运费"');
$('#noShoppingCost').show();
$('#shipping_cost').val(0);
}
}
},
/**
* 获取有赠品的促销的html
*/
showHasGiftPromotionHtml : function(promotionList, promotionType){
/* window.console && console.log('---');
window.console && console.log(promotionList);
window.console && console.log('---'); */
for(var i in promotionList){
var promotionInfo = promotionList[i];
//显示促销banner
var bannerImg = "http://static.yohobuy.com/images/banner/";
switch(0)
{
case "42":
bannerImg += 'cart_banner_168.jpg';
break;
case "43":
bannerImg += 'cart_banner_368.jpg';
break;
case "44":
bannerImg += 'cart_banner_568.jpg';
break;
case "45":
bannerImg += 'cart_banner_968.jpg';
break;
default :
bannerImg = "";
break;
}
// window.console && console.log(promotionInfo["id"] + bannerImg);
if(bannerImg != ""){
$('#cartBanner').attr('src', bannerImg);
$('#cartBanner').show();
}
//检查是否选择了赠品
var isSel = 0;
for(var j in this.srcGiftGoodsList){
// window.console && console.log(this.srcGiftGoodsList);
if((this.srcGiftGoodsList[j]['status'] == 1) &&(this.srcGiftGoodsList[j]['promotion_type'] == promotionType) && (this.srcGiftGoodsList[j]['promotion_id'] == promotionInfo['id']))
{
this.promotionSelGiftIds[promotionType][promotionInfo["id"]].push(this.srcGiftGoodsList[j]["product_id"]);
if(this.promotionSelGiftIds[promotionType][promotionInfo["id"]].length >= promotionInfo["gift_num"]){
isSel = 1;
continue;
}
}
}
if(isSel == 1){
continue;
}
var strHtml = '<h2 class="addsale_expand font_12">';
//您只需再加<b class="font_red">0.00</b>元就可以购买以下任一商品:
strHtml += promotionInfo['name'] + '<small class="font_999 font_slim">(注:您看到的以下商品可能因为下单时间差已售完)</small>';
strHtml += '</h2><ul class="addsale_cnt" id="commonGift_' + promotionInfo['id'] + '_' + promotionType + '"></ul>';
$('#commonGiftList').append(strHtml);
$('#commonGiftList').attr('class','sales_addsale');
this.loadGift(promotionInfo['id'],promotionType);
}
},
/**
* 加载礼品
*/
loadGift : function(promotionId, promotionType){
var selGiftIds = this.promotionSelGiftIds[promotionType][promotionId].join(',');
$.post('/shopping/cart/getpromotiongift', {promotion_type:promotionType,promotion_id:promotionId, sel_gift_ids:selGiftIds}, function(data){
$('#commonGift_' + promotionId + '_' + promotionType).html(data);
});
},
/**
* 获取促销的html
*/
getNoGiftPromotionHtml : function(promotionList, promotionType){
// console.log(promotionList);
var resHtml = "";
for(var i in promotionList) {
var promotionInfo = promotionList[i];
resHtml += '<tr><td class="table_left"><span class="i_cx_' + promotionInfo['favorable_type_id'] + '"></span>';
resHtml += promotionInfo['name'] + '<a href="http://www.yohobuy.com/promotion?id=' + promotionInfo['id'] + '&type=' + promotionType +'" target="_blank" class="a_eu">查看详细</a>';
resHtml += '</td><td class="table_right"><span class="icon_redselect">';
resHtml += '已参与'; //如果显示详细节省内容则添加promotionInfo['resultText']
resHtml += '</span></td></tr>';
}
return resHtml;
},
/**
* 显示VIP的折扣显示
*/
getVipDiscountHtml : function(){
return "";
var resHtml = "";
if(this.curVipLevel > 0) {
resHtml += '<tr><td class="table_left"><span class="i_cx_"></span>';
resHtml += this.vipDiscountInfo + '<a href="http://www.yohobuy.com/help/?category_id=60" target="_blank" class="a_eu">查看VIP制度</a>';
resHtml += '</td><td class="table_right"><span class="icon_redselect">';
resHtml += '已参与';
resHtml += '</span></td></tr>';
}
return resHtml;
},
/**
* 获取当前时间到当天零点的秒数
*/
getSystemTime : function (){
return parseInt(this.curSysTime%86400, 10);
}
};