Browse Source

满赠活动

zhangchuangbiao 4 years ago
parent
commit
893f77c723

+ 2 - 1
kmall-admin/src/main/java/com/kmall/admin/controller/OrderController.java

@@ -36,6 +36,7 @@ import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
+import java.text.Bidi;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -1042,7 +1043,7 @@ public class OrderController {
             BigDecimal marketPrice = orderGoodsEntity.getMarketPrice();
             BigDecimal goodsRate = orderGoodsEntity.getGoodsRate();
             Integer number = orderGoodsEntity.getNumber();
-            BigDecimal goodsTax = marketPrice.multiply(goodsRate).multiply(new BigDecimal(number));
+            BigDecimal goodsTax = marketPrice.divide(new BigDecimal(1).add(goodsRate),2,RoundingMode.HALF_DOWN).multiply(goodsRate).multiply(new BigDecimal(number)).setScale(0,RoundingMode.HALF_DOWN);
             orderGoodsEntity.setTax(goodsTax);
             tax = tax.add(goodsTax);
         }

+ 21 - 16
kmall-admin/src/main/java/com/kmall/admin/service/impl/GoodsServiceImpl.java

@@ -1142,10 +1142,16 @@ public class GoodsServiceImpl implements GoodsService {
             return null;
         }
         goods.setDiscountedPrice(new BigDecimal(0));
-        String goodsRate = goods.getGoodsRate();
-        BigDecimal tax = goods.getRetailPrice().multiply(new BigDecimal(goodsRate)).setScale(2, RoundingMode.HALF_UP);
+        BigDecimal goodsRate = null;
+        try {
+            goodsRate = new BigDecimal(goods.getGoodsRate());
+        } catch (Exception e) {
+            goodsRate = new BigDecimal(0);
+        }
+        BigDecimal retailPrice = goods.getRetailPrice();
+        BigDecimal tax = goodsRate.multiply(retailPrice.divide(new BigDecimal(1).add(goodsRate),2,RoundingMode.HALF_DOWN)).setScale(2,RoundingMode.HALF_DOWN) ;
         goods.setGoodstaxes(tax.toString());
-        goods.setActualPaymentAmount(goods.getRetailPrice().setScale(2,RoundingMode.HALF_UP));
+        goods.setActualPaymentAmount(retailPrice.setScale(2,RoundingMode.HALF_UP));
 
         Map<String,Object> skuActivitiesMap = new HashMap<>();
 
