|
@@ -26,6 +26,7 @@ import com.kmall.admin.entity.haikong.HaiKongMemberOrderSyncResendEntity;
|
|
import com.kmall.admin.entity.haikong.HaiKongMemberScoreChangeRecordEntity;
|
|
import com.kmall.admin.entity.haikong.HaiKongMemberScoreChangeRecordEntity;
|
|
import com.kmall.admin.entity.haikong.IntegralGoBackEntity;
|
|
import com.kmall.admin.entity.haikong.IntegralGoBackEntity;
|
|
import com.kmall.admin.entity.mk.MkActivitiesEntity;
|
|
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.mk.store.MkStorePromOrderRealEntity;
|
|
import com.kmall.admin.entity.record.NewRetailOrderRestoreStockRecordEntity;
|
|
import com.kmall.admin.entity.record.NewRetailOrderRestoreStockRecordEntity;
|
|
import com.kmall.admin.entity.vip.Mall2MemberConsumptionRecordsEntity;
|
|
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.*;
|
|
import com.kmall.admin.service.haikong.HaiKongMemberOrderSyncResendService;
|
|
import com.kmall.admin.service.haikong.HaiKongMemberOrderSyncResendService;
|
|
import com.kmall.admin.service.haikong.HaiKongMemberScoreChangeRecordService;
|
|
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.MkActivitiesService;
|
|
import com.kmall.admin.service.mk.store.MkStoreCampMinusService;
|
|
import com.kmall.admin.service.mk.store.MkStoreCampMinusService;
|
|
import com.kmall.admin.service.mk.store.MkStoreTicketDiscountService;
|
|
import com.kmall.admin.service.mk.store.MkStoreTicketDiscountService;
|
|
@@ -278,6 +280,9 @@ public class OrderServiceImpl implements OrderService {
|
|
@Autowired
|
|
@Autowired
|
|
private AddressDao addressDao;
|
|
private AddressDao addressDao;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private MkActivitiesScoreService mkActivitiesScoreService;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 微信海关申报
|
|
* 微信海关申报
|
|
*/
|
|
*/
|
|
@@ -2522,6 +2527,7 @@ public class OrderServiceImpl implements OrderService {
|
|
LOGGER.error("sku:【{}】库存不足,门店可用库存:【{}】,仓库可用库存:【{}】,购买数量:【{}】", sku, stockNum, warehouseStock, sellVolume);
|
|
LOGGER.error("sku:【{}】库存不足,门店可用库存:【{}】,仓库可用库存:【{}】,购买数量:【{}】", sku, stockNum, warehouseStock, sellVolume);
|
|
throw new ServiceException(String.format("sku:【%s】库存不足,门店可用库存:【%s】,仓库可用库存:【%s】,购买数量:【%s】", sku, stockNum, warehouseStock, sellVolume));
|
|
throw new ServiceException(String.format("sku:【%s】库存不足,门店可用库存:【%s】,仓库可用库存:【%s】,购买数量:【%s】", sku, stockNum, warehouseStock, sellVolume));
|
|
}
|
|
}
|
|
|
|
+ // TODO 库存变化记录新增字段:订单号、门店编号
|
|
// 门店库存变化记录
|
|
// 门店库存变化记录
|
|
StoreMngChangeEntity storeMngChangeEntity = new StoreMngChangeEntity();
|
|
StoreMngChangeEntity storeMngChangeEntity = new StoreMngChangeEntity();
|
|
storeMngChangeEntity.setChangeType(Dict.changeType.item_1.getItem());
|
|
storeMngChangeEntity.setChangeType(Dict.changeType.item_1.getItem());
|
|
@@ -2665,7 +2671,7 @@ public class OrderServiceImpl implements OrderService {
|
|
//插入订单信息和订单商品
|
|
//插入订单信息和订单商品
|
|
orderDao.saveOrderVo(order);
|
|
orderDao.saveOrderVo(order);
|
|
|
|
|
|
- // TODO 订单流转表
|
|
|
|
|
|
+ // 订单流转表
|
|
OrderProcessRecordEntity processRecordEntity = new OrderProcessRecordEntity();
|
|
OrderProcessRecordEntity processRecordEntity = new OrderProcessRecordEntity();
|
|
processRecordEntity.setOrderSn(order.getOrder_sn());
|
|
processRecordEntity.setOrderSn(order.getOrder_sn());
|
|
processRecordEntity.setUserId(Integer.valueOf(userEntity.getId() + ""));
|
|
processRecordEntity.setUserId(Integer.valueOf(userEntity.getId() + ""));
|
|
@@ -4162,6 +4168,7 @@ public class OrderServiceImpl implements OrderService {
|
|
AtomicBoolean activityFlag = new AtomicBoolean(true);
|
|
AtomicBoolean activityFlag = new AtomicBoolean(true);
|
|
// 限时特价活动标识
|
|
// 限时特价活动标识
|
|
AtomicBoolean promotionActivityFlag = new AtomicBoolean(false);
|
|
AtomicBoolean promotionActivityFlag = new AtomicBoolean(false);
|
|
|
|
+ // 与积分抵扣互斥的sku
|
|
List<String> promotionSkuList = new ArrayList<>();
|
|
List<String> promotionSkuList = new ArrayList<>();
|
|
// 判断活动类型并排序,再确定购物栏中商品是否满足活动条件
|
|
// 判断活动类型并排序,再确定购物栏中商品是否满足活动条件
|
|
mkActivitiesEntityList.stream().sorted().forEach(mkActivitiesEntity -> {
|
|
mkActivitiesEntityList.stream().sorted().forEach(mkActivitiesEntity -> {
|
|
@@ -4473,7 +4480,7 @@ public class OrderServiceImpl implements OrderService {
|
|
* @param goodsDetailsDtos 订单商品详情
|
|
* @param goodsDetailsDtos 订单商品详情
|
|
* @param calculateOrderDiscountPriceResponseVO 响应数据
|
|
* @param calculateOrderDiscountPriceResponseVO 响应数据
|
|
* @param promotionActivityFlag 是否参与了积分抵扣活动
|
|
* @param promotionActivityFlag 是否参与了积分抵扣活动
|
|
- * @param promotionSkuList 参与了积分抵扣活动的sku集合
|
|
|
|
|
|
+ * @param promotionSkuList 参与了限时特价活动并且与积分抵扣互斥的sku集合
|
|
* @return 积分抵扣后的订单总金额
|
|
* @return 积分抵扣后的订单总金额
|
|
*/
|
|
*/
|
|
private BigDecimal calculatePreferentialPrice(BigDecimal orderTotalPrice, Integer score, String storeId, String memberCode, CalculateOrderDiscountPriceResponseVO calculateOrderDiscountPriceResponseVO, List<GoodsDetailsDto> goodsDetailsDtos, AtomicBoolean promotionActivityFlag, List<String> promotionSkuList) {
|
|
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) {
|
|
if (Objects.nonNull(score) && score > 0) {
|
|
isCalculateScorePrice.set(true);
|
|
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. 计算积分抵扣后的总价格
|
|
// 2. 计算积分抵扣后的总价格
|
|
if (isCalculateScorePrice.get()) {
|
|
if (isCalculateScorePrice.get()) {
|
|
- // 3-1. 计算总价的50%,百分比可以进行设置,算出整数(向下取整)
|
|
|
|
- BigDecimal halfPrice = orderTotalPrice.multiply(new BigDecimal("0.5")).setScale(0, BigDecimal.ROUND_FLOOR);
|
|
|
|
Integer scoreLimit = haiKongProperties.getMemberScoreLimit();
|
|
Integer scoreLimit = haiKongProperties.getMemberScoreLimit();
|
|
if (score < scoreLimit) {
|
|
if (score < scoreLimit) {
|
|
LOGGER.warn("用户【{}】的积分数量为:{},最低需要30积分才能抵扣!", memberCode, score);
|
|
LOGGER.warn("用户【{}】的积分数量为:{},最低需要30积分才能抵扣!", memberCode, score);
|
|
@@ -4498,41 +4524,65 @@ public class OrderServiceImpl implements OrderService {
|
|
// 3-2. 计算出积分能抵扣的价格
|
|
// 3-2. 计算出积分能抵扣的价格
|
|
int scoreMayDeductionPrice = (int) (score / scoreLimit);
|
|
int scoreMayDeductionPrice = (int) (score / scoreLimit);
|
|
BigDecimal scoreMayDeductionPriceDecimal = new BigDecimal(scoreMayDeductionPrice);
|
|
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);
|
|
orderTotalPrice = orderTotalPrice.subtract(scoreMayDeductionPriceDecimal);
|
|
int afterScore = score - scoreIntegerHalf;
|
|
int afterScore = score - scoreIntegerHalf;
|