1
0
فهرست منبع

统一设置最大积分抵扣比例,新增积分抵扣是否参与逻辑

lhm 3 سال پیش
والد
کامیت
be12dd0f4e

+ 0 - 9
kmall-admin/src/main/java/com/kmall/admin/dto/ScoreReductionDTO.java

@@ -16,7 +16,6 @@ public class ScoreReductionDTO implements Serializable {
     private String prodBarcode;
     private String sku;
     private Integer storeId;
-    private BigDecimal scoreLimit;
     private Date deadline;
     private String deadlineStr;
     private String reject;
@@ -45,14 +44,6 @@ public class ScoreReductionDTO implements Serializable {
         this.storeId = storeId;
     }
 
-    public BigDecimal getScoreLimit() {
-        return scoreLimit;
-    }
-
-    public void setScoreLimit(BigDecimal scoreLimit) {
-        this.scoreLimit = scoreLimit;
-    }
-
     public Date getDeadline() {
         return deadline;
     }

+ 0 - 17
kmall-admin/src/main/java/com/kmall/admin/entity/mk/MkActivitiesScoreEntity.java

@@ -32,10 +32,6 @@ public class MkActivitiesScoreEntity implements Serializable {
      */
     private Integer storeId;
     /**
-     * 抵扣比例
-     */
-    private BigDecimal scoreLimit;
-    /**
      * 营销活动编号
      */
     private Long mkaId;
@@ -117,19 +113,6 @@ public class MkActivitiesScoreEntity implements Serializable {
         return storeId;
     }
     /**
-     * 设置:抵扣比例
-     */
-    public void setScoreLimit(BigDecimal scoreLimit) {
-        this.scoreLimit = scoreLimit;
-    }
-
-    /**
-     * 获取:抵扣比例
-     */
-    public BigDecimal getScoreLimit() {
-        return scoreLimit;
-    }
-    /**
      * 设置:营销活动编号
      */
     public void setMkaId(Long mkaId) {

+ 2 - 0
kmall-admin/src/main/java/com/kmall/admin/haikong/constant/Constants.java

@@ -23,6 +23,8 @@ public class Constants {
 
     public static final String HAIKONG_MEMBER_SCORE_LIMIT = "HAIKONG_MEMBER_SCORE_LIMIT";
 
+    public static final String HAIKONG_MEMBER_MAX_SCORE_RATIO = "HAIKONG_MEMBER_MAX_SCORE_RATIO";
+
     /* --------------------------------------------------系统常量----------------------------------------------- */
 
 

+ 53 - 21
kmall-admin/src/main/java/com/kmall/admin/service/impl/OrderServiceImpl.java

@@ -4614,30 +4614,46 @@ public class OrderServiceImpl implements OrderService {
 
         List<MkActivitiesScoreEntity> mkActivitiesScoreEntities = mkActivitiesScoreService.queryActivityInfoByMkaIdList(mkaIdList);
 
-        // 参与了积分抵扣的sku集合
-        List<String> scoreDeductionSkuList = mkActivitiesScoreEntities.stream()
+        if (CollectionUtils.isEmpty(mkActivitiesScoreEntities)) {
+            LOGGER.error("查询积分抵扣活动SKU为空!");
+            throw new ServiceException("查询积分抵扣活动SKU为空!请先导入积分抵扣活动信息!");
+        }
+
+        // 参与了积分抵扣的sku集合,过滤的是参与的sku,如果该list不为空,则默认其余的sku不参与积分抵扣
+        List<String> scoreDeductionAllowSkuList = mkActivitiesScoreEntities.stream()
                 .filter(m -> Constants.RejectStatus.ALLOW.getCode().equals(m.getReject()))
                 .map(MkActivitiesScoreEntity::getSku)
                 .collect(Collectors.toList());
-        // 转换成map,保存参与了积分抵扣活动的sku,积分计算比例的数据,key===>sku,value===>最大抵扣比例
-        Map<String, BigDecimal> skuScoreLimitMap = mkActivitiesScoreEntities.stream()
-                .filter(m -> Constants.RejectStatus.ALLOW.getCode().equals(m.getReject()))
-                .collect(Collectors.toMap(MkActivitiesScoreEntity::getSku, mkActivitiesScoreEntity -> {
-                    BigDecimal scoreLimit = mkActivitiesScoreEntity.getScoreLimit();
-                    if (Objects.isNull(scoreLimit)) {
-                        LOGGER.error("商品:【{}】,未设置最大抵扣比例!请设置后再计算优惠价!", mkActivitiesScoreEntity.getSku());
-                        throw new ServiceException(String.format("商品:【%s】,未设置最大抵扣比例!请设置后再计算优惠价!", mkActivitiesScoreEntity.getSku()));
-                    }
-                    return scoreLimit;
-                }, (k1, k2) -> k2));
+        // 不参与积分抵扣的sku集合,如果该list不为空,则默认其余的sku参与积分抵扣
+        List<String> scoreDeductionRejectSkuList = mkActivitiesScoreEntities.stream()
+                .filter(m -> Constants.RejectStatus.REJECT.getCode().equals(m.getReject()))
+                .map(MkActivitiesScoreEntity::getSku)
+                .collect(Collectors.toList());
+
+        if (!CollectionUtils.isEmpty(scoreDeductionAllowSkuList) && !CollectionUtils.isEmpty(scoreDeductionRejectSkuList)) {
+            LOGGER.error("积分抵扣表中既有参与又有不参与!与需求不符!");
+            throw new ServiceException("导入的积分抵扣活动商品设置有误!请确保导入的数据中只有参与或者不参与!");
+        }
+        if (CollectionUtils.isEmpty(scoreDeductionAllowSkuList) && CollectionUtils.isEmpty(scoreDeductionRejectSkuList)) {
+            LOGGER.error("积分抵扣表中无是否参与字段!");
+            throw new ServiceException("导入的积分抵扣活动商品设置有误!导入的活动商品数据中必须有参与或者不参与!");
+        }
+
         // 当前订单中参与了积分抵扣活动的sku总支付金额
         BigDecimal skuTotalPrice = BigDecimal.ZERO;
         for (GoodsDetailsDto goodsDetailsDto : goodsDetailsDtos) {
             String sku = goodsDetailsDto.getGoodsSn();
             if (!promotionSkuList.contains(sku)) {
-                if (scoreDeductionSkuList.contains(sku)) {
-                    BigDecimal skuActualPaymentAmount = goodsDetailsDto.getActualPaymentAmount();
-                    skuTotalPrice = skuTotalPrice.add(skuActualPaymentAmount);
+                if (CollectionUtils.isEmpty(scoreDeductionAllowSkuList) && !CollectionUtils.isEmpty(scoreDeductionRejectSkuList)) {
+                    if (!scoreDeductionRejectSkuList.contains(sku)) {
+                        BigDecimal skuActualPaymentAmount = goodsDetailsDto.getActualPaymentAmount();
+                        skuTotalPrice = skuTotalPrice.add(skuActualPaymentAmount);
+                    }
+                } else if (!CollectionUtils.isEmpty(scoreDeductionAllowSkuList) && CollectionUtils.isEmpty(scoreDeductionRejectSkuList)) {
+                    if (scoreDeductionAllowSkuList.contains(sku)) {
+                        BigDecimal skuActualPaymentAmount = goodsDetailsDto.getActualPaymentAmount();
+                        skuTotalPrice = skuTotalPrice.add(skuActualPaymentAmount);
+                    }
                 }
             }
         }
@@ -4659,8 +4675,19 @@ public class OrderServiceImpl implements OrderService {
                 int scoreInteger = score % scoreLimit == 0 ? score : score - (score % scoreLimit);
                 // 过滤掉参与过限时特价并且与积分抵扣互斥的sku,以及未参加积分抵扣活动的sku
                 goodsDetailsDtos = goodsDetailsDtos.stream().filter(goodsDetailsDto -> {
-                    if (!promotionSkuList.contains(goodsDetailsDto.getSku()) && scoreDeductionSkuList.contains(goodsDetailsDto.getSku())) {
-                        return true;
+                    String sku = goodsDetailsDto.getSku();
+                    if (!promotionSkuList.contains(sku)) {
+                        // 如果导入的商品都为不参与,则其余的商品都默认参与积分抵扣活动
+                        if (CollectionUtils.isEmpty(scoreDeductionAllowSkuList) && !CollectionUtils.isEmpty(scoreDeductionRejectSkuList)) {
+                            if (!scoreDeductionRejectSkuList.contains(sku)) {
+                                return true;
+                            }
+                        // 如果导入的商品都为参与,则默认其余商品不参与
+                        } else if (!CollectionUtils.isEmpty(scoreDeductionAllowSkuList) && CollectionUtils.isEmpty(scoreDeductionRejectSkuList)) {
+                            if (scoreDeductionAllowSkuList.contains(sku)) {
+                                return true;
+                            }
+                        }
                     }
                     // 满赠商品不参与积分分摊计算
                     return !Constants.ActivityTopicEnum.MZ.getTopicName().equals(goodsDetailsDto.getActivity());
@@ -4672,6 +4699,13 @@ public class OrderServiceImpl implements OrderService {
                 // 订单详情积分抵扣总金额
                 BigDecimal goodsDetailScoreDeductionPrice = BigDecimal.ZERO;
                 int size = goodsDetailsDtos.size();
+                // 系统设置的最大抵扣比例(最多能抵扣订单金额的比例),在系统管理的系统参数中设置,KEY为 HAIKONG_MEMBER_MAX_SCORE_RATIO
+                String scoreRatioStr = sysConfigDao.queryByKey(Constants.HAIKONG_MEMBER_MAX_SCORE_RATIO);
+                if (org.springframework.util.StringUtils.isEmpty(scoreRatioStr)) {
+                    LOGGER.error("计算优惠价格时,未设置订单的最大积分抵扣比例!");
+                    throw new ServiceException(String.format("请先设置订单的最大积分抵扣比例,设置方式:【系统管理】-->【系统参数】,参数名为:【%s】", Constants.HAIKONG_MEMBER_MAX_SCORE_RATIO));
+                }
+                BigDecimal scoreRatio = new BigDecimal(scoreRatioStr);
                 for (int i = 0; i < size; i++) {
                     GoodsDetailsDto goodsDetailsDto = goodsDetailsDtos.get(i);
                     // 抵扣积分分摊
@@ -4679,14 +4713,12 @@ public class OrderServiceImpl implements OrderService {
                     String activity = goodsDetailsDto.getActivity();
                     goodsDetailsDto.setActivity(org.springframework.util.StringUtils.isEmpty(activity) ? "积分抵扣" : activity.contains("积分抵扣") ? activity : activity + ",积分抵扣");
                     String sku = goodsDetailsDto.getGoodsSn();
-                    // 系统设置的最大抵扣比例(最多能抵扣订单金额的比例),导入积分抵扣活动时设置
-                    BigDecimal scoreLimitDecimal = skuScoreLimitMap.get(sku);
                     String prodBarcode = goodsDetailsDto.getProdBarcode();
                     // 此字段 = 零售价 - 其他活动优惠金额
                     BigDecimal actualPaymentAmount = goodsDetailsDto.getActualPaymentAmount();
                     // 当前商品最大支持抵扣的金额
                     BigDecimal currentSkuMaxDeductionPrice = actualPaymentAmount.multiply(BigDecimal.valueOf(goodsDetailsDto.getSellVolume()))
-                                                                                .multiply(scoreLimitDecimal);
+                                                                                .multiply(scoreRatio);
                     // 其他活动优惠金额
                     BigDecimal otherDiscountedPrice = Objects.isNull(goodsDetailsDto.getDiscountedPrice()) ? BigDecimal.ZERO : goodsDetailsDto.getDiscountedPrice();
 

+ 8 - 1
kmall-admin/src/main/java/com/kmall/admin/service/impl/mk/MkActivitiesScoreServiceImpl.java

@@ -17,6 +17,7 @@ import org.springframework.util.CollectionUtils;
 
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.stream.Collectors;
 
 
 /**
@@ -80,6 +81,13 @@ public class MkActivitiesScoreServiceImpl implements MkActivitiesScoreService {
         if (!CollectionUtils.isEmpty(scoreReductionDTOList)) {
             List<MkActivitiesScoreEntity> mkActivitiesScoreEntities = new ArrayList<>();
 
+            Set<String> rejectSet = scoreReductionDTOList.stream().map(ScoreReductionDTO::getReject).collect(Collectors.toSet());
+            if (CollectionUtils.isEmpty(rejectSet)) {
+                throw new RRException("是否参与字段不能为空!");
+            }
+            if (rejectSet.size() > 1) {
+                throw new RRException("请检查是否参与字段,必须为参与或者不参与!不能既有参与又有不参与!");
+            }
             scoreReductionDTOList.forEach(scoreReductionDTO -> {
                 Map<String, Object> valideDate = MapBeanUtil.fromObject(scoreReductionDTO);
                 // 校验excel传入的数据
@@ -87,7 +95,6 @@ public class MkActivitiesScoreServiceImpl implements MkActivitiesScoreService {
                 builder.put("storeId", "门店编号");
                 builder.put("sku", "商品SKU");
                 builder.put("prodBarcode", "商品条码");
-                builder.put("scoreLimit", "抵扣比例");
                 builder.put("reject", "是否参与");
                 builder.put("deadlineStr", "截止日期");
 

+ 2 - 3
kmall-admin/src/main/resources/XmlTemplate/ScoreReductionDTOList.xml

@@ -8,9 +8,8 @@
                 <mapping row="1" col="0">ScoreReductionDTO.storeId</mapping>
                 <mapping row="1" col="1">ScoreReductionDTO.prodBarcode</mapping>
                 <mapping row="1" col="2">ScoreReductionDTO.sku</mapping>
-                <mapping row="1" col="3">ScoreReductionDTO.scoreLimit</mapping>
-                <mapping row="1" col="4">ScoreReductionDTO.reject</mapping>
-                <mapping row="1" col="5">ScoreReductionDTO.deadlineStr</mapping>
+                <mapping row="1" col="3">ScoreReductionDTO.reject</mapping>
+                <mapping row="1" col="4">ScoreReductionDTO.deadlineStr</mapping>
             </section>
             <loopbreakcondition>
                 <rowcheck offset="0">

+ 0 - 10
kmall-admin/src/main/resources/mybatis/mapper/mk/MkActivitiesScoreDao.xml

@@ -8,7 +8,6 @@
         <result property="prodBarcode" column="prod_barcode"/>
         <result property="sku" column="sku"/>
         <result property="storeId" column="store_id"/>
-        <result property="scoreLimit" column="score_limit"/>
         <result property="mkaId" column="mka_id"/>
         <result property="deadline" column="deadline"/>
         <result property="reject" column="reject"/>
@@ -24,7 +23,6 @@
 			`prod_barcode`,
 			`sku`,
 			`store_id`,
-			`score_limit`,
 			`mka_id`,
 			`deadline`,
 			`reject`,
@@ -42,7 +40,6 @@
     		`prod_barcode`,
     		`sku`,
     		`store_id`,
-    		`score_limit`,
     		`mka_id`,
     		`deadline`,
     		`reject`,
@@ -83,7 +80,6 @@
     		`prod_barcode`,
     		`sku`,
     		`store_id`,
-    		`score_limit`,
     		`mka_id`,
     		`deadline`,
     		`reject`,
@@ -101,7 +97,6 @@
     		`prod_barcode`,
     		`sku`,
     		`store_id`,
-    		`score_limit`,
     		`mka_id`,
     		`deadline`,
     		`reject`,
@@ -128,7 +123,6 @@
 			`prod_barcode`,
 			`sku`,
 			`store_id`,
-			`score_limit`,
 			`mka_id`,
 			`deadline`,
 			`reject`,
@@ -140,7 +134,6 @@
 			#{prodBarcode},
 			#{sku},
 			#{storeId},
-			#{scoreLimit},
 			#{mkaId},
 			#{deadline},
 			#{reject},
@@ -155,7 +148,6 @@
 			`prod_barcode`,
 			`sku`,
 			`store_id`,
-			`score_limit`,
 			`mka_id`,
 			`deadline`,
 			`reject`,
@@ -169,7 +161,6 @@
 				#{item.prodBarcode},
 				#{item.sku},
 				#{item.storeId},
-				#{item.scoreLimit},
 				#{item.mkaId},
 				#{item.deadline},
 				#{item.reject},
@@ -187,7 +178,6 @@
 			<if test="prodBarcode != null">`prod_barcode` = #{prodBarcode}, </if>
 			<if test="sku != null">`sku` = #{sku}, </if>
 			<if test="storeId != null">`store_id` = #{storeId}, </if>
-			<if test="scoreLimit != null">`score_limit` = #{scoreLimit}, </if>
 			<if test="mkaId != null">`mka_id` = #{mkaId}, </if>
 			<if test="deadline != null">`deadline` = #{deadline}, </if>
 			<if test="reject != null">`reject` = #{reject}, </if>

BIN
kmall-admin/src/main/webapp/statics/file/activities_score_yyyy_mm_dd_v1.0.0.xlsx