Procházet zdrojové kódy

Merge remote-tracking branch 'upsteam/master'

# Conflicts:
#	kmall-admin/src/main/java/com/kmall/admin/service/impl/OrderServiceImpl.java
zhh před 3 roky
rodič
revize
8423ec4d98

+ 3 - 0
kmall-admin/src/main/java/com/kmall/admin/dao/mk/MkActivitiesScoreDao.java

@@ -6,6 +6,7 @@ import com.kmall.manager.dao.BaseDao;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.Date;
+import java.util.List;
 
 /**
  * 营销方式-积分抵扣Dao
@@ -20,4 +21,6 @@ public interface MkActivitiesScoreDao extends BaseDao<MkActivitiesScoreEntity> {
                                                                             @Param("sku") String sku,
                                                                             @Param("storeId") Integer storeId,
                                                                             @Param("nowTime") Date nowTime);
+
+    List<MkActivitiesScoreEntity> queryDetailByTime(@Param("date") Date date);
 }

+ 13 - 0
kmall-admin/src/main/java/com/kmall/admin/dto/GoodsDetailsDto.java

@@ -84,6 +84,11 @@ public class GoodsDetailsDto {
      */
     private Integer exitRegionNumber;
 
+    /**
+     * 当前sku,计算出的抵扣积分数量
+     */
+    private Integer deductionScore;
+
     public BigDecimal getRmarketPrice() {
         return rmarketPrice;
     }
@@ -307,4 +312,12 @@ public class GoodsDetailsDto {
     public void setId(Integer id) {
         this.id = id;
     }
+
+    public Integer getDeductionScore() {
+        return deductionScore;
+    }
+
+    public void setDeductionScore(Integer deductionScore) {
+        this.deductionScore = deductionScore;
+    }
 }

+ 5 - 0
kmall-admin/src/main/java/com/kmall/admin/entity/OrderGoodsEntity.java

