From 8948d3e30d31fe7645c66e50d280c256dd3c4b5c Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Mon, 20 Mar 2023 12:44:02 +0800
Subject: [PATCH] 后台修改

---
 src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java |   68 +++++++++++++++-------------------
 1 files changed, 30 insertions(+), 38 deletions(-)

diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
index 593621c..8b8639b 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
@@ -206,25 +206,19 @@
         /**
          * 使用积分折扣现金
          */
-        DataDictionaryCustom scorePercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
-                DataDictionaryEnum.SCORE_PERCENT.getType(),
-                DataDictionaryEnum.SCORE_PERCENT.getCode()
-        );
         DataDictionaryCustom scoreChangeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                 DataDictionaryEnum.SCORE_CHANGE.getType(),
                 DataDictionaryEnum.SCORE_CHANGE.getCode()
         );
         BigDecimal score = ObjectUtil.isEmpty(addOrderDto.getScore()) ? BigDecimal.ZERO : addOrderDto.getScore();
         orderInfo.setScoreCnt(score);
-        if(ObjectUtil.isNotEmpty(scorePercentDic)){
-            BigDecimal scoreChange = BigDecimal.ONE;
-            if(ObjectUtil.isNotEmpty(scoreChangeDic)){
-                scoreChange = new BigDecimal(scoreChangeDic.getValue()).abs().setScale(2,BigDecimal.ROUND_DOWN);
-            }
-            //折扣现金
-            BigDecimal scorePercentAmount = score.divide(scoreChange,BigDecimal.ROUND_DOWN).setScale(2,BigDecimal.ROUND_DOWN);
-            orderInfo.setScoreAmount(scorePercentAmount);
+        BigDecimal scoreChange = BigDecimal.ONE;
+        if(ObjectUtil.isNotEmpty(scoreChangeDic)){
+            scoreChange = new BigDecimal(scoreChangeDic.getValue()).abs().setScale(2,BigDecimal.ROUND_DOWN);
         }
+        //折扣现金
+        BigDecimal scorePercentAmount = score.divide(scoreChange,BigDecimal.ROUND_DOWN).setScale(2,BigDecimal.ROUND_DOWN);
+        orderInfo.setScoreAmount(scorePercentAmount);
         orderInfo.setAmount(total);
         if(2 == deliverType){
             orderInfo.setDeliverType(2);
@@ -851,18 +845,24 @@
         }
 
         boolean hasTc = false;
+        //总的折扣积分数量
         BigDecimal total = BigDecimal.ZERO;
         for (AddOrderItemDto item : addOrderDto.getItems()) {
-                MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(item.getSkuId());
-                MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId());
-                /**
-                 * 贡献点判断
+            MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(item.getSkuId());
+            MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId());
+            /**
+             * 贡献点判断
+             */
+            if (mallGoods.getIsNormal() == 2) {
+                hasTc = true;
+            }
+                /*
+                获取单个商品的折扣积分数量
+                    = 现价 * 数量 * 折扣现金比例
                  */
-                if (mallGoods.getIsNormal() == 2) {
-                    hasTc = true;
-                }
-                BigDecimal amount = sku.getPresentPrice().multiply(BigDecimal.valueOf(item.getCnt()));
-                total = total.add(amount);
+            BigDecimal scorePercent = new BigDecimal(mallGoods.getScorePercent()).multiply(new BigDecimal(0.01));
+            BigDecimal amount = sku.getPresentPrice().multiply(BigDecimal.valueOf(item.getCnt())).multiply(scorePercent);
+            total = total.add(amount);
         }
 
         BigDecimal score = ObjectUtil.isEmpty(addOrderDto.getScore()) ? BigDecimal.ZERO : addOrderDto.getScore();
@@ -889,28 +889,20 @@
         /**
          * 使用积分折扣现金
          */
-        DataDictionaryCustom scorePercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
-                DataDictionaryEnum.SCORE_PERCENT.getType(),
-                DataDictionaryEnum.SCORE_PERCENT.getCode()
-        );
         DataDictionaryCustom scoreChangeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                 DataDictionaryEnum.SCORE_CHANGE.getType(),
                 DataDictionaryEnum.SCORE_CHANGE.getCode()
         );
 
-        if(ObjectUtil.isNotEmpty(scorePercentDic)){
-            //商品的现金折扣比例
-            BigDecimal scorePercent = new BigDecimal(scorePercentDic.getValue()).multiply(BigDecimal.valueOf(0.01));
-            //最大折扣金额对应需要的总积分数目
-            BigDecimal scorePercentMaxAmount = total.multiply(scorePercent);
-            BigDecimal scoreChange = BigDecimal.ONE;
-            if(ObjectUtil.isNotEmpty(scoreChangeDic)){
-                scoreChange = new BigDecimal(scoreChangeDic.getValue()).abs().setScale(2,BigDecimal.ROUND_DOWN);
-            }
-            scorePercentMaxAmount = scorePercentMaxAmount.multiply(scoreChange).setScale(2,BigDecimal.ROUND_DOWN);
-            if(scorePercentMaxAmount.compareTo(score) < 0){
-                throw new FebsException("最多可使用"+scorePercentMaxAmount+"积分");
-            }
+        //最大折扣金额对应需要的总积分数目
+        BigDecimal scorePercentMaxAmount = total;
+        BigDecimal scoreChange = BigDecimal.ONE;
+        if(ObjectUtil.isNotEmpty(scoreChangeDic)){
+            scoreChange = new BigDecimal(scoreChangeDic.getValue()).abs().setScale(2,BigDecimal.ROUND_DOWN);
+        }
+        scorePercentMaxAmount = scorePercentMaxAmount.multiply(scoreChange).setScale(2,BigDecimal.ROUND_DOWN);
+        if(scorePercentMaxAmount.compareTo(score) < 0){
+            throw new FebsException("最多可使用"+scorePercentMaxAmount+"积分");
         }
         return new FebsResponse().success();
     }

--
Gitblit v1.9.1