瀏覽代碼

Merge branch 'master' of http://git.ds-bay.com/project/kmall-haikong

zyh 3 年之前
父節點
當前提交
1606a79030

+ 8 - 4
kmall-admin/src/main/java/com/kmall/admin/controller/order/OrderController.java

@@ -615,8 +615,10 @@ public class OrderController {
             BigDecimal allDiscountedPrice = new BigDecimal(0);
             for (OrderGoodsEntity orderGoodsEntity : goodsList) {
                 GoodsEntity goodsEntity = goodsService.queryObject(orderGoodsEntity.getGoodsId());
-                BigDecimal goodsTax = CalculateTax.calculateFinalTax(goodsEntity,orderGoodsEntity.getMarketPrice(),goodsService).setScale(3,RoundingMode.HALF_UP);
-                goodsTax = goodsTax.multiply(new BigDecimal(orderGoodsEntity.getNumber())).setScale(2,RoundingMode.HALF_UP);
+                // 计算算税金额 实际支付价 + 积分抵扣金额
+                BigDecimal price = orderGoodsEntity.getDeductionPrice().add(orderGoodsEntity.getActualPaymentAmount());
+                BigDecimal goodsTax = CalculateTax.calculateFinalTax(goodsEntity,price,goodsService).setScale(3,RoundingMode.HALF_UP);
+                // goodsTax = goodsTax.multiply(new BigDecimal(orderGoodsEntity.getNumber())).setScale(2,RoundingMode.HALF_UP);
                 orderGoodsEntity.setTax(goodsTax);
                 tax = tax.add(goodsTax).setScale(2,RoundingMode.HALF_UP);
 //                BigDecimal goodsTax = orderGoodsEntity.getMarketPrice().divide(new BigDecimal(1).add(orderGoodsEntity.getGoodsRate()),2,RoundingMode.HALF_DOWN).multiply(orderGoodsEntity.getGoodsRate())
@@ -671,8 +673,10 @@ public class OrderController {
         BigDecimal allDiscountedPrice = new BigDecimal(0);
         for (OrderGoodsEntity orderGoodsEntity : goodsList) {
             GoodsEntity goodsEntity = goodsService.queryObject(orderGoodsEntity.getGoodsId());
-            BigDecimal goodsTax = CalculateTax.calculateFinalTax(goodsEntity,orderGoodsEntity.getMarketPrice(),goodsService).setScale(3,RoundingMode.HALF_UP);
-            goodsTax = goodsTax.multiply(new BigDecimal(orderGoodsEntity.getNumber())).setScale(2,RoundingMode.HALF_UP);
+            // 计算算税金额 实际支付价 + 积分抵扣金额
+            BigDecimal price = orderGoodsEntity.getDeductionPrice().add(orderGoodsEntity.getActualPaymentAmount());
+            BigDecimal goodsTax = CalculateTax.calculateFinalTax(goodsEntity,price,goodsService).setScale(3,RoundingMode.HALF_UP);
+            // goodsTax = goodsTax.multiply(new BigDecimal(orderGoodsEntity.getNumber())).setScale(2,RoundingMode.HALF_UP);
             orderGoodsEntity.setTax(goodsTax);
             tax = tax.add(goodsTax).setScale(2,RoundingMode.HALF_UP);
             // 计算其他优惠 = 总优惠减去积分抵扣优惠

+ 25 - 5
kmall-admin/src/main/java/com/kmall/admin/service/impl/GoodsServiceImpl.java

@@ -1594,7 +1594,11 @@ public class GoodsServiceImpl implements GoodsService {
 
         // 计算税费
         GoodsEntity goodsEntity = goodsDao.queryByBarcodeAndSku(prodBarcode, goods.getGoodsSn());
-        BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity, goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
+        // 计算算税金额 实际支付价 + 积分抵扣金额
+        BigDecimal deductionPrice = Objects.isNull(goods.getDeductionPrice()) ? new BigDecimal("0") : goods.getDeductionPrice();
+        BigDecimal actualPaymentAmount = Objects.isNull(goods.getActualPaymentAmount()) ? new BigDecimal("0") : goods.getActualPaymentAmount();
+        BigDecimal price = deductionPrice.add(actualPaymentAmount);
+        BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity, price,this).setScale(3,RoundingMode.HALF_UP);
         goods.setGoodstaxes(tax.toString());
         goods.setSellVolume(1);
 
@@ -1712,7 +1716,11 @@ public class GoodsServiceImpl implements GoodsService {
         Map<String,Object> skuActivitiesMap = new HashMap<>();
         // 计算税费
         GoodsEntity goodsEntity = goodsDao.queryByBarcodeAndSku(prodBarcode, goods.getGoodsSn());
-        BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity,goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
+        // 计算算税金额 实际支付价 + 积分抵扣金额
+        BigDecimal deductionPrice = Objects.isNull(goods.getDeductionPrice()) ? new BigDecimal("0") : goods.getDeductionPrice();
+        BigDecimal actualPaymentAmount = Objects.isNull(goods.getActualPaymentAmount()) ? new BigDecimal("0") : goods.getActualPaymentAmount();
+        BigDecimal price = deductionPrice.add(actualPaymentAmount);
+        BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity,price,this).setScale(3,RoundingMode.HALF_UP);
         goods.setGoodstaxes(tax.toString());
 
 
@@ -2019,7 +2027,11 @@ public class GoodsServiceImpl implements GoodsService {
         goods.setRetailPrice(promotionEntity.getActivityPrice());
         goods.setActivity("临时促销");
         try {
-            CalculateTax.calculateFinalTax(goods,goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
+            // 计算算税金额 实际支付价 + 积分抵扣金额
+            BigDecimal deductionPrice = Objects.isNull(goods.getDeductionPrice()) ? new BigDecimal("0") : goods.getDeductionPrice();
+            BigDecimal actualPaymentAmount = Objects.isNull(goods.getActualPaymentAmount()) ? new BigDecimal("0") : goods.getActualPaymentAmount();
+            BigDecimal price = deductionPrice.add(actualPaymentAmount);
+            CalculateTax.calculateFinalTax(goods,price,this).setScale(3,RoundingMode.HALF_UP);
         } catch (Exception e) {
             ShopErrorPriceRecordEntity shopErrorPriceRecordEntity = new ShopErrorPriceRecordEntity();
             shopErrorPriceRecordEntity.setMerchSn(goods.getMerchSn());
@@ -2068,7 +2080,11 @@ public class GoodsServiceImpl implements GoodsService {
         goods.setActivity("日常活动");
         // 计算税费
         try {
-            CalculateTax.calculateFinalTax(goods,goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
+            // 计算算税金额 实际支付价 + 积分抵扣金额
+            BigDecimal deductionPrice = Objects.isNull(goods.getDeductionPrice()) ? new BigDecimal("0") : goods.getDeductionPrice();
+            BigDecimal actualPaymentAmount = Objects.isNull(goods.getActualPaymentAmount()) ? new BigDecimal("0") : goods.getActualPaymentAmount();
+            BigDecimal price = deductionPrice.add(actualPaymentAmount);
+            CalculateTax.calculateFinalTax(goods,price,this).setScale(3,RoundingMode.HALF_UP);
         } catch (Exception e) {
             // 记录有异常的sku
             ShopErrorPriceRecordEntity shopErrorPriceRecordEntity = new ShopErrorPriceRecordEntity();
@@ -2106,7 +2122,11 @@ public class GoodsServiceImpl implements GoodsService {
 
         // 计算税费
         try {
-            CalculateTax.calculateFinalTax(goods,goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
+            // 计算算税金额 实际支付价 + 积分抵扣金额
+            BigDecimal deductionPrice = Objects.isNull(goods.getDeductionPrice()) ? new BigDecimal("0") : goods.getDeductionPrice();
+            BigDecimal actualPaymentAmount = Objects.isNull(goods.getActualPaymentAmount()) ? new BigDecimal("0") : goods.getActualPaymentAmount();
+            BigDecimal price = deductionPrice.add(actualPaymentAmount);
+            CalculateTax.calculateFinalTax(goods,price,this).setScale(3,RoundingMode.HALF_UP);
         } catch (Exception e) {
             // 记录有异常的sku
             ShopErrorPriceRecordEntity shopErrorPriceRecordEntity = new ShopErrorPriceRecordEntity();

+ 20 - 9
kmall-admin/src/main/java/com/kmall/admin/service/impl/OrderServiceImpl.java

@@ -562,8 +562,10 @@ public class OrderServiceImpl implements OrderService {
 
 
             GoodsEntity goodsEntity = goodsService.queryObject(orderGoods.getGoodsId());
-            BigDecimal goodsTax = CalculateTax.calculateFinalTax(goodsEntity, orderGoods.getRetailPrice(), goodsService).setScale(3, RoundingMode.HALF_UP);
-            goodsTax = goodsTax.multiply(new BigDecimal(orderGoods.getNumber())).setScale(2, RoundingMode.HALF_UP);
+            // 计算算税金额 实际支付价 + 积分抵扣金额
+            BigDecimal price = orderGoods.getDeductionPrice().add(orderGoods.getActualPaymentAmount());
+            BigDecimal goodsTax = CalculateTax.calculateFinalTax(goodsEntity, price, goodsService).setScale(3, RoundingMode.HALF_UP);
+            //goodsTax = goodsTax.multiply(new BigDecimal(orderGoods.getNumber())).setScale(2, RoundingMode.HALF_UP);
             taxTotal = taxTotal.add(goodsTax).setScale(2, RoundingMode.HALF_UP);
 
             Goods goods = new Goods(orderGoods.getGoodsName(),
@@ -2644,6 +2646,8 @@ public class OrderServiceImpl implements OrderService {
                  * 根据门店id 和时间查询积分赠送规则
                  */
                 List<PointsRulesAndDetailVO> pointsRulesAndDetailVOList= mall2PointsRulesService.queryListByTime(new Date(), store.getId().toString());
+                // 将此商品列表信息分组  key:sku 值:购买数量
+                Map<String, Integer> queryGoodsVOListMap = queryGoodsVOList.stream().collect(Collectors.toMap(QueryGoodsVO::getSku, QueryGoodsVO::getSellVolume, (k1, k2) -> k2));
 
                 // 商品map,key===>sku value===>金额
                 Map<String, BigDecimal> goodsMap = goodsEntities.stream().collect(Collectors.toMap(GoodsEntity::getSku, GoodsEntity::getActualPaymentAmount, (k1, k2) -> k2));
@@ -2651,7 +2655,9 @@ public class OrderServiceImpl implements OrderService {
                 Map<String, GoodsEntity> goodsDataMap = goodsEntities.stream().collect(Collectors.toMap(GoodsEntity::getSku, goodsEntity -> goodsEntity, (k1, k2) -> k2));
                 // 根据门店、时间和活动类型 查询参加积分赠送活动的sku,转换为map
                 //  ,sku为key,对象为值,判断sku是否在此之中,在则计算赠送积分算完
-                List<MkActivitiesPresentIntegralEntity> mkActivitiesEntityList = mkActivitiesPresentIntegralService.querySkuByNow(store.getId().toString(), DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"), Constants.ActivityTopicEnum.ZSJF.getTopicCode());
+                List<MkActivitiesPresentIntegralEntity> mkActivitiesEntityList = mkActivitiesPresentIntegralService.querySkuByNow(store.getId().toString(), DateUtils.format(new Date()
+                        , "yyyy-MM-dd HH:mm:ss")
+                        , Constants.ActivityTopicEnum.ZSJF.getTopicCode());
                 Map<String, MkActivitiesPresentIntegralEntity> mkActivitiesEntityMap = new HashMap<>();
                 if(!CollectionUtils.isEmpty(mkActivitiesEntityList) && mkActivitiesEntityList.size() > 0){
                     // 不为空 则处理
@@ -2676,6 +2682,7 @@ public class OrderServiceImpl implements OrderService {
                             // 商品积分生成规则包含这个sku
                             // 订单中该sku的总金额
                             BigDecimal money = goodsMap.get(pointsDetailNameId);
+                            Integer number = queryGoodsVOListMap.get(pointsDetailNameId);
                             OrderGiftScoreRulesVo orderGiftScoreRulesVo = new OrderGiftScoreRulesVo();
                             orderGiftScoreRulesVo.setGenerateType(Constants.MemberScoreRulesEnum.TWO.getCode());
                             BigDecimal bigDecimal = new BigDecimal(0);
@@ -2694,7 +2701,7 @@ public class OrderServiceImpl implements OrderService {
                             }
                             // 在这里计算赠送积分,并放入
                             // 判断此sku是否参加活动 并计算活动积分
-                            getGiftScore(activityGiftScore, bigDecimal, mkActivitiesEntityMap, pointsDetailNameId, orderGiftScoreRulesVo);
+                            getGiftScore(activityGiftScore, bigDecimal, mkActivitiesEntityMap, pointsDetailNameId, orderGiftScoreRulesVo,number);
                             giftGoodsScoreDetailMap.put(pointsDetailNameId, orderGiftScoreRulesVo);
                             goodsDataMap.remove(pointsDetailNameId);
                         }
@@ -2707,6 +2714,7 @@ public class OrderServiceImpl implements OrderService {
                             // 商品类别
                             Integer categoryId = goodsEntity.getCategoryId();
                             String sku = goodsEntity.getSku();
+                            Integer number = queryGoodsVOListMap.get(sku);
                             OrderGiftScoreRulesVo orderGiftScoreRulesVo = new OrderGiftScoreRulesVo();
                             orderGiftScoreRulesVo.setGenerateType(Constants.MemberScoreRulesEnum.ONE.getCode());
                             if (categorySet.contains(categoryId)) {
@@ -2728,7 +2736,7 @@ public class OrderServiceImpl implements OrderService {
                                         orderGiftScoreRulesVo.setGenerateRatio(BigDecimal.ZERO);
                                     }
                                     // 判断此sku是否参加活动 并计算活动积分
-                                    getGiftScore(activityGiftScore, bigDecimal, mkActivitiesEntityMap, sku, orderGiftScoreRulesVo);
+                                    getGiftScore(activityGiftScore, bigDecimal, mkActivitiesEntityMap, sku, orderGiftScoreRulesVo, number);
                                     giftGoodsScoreDetailMap.put(sku, orderGiftScoreRulesVo);
                                     goodsDataMap.remove(sku);
                                 }
@@ -2742,6 +2750,7 @@ public class OrderServiceImpl implements OrderService {
                         for(GoodsEntity goodsEntity : goodsEntityCollection){
                             Integer storeId1 = goodsEntity.getStoreId();
                             String sku = goodsEntity.getSku();
+                            Integer number = queryGoodsVOListMap.get(sku);
                             OrderGiftScoreRulesVo orderGiftScoreRulesVo = new OrderGiftScoreRulesVo();
                             orderGiftScoreRulesVo.setGenerateType(Constants.MemberScoreRulesEnum.ZERO.getCode());
                             BigDecimal bigDecimal = new BigDecimal(0);
@@ -2764,7 +2773,7 @@ public class OrderServiceImpl implements OrderService {
                             }
 
                             // 判断此sku是否参加活动 并计算活动积分
-                            getGiftScore(activityGiftScore, bigDecimal, mkActivitiesEntityMap, sku, orderGiftScoreRulesVo);
+                            getGiftScore(activityGiftScore, bigDecimal, mkActivitiesEntityMap, sku, orderGiftScoreRulesVo,number);
                             giftGoodsScoreDetailMap.put(sku, orderGiftScoreRulesVo);
                         }
 
@@ -2892,14 +2901,14 @@ public class OrderServiceImpl implements OrderService {
      * @param sku
      */
     private void getGiftScore(AtomicReference<Integer> activityGiftScore, BigDecimal baseScore
-            , Map<String, MkActivitiesPresentIntegralEntity> mkActivitiesEntityMap, String sku, OrderGiftScoreRulesVo orderGiftScoreRulesVo) {
+            , Map<String, MkActivitiesPresentIntegralEntity> mkActivitiesEntityMap, String sku, OrderGiftScoreRulesVo orderGiftScoreRulesVo,Integer number) {
         if(mkActivitiesEntityMap.containsKey(sku)){
             // 存在表示它参加赠送积分活动
             MkActivitiesPresentIntegralEntity mkActivitiesPresentIntegralEntity = mkActivitiesEntityMap.get(sku);
             // 计算活动积分
             if(ActivityGiveTypeEnum.FIXED_VALUE.getCode().equals(mkActivitiesPresentIntegralEntity.getActivityGiveType())){
                 // 固定值  那赠送积分就是固定值
-                BigDecimal giftScoreTmp = mkActivitiesPresentIntegralEntity.getActivityGiveNum();
+                BigDecimal giftScoreTmp = mkActivitiesPresentIntegralEntity.getActivityGiveNum().multiply(new BigDecimal(number));
                 // 此sku赠送的积分加上之前赠送的积分 算出来订单赠送总分
                 int giftScore = giftScoreTmp.add(new BigDecimal(activityGiftScore.get())).intValue();
                 activityGiftScore.set(giftScore);
@@ -5494,7 +5503,9 @@ public class OrderServiceImpl implements OrderService {
         /*GoodsEntity goodsEntity = goodsService.queryObject(goodsDto.getId().intValue());
         BigDecimal goodsTax = CalculateTax.calculateFinalTax(goodsEntity, goodsDto.getStoreRetailPrice(), goodsService).setScale(3, RoundingMode.HALF_UP);
         goodsTax = goodsTax.multiply(number).setScale(2, RoundingMode.HALF_UP);*/
-        orderGoodsVo.setTaxPrice(goodsDto.getGoodsTaxes().divide(BigDecimal.valueOf(goodsDto.getSellVolume()), 3, BigDecimal.ROUND_HALF_UP));
+        // wcq注解: 原先在数据入库的时候  预估税费除以了数量  现在不除以数量了
+        // 注释代码:.divide(BigDecimal.valueOf(goodsDto.getSellVolume()), 3, BigDecimal.ROUND_HALF_UP)
+        orderGoodsVo.setTaxPrice(goodsDto.getGoodsTaxes());
 
         return orderGoodsVo;
     }