@@ -76,6 +76,11 @@ public class OrderGoodsEntity implements Serializable {
 
 	private BigDecimal taxPrice;
 
+	/**
+	 * 抵扣的积分数量
+	 */
+	private Integer deductionScore;
+
 	public String getPlu() {
 		return plu;
 	}

+ 86 - 36
kmall-admin/src/main/java/com/kmall/admin/service/impl/OrderServiceImpl.java

@@ -26,6 +26,7 @@ import com.kmall.admin.entity.haikong.HaiKongMemberOrderSyncResendEntity;
 import com.kmall.admin.entity.haikong.HaiKongMemberScoreChangeRecordEntity;
 import com.kmall.admin.entity.haikong.IntegralGoBackEntity;
 import com.kmall.admin.entity.mk.MkActivitiesEntity;
+import com.kmall.admin.entity.mk.MkActivitiesScoreEntity;
 import com.kmall.admin.entity.mk.store.MkStorePromOrderRealEntity;
 import com.kmall.admin.entity.record.NewRetailOrderRestoreStockRecordEntity;
 import com.kmall.admin.entity.vip.Mall2MemberConsumptionRecordsEntity;
@@ -47,6 +48,7 @@ import com.kmall.admin.haikong.utils.Response;
 import com.kmall.admin.service.*;
 import com.kmall.admin.service.haikong.HaiKongMemberOrderSyncResendService;
 import com.kmall.admin.service.haikong.HaiKongMemberScoreChangeRecordService;
+import com.kmall.admin.service.mk.MkActivitiesScoreService;
 import com.kmall.admin.service.mk.MkActivitiesService;
 import com.kmall.admin.service.mk.store.MkStoreCampMinusService;
 import com.kmall.admin.service.mk.store.MkStoreTicketDiscountService;
@@ -278,6 +280,9 @@ public class OrderServiceImpl implements OrderService {
     @Autowired
     private AddressDao addressDao;
 
+    @Autowired
+    private MkActivitiesScoreService mkActivitiesScoreService;
+
     /**
      * 微信海关申报
      */
@@ -2522,6 +2527,7 @@ public class OrderServiceImpl implements OrderService {
                         LOGGER.error("sku:【{}】库存不足,门店可用库存:【{}】,仓库可用库存:【{}】,购买数量:【{}】", sku, stockNum, warehouseStock, sellVolume);
                         throw new ServiceException(String.format("sku:【%s】库存不足,门店可用库存:【%s】,仓库可用库存:【%s】,购买数量:【%s】", sku, stockNum, warehouseStock, sellVolume));
                     }
+                    // TODO 库存变化记录新增字段:订单号、门店编号
                     // 门店库存变化记录
                     StoreMngChangeEntity storeMngChangeEntity = new StoreMngChangeEntity();
                     storeMngChangeEntity.setChangeType(Dict.changeType.item_1.getItem());
@@ -2665,7 +2671,7 @@ public class OrderServiceImpl implements OrderService {
             //插入订单信息和订单商品
             orderDao.saveOrderVo(order);
 
-            // TODO 订单流转表
+            // 订单流转表
             OrderProcessRecordEntity processRecordEntity = new OrderProcessRecordEntity();
             processRecordEntity.setOrderSn(order.getOrder_sn());
             processRecordEntity.setUserId(Integer.valueOf(userEntity.getId() + ""));
@@ -4162,6 +4168,7 @@ public class OrderServiceImpl implements OrderService {
         AtomicBoolean activityFlag = new AtomicBoolean(true);
         // 限时特价活动标识
         AtomicBoolean promotionActivityFlag = new AtomicBoolean(false);
+        // 与积分抵扣互斥的sku
         List<String> promotionSkuList = new ArrayList<>();
         // 判断活动类型并排序,再确定购物栏中商品是否满足活动条件
         mkActivitiesEntityList.stream().sorted().forEach(mkActivitiesEntity -> {
@@ -4473,7 +4480,7 @@ public class OrderServiceImpl implements OrderService {
      * @param goodsDetailsDtos  订单商品详情
      * @param calculateOrderDiscountPriceResponseVO 响应数据
      * @param promotionActivityFlag 是否参与了积分抵扣活动
-     * @param promotionSkuList  参与了积分抵扣活动的sku集合
+     * @param promotionSkuList  参与了限时特价活动并且与积分抵扣互斥的sku集合
      * @return                  积分抵扣后的订单总金额
      */
     private BigDecimal calculatePreferentialPrice(BigDecimal orderTotalPrice, Integer score, String storeId, String memberCode, CalculateOrderDiscountPriceResponseVO calculateOrderDiscountPriceResponseVO, List<GoodsDetailsDto> goodsDetailsDtos, AtomicBoolean promotionActivityFlag, List<String> promotionSkuList) {
@@ -4482,10 +4489,29 @@ public class OrderServiceImpl implements OrderService {
         if (Objects.nonNull(score) && score > 0) {
             isCalculateScorePrice.set(true);
         }
+        // 参与了积分抵扣的sku集合
+        Date date = new Date();
+        List<MkActivitiesScoreEntity> mkActivitiesScoreEntities = mkActivitiesScoreService.queryDetailByTime(date);
+        if (CollectionUtils.isEmpty(mkActivitiesScoreEntities)) {
+            LOGGER.error("当前时间【{}】无积分抵扣活动!", date);
+            return orderTotalPrice;
+        }
+        List<String> scoreDeductionSkuList = mkActivitiesScoreEntities.stream().map(MkActivitiesScoreEntity::getSku).collect(Collectors.toList());
+        // 转换成map,保存参与了积分抵扣活动的sku,积分计算比例的数据,key===>sku,value===>比例
+        Map<String, BigDecimal> skuScoreLimitMap = mkActivitiesScoreEntities.stream().collect(Collectors.toMap(MkActivitiesScoreEntity::getSku, MkActivitiesScoreEntity::getScoreLimit, (k1, k2) -> k2));
+        // 当前订单中参与了积分抵扣活动的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);
+                }
+            }
+        }
         // 2. 计算积分抵扣后的总价格
         if (isCalculateScorePrice.get()) {
-            // 3-1. 计算总价的50%,百分比可以进行设置,算出整数(向下取整)
-            BigDecimal halfPrice = orderTotalPrice.multiply(new BigDecimal("0.5")).setScale(0, BigDecimal.ROUND_FLOOR);
             Integer scoreLimit = haiKongProperties.getMemberScoreLimit();
             if (score < scoreLimit) {
                 LOGGER.warn("用户【{}】的积分数量为:{},最低需要30积分才能抵扣!", memberCode, score);
@@ -4498,41 +4524,65 @@ public class OrderServiceImpl implements OrderService {
                 // 3-2. 计算出积分能抵扣的价格
                 int scoreMayDeductionPrice = (int) (score / scoreLimit);
                 BigDecimal scoreMayDeductionPriceDecimal = new BigDecimal(scoreMayDeductionPrice);
-                // 3-3. 计算积分抵扣后的价格
-                if (halfPrice.compareTo(scoreMayDeductionPriceDecimal) <= 0) {
-                    // 积分能抵扣的金额大于订单总额的50%,按50%抵扣
-                    scoreMayDeductionPriceDecimal = halfPrice;
-                }
-                // 参与了积分抵扣活动,不互斥的情况下
-                if (promotionActivityFlag.get() && !CollectionUtils.isEmpty(promotionSkuList)) {
-                    BigDecimal shareScore = BigDecimal.ZERO;
-                    BigDecimal scoreIntegerDecimal = BigDecimal.valueOf(scoreInteger);
-                    BigDecimal scoreLimitDecimal = BigDecimal.valueOf(scoreLimit);
-                    BigDecimal goodsDetailScoreDeductionPrice = BigDecimal.ZERO;
-                    for (int i = 0; i < goodsDetailsDtos.size(); i++) {
-                        GoodsDetailsDto goodsDetailsDto = goodsDetailsDtos.get(i);
-                        // 抵扣积分分摊
-                        int index = goodsDetailsDtos.size() - 1;
-                        if (promotionSkuList.contains(goodsDetailsDto.getSku()) && i < index) {
-                            // 计算抵扣
-                            // 商品总价
-                            BigDecimal actualPaymentAmount = goodsDetailsDto.getActualPaymentAmount();
-                            BigDecimal scoreIntegerHalfDecimal = BigDecimal.valueOf(scoreIntegerHalf);
-                            // 分摊积分
-                            shareScore = shareScore.add(actualPaymentAmount.divide(scoreIntegerDecimal.multiply(scoreIntegerHalfDecimal), 2, BigDecimal.ROUND_HALF_UP));
-                            // 保留两位小数,四舍五入
-                            BigDecimal discountedPrice = shareScore.divide(scoreLimitDecimal, 2, BigDecimal.ROUND_HALF_UP);
-                            goodsDetailScoreDeductionPrice = goodsDetailScoreDeductionPrice.add(discountedPrice);
-                            goodsDetailsDto.setDiscountedPrice(discountedPrice);
-                        }
-                        if (i == index) {
-                            BigDecimal discountedPrice = scoreIntegerDecimal.subtract(shareScore).divide(scoreLimitDecimal, 2, BigDecimal.ROUND_HALF_UP);
-                            goodsDetailScoreDeductionPrice = goodsDetailScoreDeductionPrice.add(discountedPrice);
-                            goodsDetailsDto.setDiscountedPrice(discountedPrice);
+                // 过滤掉参与过限时特价并且与积分抵扣互斥的sku
+                goodsDetailsDtos = goodsDetailsDtos.stream().filter(goodsDetailsDto -> !promotionSkuList.contains(goodsDetailsDto.getSku())).collect(Collectors.toList());
+                // 总分摊积分
+                BigDecimal shareScore = BigDecimal.ZERO;
+                BigDecimal scoreIntegerDecimal = BigDecimal.valueOf(scoreInteger);
+                BigDecimal goodsDetailScoreDeductionPrice = BigDecimal.ZERO;
+                int size = goodsDetailsDtos.size();
+                for (int i = 0; i < size; i++) {
+                    GoodsDetailsDto goodsDetailsDto = goodsDetailsDtos.get(i);
+                    // 抵扣积分分摊
+                    int index = size - 1;
+                    String sku = goodsDetailsDto.getGoodsSn();
+                    BigDecimal scoreLimitDecimal = skuScoreLimitMap.get(sku);
+                    String prodBarcode = goodsDetailsDto.getProdBarcode();
+                    BigDecimal actualPaymentAmount = goodsDetailsDto.getActualPaymentAmount();
+                    // 计算抵扣,当商品不是最后一个商品
+                    if (i < index) {
+                        // 商品总价
+                        // 分摊积分
+                        BigDecimal shareScoreItem = actualPaymentAmount.divide(scoreIntegerDecimal.multiply(skuTotalPrice), 2, BigDecimal.ROUND_HALF_UP);
+                        shareScore = shareScore.add(shareScoreItem);
+                        // 保留两位小数,四舍五入
+                        BigDecimal discountedPrice = shareScore.divide(scoreLimitDecimal, 2, BigDecimal.ROUND_HALF_UP);
+                        goodsDetailScoreDeductionPrice = goodsDetailScoreDeductionPrice.add(discountedPrice);
+                        goodsDetailsDto.setDiscountedPrice(discountedPrice);
+                        goodsDetailsDto.setDeductionScore(shareScoreItem.intValue());
+                        goodsDetailsDto.setActualPaymentAmount(actualPaymentAmount.subtract(discountedPrice));
+                    }
+                    // 订单商品详情最后一个商品并且详情不止一个商品
+                    if (i == index && size > 1) {// 商品总价
+                        // 分摊积分
+                        BigDecimal shareScoreItem = scoreIntegerDecimal.subtract(shareScore);
+                        BigDecimal discountedPrice = shareScoreItem.divide(scoreLimitDecimal, 2, BigDecimal.ROUND_HALF_UP);
+                        goodsDetailScoreDeductionPrice = goodsDetailScoreDeductionPrice.add(discountedPrice);
+                        goodsDetailsDto.setDiscountedPrice(discountedPrice);
+                        goodsDetailsDto.setDeductionScore(shareScoreItem.intValue());
+                        goodsDetailsDto.setActualPaymentAmount(actualPaymentAmount.subtract(discountedPrice));
+                    }
+                    // 订单商品详情只有一个商品的情况下
+                    if (size == 1) {
+                        BigDecimal shareScoreItem = scoreIntegerDecimal.subtract(shareScore);
+                        // 3-1. 计算总价的50%,百分比可以进行设置,算出整数(向下取整)
+                        BigDecimal halfPrice = orderTotalPrice.multiply(scoreLimitDecimal).setScale(0, BigDecimal.ROUND_FLOOR);
+                        // 3-3. 计算积分抵扣后的价格
+                        BigDecimal discountedPrice = scoreMayDeductionPriceDecimal;
+                        if (halfPrice.compareTo(discountedPrice) <= 0) {
+                            // 积分能抵扣的金额大于订单总额的50%,按50%抵扣
+                            discountedPrice = halfPrice;
                         }
+                        goodsDetailScoreDeductionPrice = goodsDetailScoreDeductionPrice.add(discountedPrice);
+                        goodsDetailsDto.setDiscountedPrice(discountedPrice);
+                        goodsDetailsDto.setDeductionScore(shareScoreItem.intValue());
+                        goodsDetailsDto.setActualPaymentAmount(actualPaymentAmount.subtract(discountedPrice));
                     }
-                    scoreMayDeductionPriceDecimal = goodsDetailScoreDeductionPrice;
+                    LOGGER.info("--------------------------------------------------------");
+                    LOGGER.info("【计算优惠价】sku:【{}】,条码:【{}】积分抵扣{}元,抵扣积分{}分", sku, prodBarcode, goodsDetailsDto.getDiscountedPrice(), shareScore.intValue());
+                    LOGGER.info("--------------------------------------------------------");
                 }
+                scoreMayDeductionPriceDecimal = goodsDetailScoreDeductionPrice;
 
                 orderTotalPrice = orderTotalPrice.subtract(scoreMayDeductionPriceDecimal);
                 int afterScore = score - scoreIntegerHalf;

+ 11 - 0
kmall-admin/src/main/java/com/kmall/admin/service/impl/mk/MkActivitiesScoreServiceImpl.java

@@ -148,4 +148,15 @@ public class MkActivitiesScoreServiceImpl implements MkActivitiesScoreService {
     public void saveBatch(List<MkActivitiesScoreEntity> mkActivitiesScoreEntities) {
         mkActivitiesScoreDao.saveBatch(mkActivitiesScoreEntities);
     }
+
+    /**
+     * 查询当前时间的参与积分抵扣的sku
+     *
+     * @param date 当前时间
+     * @return sku
+     */
+    @Override
+    public List<MkActivitiesScoreEntity> queryDetailByTime(Date date) {
+        return mkActivitiesScoreDao.queryDetailByTime(date);
+    }
 }

+ 7 - 0
kmall-admin/src/main/java/com/kmall/admin/service/mk/MkActivitiesScoreService.java

@@ -96,4 +96,11 @@ public interface MkActivitiesScoreService {
      * @param mkActivitiesScoreEntities 新增数据
      */
     void saveBatch(List<MkActivitiesScoreEntity> mkActivitiesScoreEntities);
+
+    /**
+     * 查询当前时间的参与积分抵扣的sku
+     * @param date  当前时间
+     * @return      sku
+     */
+    List<MkActivitiesScoreEntity> queryDetailByTime(Date date);
 }

+ 13 - 2
kmall-admin/src/main/resources/mybatis/mapper/OrderGoodsDao.xml

@@ -20,6 +20,7 @@
         <result property="goodsSpecificationIds" column="goods_specification_ids"/>
         <result property="listPicUrl" column="list_pic_url"/>
         <result property="sku" column="sku"/>
+        <result property="deductionScore" column="deduction_score"/>
     </resultMap>
 
     <select id="queryObject" resultType="com.kmall.admin.entity.OrderGoodsEntity">
@@ -66,7 +67,8 @@
 			`goods_specification_name_value`,
 			`is_real`,
 			`goods_specification_ids`,
-			`list_pic_url`
+			`list_pic_url`,
+			`deduction_score`
 		)
 		values
 		(
@@ -81,7 +83,8 @@
 			#{goodsSpecificationNameValue},
 			#{isReal},
 			#{goodsSpecificationIds},
-			#{listPicUrl}
+			#{listPicUrl},
+			#{deductionScore}
 		)
 	</insert>
 
@@ -105,6 +108,9 @@
         is_dist_sell_scan,
         tax_price,
         store_topic_id,
+        <if test="deductionScore != null">
+            deduction_score,
+        </if>
         <if test="goodsRate != null" >
             goods_rate,
         </if>
@@ -153,6 +159,9 @@
         0,
         #{taxPrice},
         #{storeTopicId},
+        <if test="deductionScore != null">
+            #{deductionScore},
+        </if>
         <if test="goodsRate != null" >
             #{goodsRate},
         </if>
@@ -206,6 +215,7 @@
             `goods_rate`,
             `settle_price`,
             `sku`,
+            `deduction_score`,
             `order_biz_type`,
             `activity`,
             `creater_sn`,
@@ -236,6 +246,7 @@
                 #{item.goodsRate},
                 #{item.settlePrice},
                 #{item.sku,jdbcType=VARCHAR},
+                #{item.deductionScore},
                 #{item.orderBizType,jdbcType=VARCHAR},
                 #{item.activity},
                 #{item.createrSn,jdbcType=VARCHAR},

+ 19 - 1
kmall-admin/src/main/resources/mybatis/mapper/mk/MkActivitiesScoreDao.xml

@@ -95,7 +95,25 @@
 		where prod_barcode = #{prodBarcode} and sku = #{sku} and store_id = #{storeId} and (deadline &gt; #{nowTime})
 	</select>
 
-	<insert id="save" parameterType="com.kmall.admin.entity.mk.MkActivitiesScoreEntity" useGeneratedKeys="true" keyProperty="id">
+    <select id="queryDetailByTime" resultType="com.kmall.admin.entity.mk.MkActivitiesScoreEntity">
+		select
+    		`id`,
+    		`prod_barcode`,
+    		`sku`,
+    		`store_id`,
+    		`score_limit`,
+    		`mka_id`,
+    		`deadline`,
+    		`reject`,
+    		`create_time`,
+    		`creater_sn`,
+    		`moder_sn`,
+    		`update_time`
+		from mk_activities_score
+		where deadline &gt; #{date}
+	</select>
+
+    <insert id="save" parameterType="com.kmall.admin.entity.mk.MkActivitiesScoreEntity" useGeneratedKeys="true" keyProperty="id">
 		insert into mk_activities_score(
 			`prod_barcode`,
 			`sku`,

+ 1 - 1
kmall-admin/src/main/webapp/WEB-INF/page/mk/mkactivitiesscore.html

@@ -38,7 +38,7 @@
                 <i-button type="warning" @click="reloadMkactivities" v-show="!isMkactivitiesShow">返回营销方式页</i-button>
             </div>
         </Row>
-	    <ta2ble id="jqGrid"></ta2ble>
+	    <table id="jqGrid"></table>
 	    <div id="jqGridPager"></div>
     </div>
 

+ 1 - 0
kmall-admin/src/main/webapp/js/sale/sale.js

@@ -2048,6 +2048,7 @@ calculateOrderPrice = function() {
                 console.log("替换后数据===>" + JSON.stringify(vm.goodsList));
 
                 $("#calculateOrderPriceDialog").modal('hide');
+                alert("计算完成");
             } else if (r.code === 500) {
                 alert(r.msg);
             } else {

+ 13 - 0
kmall-api/src/main/java/com/kmall/api/entity/OrderGoodsVo.java

@@ -74,6 +74,11 @@ public class OrderGoodsVo implements Serializable {
 
     private BigDecimal taxPrice;
 
+    /**
+     * 计算出的积分抵扣数量
+     */
+    private Integer deductionScore;
+
 
 
     public BigDecimal getDiscountedPrice() {
@@ -316,4 +321,12 @@ public class OrderGoodsVo implements Serializable {
     public void setTaxPrice(BigDecimal taxPrice) {
         this.taxPrice = taxPrice;
     }
+
+    public Integer getDeductionScore() {
+        return deductionScore;
+    }
+
+    public void setDeductionScore(Integer deductionScore) {
+        this.deductionScore = deductionScore;
+    }
 }