@@ -1196,7 +1202,7 @@ public class GoodsServiceImpl implements GoodsService {
 
 
         // 获取未优惠前的商品价格
-        BigDecimal retailPrice = goods.getRetailPrice();
+        retailPrice = goods.getRetailPrice();;
 
 
         // 根据条码查询商品品牌名称 mall_brand  mall_product_store_rela  mall_goods
@@ -1243,7 +1249,7 @@ public class GoodsServiceImpl implements GoodsService {
             Long mkaId = mkaIdMap.get("mj");
             MkActivitiesFullReductionEntity fullReductionEntity = fullReductionService.queryByCodeOrBrand(mkaId,prodBarcode,brandName,nowTime);
             if(fullReductionEntity != null) {
-                if(fullReductionEntity.getProductBrand() != null){
+                if(!StringUtils.isNullOrEmpty(fullReductionEntity.getProductBrand())){
                     // 跟着品牌走
                     fullReductionMap.put(brandName,fullReductionEntity);
                 }else{
@@ -1293,14 +1299,13 @@ public class GoodsServiceImpl implements GoodsService {
             Long mkaId = mkaIdMap.get("mysy");
             MkActivitiesGetOneFreeGoodsEntity getOneFreeGoodsEntity = getOneFreeGoodsService.queryByCodeOrBrand(mkaId,prodBarcode,brandName);
             if(getOneFreeGoodsEntity != null){
-                // 买x送1  所以需要定义的是 买的条码 买的数量   送的条码  送的数量
-
-
-//                Map<String,String> getOneFreeMap = new HashMap<>();
-//                //                  购买商品条码                          赠品条码
-//                getOneFreeMap.put( getOneFreeGoodsEntity.getBarcode(),getOneFreeGoodsEntity.getGiftBarcode());
-
-                skuActivitiesMap.put("mysy",getOneFreeGoodsEntity);
+                if("无".equals(getOneFreeGoodsEntity.getProductBrand())){
+                    getOneFreeGoodsEntity.setBrand(false);
+                    skuActivitiesMap.put("mysy",getOneFreeGoodsEntity);
+                }else{
+                    getOneFreeGoodsEntity.setBrand(true);
+                    skuActivitiesMap.put("mysy",getOneFreeGoodsEntity);
+                }
 
             }
         }
@@ -1332,7 +1337,7 @@ public class GoodsServiceImpl implements GoodsService {
             // TODO 可能会直接替代产品价格
             if (discountEntity != null) {
                 goods.setActualPaymentAmount(discountEntity.getActivityPrice());
-                goods.setDiscountedPrice(goods.getRetailPrice().subtract(discountEntity.getActivityPrice()).setScale(2,BigDecimal.ROUND_HALF_UP));
+                goods.setDiscountedPrice(retailPrice.subtract(discountEntity.getActivityPrice()).setScale(2,BigDecimal.ROUND_HALF_UP));
                 goods.setActivity("打折");
             }
         }
@@ -1346,7 +1351,7 @@ public class GoodsServiceImpl implements GoodsService {
             MkDailyActivitiesEntity dailyActivitiesEntity = dailyActivitiesService.queryByBarCode(mkaId,prodBarcode);
             if(dailyActivitiesEntity != null){
                 goods.setActualPaymentAmount(dailyActivitiesEntity.getActivityPrice());
-                goods.setDiscountedPrice(goods.getRetailPrice().subtract(dailyActivitiesEntity.getActivityPrice()).setScale(2,BigDecimal.ROUND_HALF_UP));
+                goods.setDiscountedPrice(retailPrice.subtract(dailyActivitiesEntity.getActivityPrice()).setScale(2,BigDecimal.ROUND_HALF_UP));
                 goods.setActivity("日常活动");
 
             }
@@ -1362,7 +1367,7 @@ public class GoodsServiceImpl implements GoodsService {
             // 如果该商品存在临时促销,直接替换活动价格
             if(promotionEntity != null){
                 goods.setActualPaymentAmount(promotionEntity.getActivityPrice());
-                goods.setDiscountedPrice(goods.getRetailPrice().subtract(promotionEntity.getActivityPrice()).setScale(2,BigDecimal.ROUND_HALF_UP));
+                goods.setDiscountedPrice(retailPrice.subtract(promotionEntity.getActivityPrice()).setScale(2,BigDecimal.ROUND_HALF_UP));
                 goods.setActivity("临时促销");
 
             }

+ 117 - 61
kmall-admin/src/main/webapp/js/sale/sale.js

@@ -39,8 +39,11 @@ function calculateGoodsPrice(r){
             giftBarcode:rMap.mysy.giftBarcode,
             sendNum:rMap.mysy.sendNum
         };
-        vm.newMysy.set(rMap.mysy.barcode , mysy);
-        vm.mysy.push(rMap.mysy[barCode]);
+        if(rMap.mysy.brand){
+            vm.brandGetOneFree.set(rMap.mysy.productBrand,mysy);
+        }else{
+            vm.barcodeGetOneFree.set(rMap.mysy.barcode , mysy);
+        }
     }
 
     if(rMap.mz){
@@ -52,29 +55,29 @@ function calculateGoodsPrice(r){
             vm.mz.set(brand,rMap.mz[brand]);
         }
     }
-    if(rMap.zhjsp){
-        // 遍历该商品所有可能的组合价商品类型
-        for(var data in rMap.zhjsp){
-            if(!vm.zhjsp.get(data)){
-                // 分割组合价商品的条码,并以 条码:0 放入map中
-                var barCodeArray = data.toString().split(":");
-                var dataMap = new Map();
-                console.log(rMap.zhjsp[data]);
-                // dataMap.set();
-                for(var j = 0 ; j < barCodeArray.length ; j ++){
-                    dataMap.set(barCodeArray[j],0);
-                }
-                vm.combinationPrice.set(data,rMap.zhjsp[data][0].combinedPrice)
-
-                vm.zhjsp.set(data,dataMap);
-            }
-        }
-
-    }
-    calculateGoodsByMj(r.goodsDetails,"add");
+    // if(rMap.zhjsp){
+    //     // 遍历该商品所有可能的组合价商品类型
+    //     for(var data in rMap.zhjsp){
+    //         if(!vm.zhjsp.get(data)){
+    //             // 分割组合价商品的条码,并以 条码:0 放入map中
+    //             var barCodeArray = data.toString().split(":");
+    //             var dataMap = new Map();
+    //             console.log(rMap.zhjsp[data]);
+    //             // dataMap.set();
+    //             for(var j = 0 ; j < barCodeArray.length ; j ++){
+    //                 dataMap.set(barCodeArray[j],0);
+    //             }
+    //             vm.combinationPrice.set(data,rMap.zhjsp[data][0].combinedPrice)
+    //
+    //             vm.zhjsp.set(data,dataMap);
+    //         }
+    //     }
+    //
+    // }
+    // calculateGoodsByMj(r.goodsDetails,"add");
     calculateGoodsByMysy(r.goodsDetails,"add");
     calculateGoodsByMz(r.goodsDetails,"add");
-    calculateGoodsByZhjsp(r);
+    // calculateGoodsByZhjsp(r);
 
 }
 
@@ -113,15 +116,26 @@ function fullReduction(goodsDetails,key){
 
 // 满赠
 function calculateGoodsByMz(goodsDetails,type){
-
-    // 1.满赠的商品是不是自己,遍历满赠商品数组
-    isSend(vm.fullGiftCode,goodsDetails,"满赠");
-
-    if(vm.mz.get(goodsDetails.prodBarcode)){
-        fullGift(goodsDetails,goodsDetails.prodBarcode);
-    }else if(vm.mz.get(goodsDetails.brand)){
-        fullGift(goodsDetails,goodsDetails.brand);
+    debugger;
+    // 判断当前支付金额是否满足满赠金额,若满足,直接修改金额为1
+    var mzGoods = vm.mz.get(goodsDetails.prodBarcode);
+    if(mzGoods){
+        var mzPrice = mzGoods.qualifiedAmount;
+        if(mzPrice <  vm.actualPrice && !mzGoods.useMz){
+            mzGoods.useMz = true;
+            goodsDetails.actualPaymentAmount = 1;
+            goodsDetails.discountedPrice = goodsDetails.retailPrice - 1;
+        }
     }
+
+    // // 1.满赠的商品是不是自己,遍历满赠商品数组
+    // isSend(vm.fullGiftCode,goodsDetails,"满赠");
+    //
+    // if(vm.mz.get(goodsDetails.prodBarcode)){
+    //     fullGift(goodsDetails,goodsDetails.prodBarcode);
+    // }else if(vm.mz.get(goodsDetails.brand)){
+    //     fullGift(goodsDetails,goodsDetails.brand);
+    // }
 }
 
 function fullGift(goodsDetails,key){
@@ -152,19 +166,22 @@ function fullGift(goodsDetails,key){
 
 // 买一送一
 function calculateGoodsByMysy(goodsDetails,type){
-    var mysy = vm.newMysy.get(goodsDetails.prodBarcode);
+    var mysy = vm.barcodeGetOneFree.get(goodsDetails.prodBarcode);
+    var brandMysy = vm.brandGetOneFree.get(goodsDetails.brand);
     if(mysy){
         var buyNum = mysy.buyNum;
         if(type == "add"){
+            
             // 证明是买一送一,并且达到买一送一的条件
             if(buyNum == 1 && vm.boughtNum.get(goodsDetails.prodBarcode)){
                 // 设置赠品的单价
                 goodsDetails.discountedPrice = goodsDetails.retailPrice;
                 goodsDetails.actualPaymentAmount = 0;
-                goodsDetails.activity = "买1送1";
+                // goodsDetails.activity = "买1送1";
 
                 // 清除该商品买一送一条件
                 vm.boughtNum.delete(goodsDetails.prodBarcode);
+                return ;
             }
             // 如果不是买一送一,而是买n送n,先获取购物车已有该类型商品数量
             var boughtNum = vm.boughtNum.get(goodsDetails.prodBarcode);
@@ -178,7 +195,7 @@ function calculateGoodsByMysy(goodsDetails,type){
             if(buyNum === boughtNum){
                 goodsDetails.discountedPrice = goodsDetails.retailPrice;
                 goodsDetails.actualPaymentAmount = 0;
-                goodsDetails.activity = "买"+buyNum+"送1";
+                // goodsDetails.activity = "买"+buyNum+"送1";
                 // 清除该商品买一送一条件
                 vm.boughtNum.delete(goodsDetails.prodBarcode);
                 console.log(vm.boughtNum);
@@ -194,33 +211,33 @@ function calculateGoodsByMysy(goodsDetails,type){
             var boughtNum = goodsDetails.sellVolume;
             // 减一后,不满足买一送一条件,重新计算金额
             // 如果不等于0,要减去价格
-            debugger;
+            
             var remainder = 0;
             if(boughtNum > buyNum+1){
                 remainder = buyNum - (boughtNum % (buyNum+1))  ;
             }else{
                 remainder = buyNum - ((buyNum+1) %boughtNum )  ;
             }
-
             if(boughtNum % (buyNum+1) != 0){
                 // console.log("我要减去价格,也要减去数量,减去数量=" + goodsDetails.sellVolume);
-                goodsDetails.actualPaymentAmount = -goodsDetails.retailPrice;
-                // goodsDetails.discountedPrice = 0;
-                goodsDetails.sellVolume = -1 ;
+                goodsDetails.actualPaymentAmount = goodsDetails.retailPrice;
+                goodsDetails.discountedPrice = 0;
             // 如果等于0,只用减去数量跟优惠价,并恢复活动
             }else{
                 // console.log("我不用减去价格,只要减去数量");
-                goodsDetails.sellVolume = -1 ;
-                goodsDetails.discountedPrice = -goodsDetails.retailPrice;
+                goodsDetails.discountedPrice = goodsDetails.retailPrice;
                 goodsDetails.actualPaymentAmount = 0;
             }
-            goodsDetails.retailPrice = - goodsDetails.retailPrice;
+            goodsDetails.sellVolume = 1;
             vm.boughtNum.set(goodsDetails.prodBarcode,remainder);
-            goodsDetails.goodstaxes = - goodsDetails.goodstaxes;
+
         }
 
     }
 
+    
+    
+    
     // 判断当前商品是否为赠品
     // isSend(vm.mysy,goodsDetails,"买一送一");
     // 判断购物车里面是否有商品为赠品
@@ -236,9 +253,8 @@ function isSend(activity,goodsDetails,activityName){
         var index = activity.indexOf(goodsDetails.prodBarcode);
         activity.splice(index,1);
         // 设置赠品的单价
-        goodsDetails.discountedPrice = goodsDetails.retailPrice;
-        goodsDetails.actualPaymentAmount = 0;
-        goodsDetails.activity = activityName;
+        goodsDetails.discountedPrice = goodsDetails.retailPrice - 1;
+        goodsDetails.actualPaymentAmount = 1;
     }
 }
 
@@ -408,7 +424,9 @@ let vm = new Vue({
         },
         // 买一送一
         mysy: [],
-        newMysy: new Map(),
+        freeBardcode : new Map(),
+        brandGetOneFree : new Map(),
+        barcodeGetOneFree: new Map(),
         boughtNum: new Map(),
         // 组合价
         zhjsp: new Map(),
@@ -421,6 +439,7 @@ let vm = new Vue({
         reduceMoney:0, // 满减金额
         showReduceMoney:0, // 用于展示的满减金额
         // 满赠
+        useMz:false,
         mz: new Map(),
         accumulatedAmountForFullGift: new Map(), // 累积金额(满赠使用的)
         fullGiftCode:[],// 满赠商品条码
@@ -440,11 +459,15 @@ let vm = new Vue({
             var thisGoods = {};
             $.get("../goods/details/"+vm.prodBarcode+"/"+vm.storeId, function (r) {
                 if (r.code == 0) {
+
+                    r.goodsDetails.sellVolume = 1;
+                    vm.goodsMap.set(r.goodsDetails.goodsSn,JSON.parse(JSON.stringify(r.goodsDetails)));
                     vm.prodBarcode = '';
                     calculateGoodsPrice(r);
-                    r.goodsDetails.sellVolume = 1;
-                    handle(r.goodsDetails);
-                    vm.goodsMap.set(r.goodsDetails.goodsSn,r.goodsDetails);
+                    handle(r.goodsDetails,"add");
+
+
+
                 } else {
                     alert(r.msg);
                 }
@@ -458,8 +481,8 @@ let vm = new Vue({
                     var goodsDetails = JSON.parse(JSON.stringify(vm.goodsMap.get(this.goodsList[i].goodsSn)));
                     calculateGoodsByMj(goodsDetails,"add");
                     calculateGoodsByMysy(goodsDetails,"add");
-                    calculateGoodsByMz(goodsDetails,"add");
-                    handle(goodsDetails);
+                    // calculateGoodsByMz(goodsDetails,"add");
+                    handle(goodsDetails,"add");
                     break;
                 }
             }
@@ -468,7 +491,6 @@ let vm = new Vue({
             // 减少数量
             for(var i = 0 ; i < this.goodsList.length ; i++){
                 if(this.goodsList[i].id == value){
-
                     // 获取当前购物车的数量
                     var g = JSON.parse(JSON.stringify(this.goodsList[i]));
 
@@ -478,11 +500,17 @@ let vm = new Vue({
                         alert("数量至少为1个");
                         return ;
                     }
+                    debugger;
                     goodsDetails.sellVolume = g.sellVolume;
                     calculateGoodsByMj(goodsDetails,"minus");
                     calculateGoodsByMysy(goodsDetails,"minus");
-                    calculateGoodsByMz(goodsDetails,"minus");
-                    handle(goodsDetails);
+                    // calculateGoodsByMz(goodsDetails,"minus");
+                    goodsDetails.sellVolume = -1;
+                    goodsDetails.actualPaymentAmount = -goodsDetails.actualPaymentAmount;
+                    goodsDetails.discountedPrice = -goodsDetails.discountedPrice;
+                    goodsDetails.goodstaxes = - goodsDetails.goodstaxes;
+                    goodsDetails.retailPrice = - goodsDetails.retailPrice;
+                    handle(goodsDetails,"minus");
                     break;
                 }
             }
@@ -497,7 +525,9 @@ let vm = new Vue({
                         vm.goods = {};
                         vm.goodsDetail = false;
                     }
-
+                    if(vm.mz.get(this.goodsList[i].prodBarcode)){
+                        vm.mz.get(this.goodsList[i].prodBarcode).useMz = false ;
+                    }
                     var goods = this.goodsList[i];
                     console.log(goods);
                     vm.totalPrice = vm.totalPrice - (goods.retailPrice * goods.sellVolume);
@@ -617,7 +647,8 @@ let vm = new Vue({
             vm.goodsDetail = false;
             // 买一送一
             vm.mysy = [];
-            vm.newMysy = new Map();
+            vm.barcodeGetOneFree = new Map();
+            vm.brandGetOneFree = new Map();
             vm.boughtNum = new Map();
             // 组合价
             vm.zhjsp = new Map();
@@ -1238,7 +1269,7 @@ function removeByValue(arr, val) {
     }
 }
 
-function handle(goodsDetails){
+function handle(goodsDetails,operatorType){
     vm.goodsDetail = true;
     // goodsDetails.sellVolume = 1;
     goodsDetails.id = vm.index;
@@ -1248,6 +1279,12 @@ function handle(goodsDetails){
     vm.max++;
     goodsDetails.goodsDesc = "";
 
+
+
+
+
+
+
     goodsDetails.discountedPrice =  Math.round(goodsDetails.discountedPrice * 100) / 100;
     goodsDetails.actualPaymentAmount =  Math.round(goodsDetails.actualPaymentAmount * 100) / 100;
     var data = Object.assign({}, JSON.parse(JSON.stringify(goodsDetails)));
@@ -1256,16 +1293,35 @@ function handle(goodsDetails){
     for(var i = 0 ; i < vm.goodsList.length ; i++){
         if(vm.goodsList[i].goodsSn == data.goodsSn){
             var goodsDetails = vm.goodsList[i];
-            // 税 goodstaxes,优惠金额 discountedPrice,实际支付 actualPaymentAmount,数量 sellVolume 45636917
-            goodsDetails.goodstaxes = Math.round((parseFloat(goodsDetails.goodstaxes) +  parseFloat(data.goodstaxes)) * 100)/100;
+            if(data.actualPaymentAmount < 0 && goodsDetails.actualPaymentAmount == 0){
+                // goodsDetails.goodstaxes = Math.round((parseFloat(goodsDetails.goodstaxes) -  parseFloat(data.goodstaxes)) * 100)/100;
+                // goodsDetails.discountedPrice = Math.round((parseFloat(goodsDetails.discountedPrice) -  parseFloat(data.discountedPrice)) * 100)/100;
+                goodsDetails.actualPaymentAmount = 0;
+            }else{
+                // 税 goodstaxes,优惠金额 discountedPrice,实际支付 actualPaymentAmount,数量 sellVolume 45636917
+                goodsDetails.actualPaymentAmount = Math.round((parseFloat(goodsDetails.actualPaymentAmount) +  parseFloat(data.actualPaymentAmount)) * 100)/100;
+            }
             goodsDetails.discountedPrice = Math.round((parseFloat(goodsDetails.discountedPrice) +  parseFloat(data.discountedPrice)) * 100)/100;
-            goodsDetails.actualPaymentAmount = Math.round((parseFloat(goodsDetails.actualPaymentAmount) +  parseFloat(data.actualPaymentAmount)) * 100)/100;
+            goodsDetails.goodstaxes = Math.round((parseFloat(goodsDetails.goodstaxes) +  parseFloat(data.goodstaxes)) * 100)/100;
             goodsDetails.sellVolume = Math.round((parseFloat(goodsDetails.sellVolume) +  parseFloat(data.sellVolume)) * 100)/100;
             goodsDetails.activity = data.activity;
             isPush = false;
             break;
         }
     }
+    // for(var i = 0 ; i < vm.goodsList.length ; i++){
+    //     if(vm.goodsList[i].goodsSn == data.goodsSn){
+    //         var goodsDetails = vm.goodsList[i];
+    //         // 税 goodstaxes,优惠金额 discountedPrice,实际支付 actualPaymentAmount,数量 sellVolume 45636917
+    //         goodsDetails.goodstaxes = Math.round((parseFloat(goodsDetails.goodstaxes) +  parseFloat(data.goodstaxes)) * 100)/100;
+    //         goodsDetails.discountedPrice = Math.round((parseFloat(goodsDetails.discountedPrice) +  parseFloat(data.discountedPrice)) * 100)/100;
+    //         goodsDetails.actualPaymentAmount = Math.round((parseFloat(goodsDetails.actualPaymentAmount) +  parseFloat(data.actualPaymentAmount)) * 100)/100;
+    //         goodsDetails.sellVolume = Math.round((parseFloat(goodsDetails.sellVolume) +  parseFloat(data.sellVolume)) * 100)/100;
+    //         goodsDetails.activity = data.activity;
+    //         isPush = false;
+    //         break;
+    //     }
+    // }
     if(isPush){
         vm.goodsList.push(data);
         vm.index = vm.index + 1;