|
@@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
import com.google.common.collect.ImmutableBiMap;
|
|
import com.google.common.collect.ImmutableBiMap;
|
|
-import com.google.common.collect.Lists;
|
|
|
|
import com.google.common.collect.Maps;
|
|
import com.google.common.collect.Maps;
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.internal.LinkedTreeMap;
|
|
import com.google.gson.internal.LinkedTreeMap;
|
|
@@ -21,7 +20,6 @@ import com.kmall.admin.dao.vip.Mall2MemberPointsDao;
|
|
import com.kmall.admin.dao.vip.Mall2PointsRulesDao;
|
|
import com.kmall.admin.dao.vip.Mall2PointsRulesDao;
|
|
import com.kmall.admin.dto.*;
|
|
import com.kmall.admin.dto.*;
|
|
import com.kmall.admin.entity.*;
|
|
import com.kmall.admin.entity.*;
|
|
-import com.kmall.admin.entity.kmall2eccs.KtoEccsEntity;
|
|
|
|
import com.kmall.admin.entity.mk.MkActivitiesEntity;
|
|
import com.kmall.admin.entity.mk.MkActivitiesEntity;
|
|
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;
|
|
@@ -33,7 +31,8 @@ import com.kmall.admin.fromcomm.entity.SysUserEntity;
|
|
import com.kmall.admin.haikong.constant.Constants;
|
|
import com.kmall.admin.haikong.constant.Constants;
|
|
import com.kmall.admin.haikong.dto.WareQueryStockResponseDTO;
|
|
import com.kmall.admin.haikong.dto.WareQueryStockResponseDTO;
|
|
import com.kmall.admin.haikong.utils.ListUtils;
|
|
import com.kmall.admin.haikong.utils.ListUtils;
|
|
-import com.kmall.admin.haikong.vo.QueryGoodsVo;
|
|
|
|
|
|
+import com.kmall.admin.haikong.vo.CalculateOrderDiscountPriceResponseVO;
|
|
|
|
+import com.kmall.admin.haikong.vo.QueryGoodsVO;
|
|
import com.kmall.admin.haikong.client.HaiKongMemberTemplate;
|
|
import com.kmall.admin.haikong.client.HaiKongMemberTemplate;
|
|
import com.kmall.admin.haikong.client.HaiKongWarehouseTemplate;
|
|
import com.kmall.admin.haikong.client.HaiKongWarehouseTemplate;
|
|
import com.kmall.admin.haikong.client.VmcShopTemplate;
|
|
import com.kmall.admin.haikong.client.VmcShopTemplate;
|
|
@@ -53,7 +52,7 @@ import com.kmall.admin.utils.data.response.ResponseMessageData;
|
|
import com.kmall.admin.utils.jackson.JacksonUtil;
|
|
import com.kmall.admin.utils.jackson.JacksonUtil;
|
|
import com.kmall.admin.utils.oms.OmsSign;
|
|
import com.kmall.admin.utils.oms.OmsSign;
|
|
import com.kmall.admin.utils.pdf.BarcodeUtil;
|
|
import com.kmall.admin.utils.pdf.BarcodeUtil;
|
|
-import com.kmall.admin.vo.CalculateOrderDiscountPriceVo;
|
|
|
|
|
|
+import com.kmall.admin.haikong.vo.CalculateOrderDiscountPriceVO;
|
|
import com.kmall.admin.websocket.WebSocketServer;
|
|
import com.kmall.admin.websocket.WebSocketServer;
|
|
import com.kmall.api.entity.OrderGoodsRestoreVo;
|
|
import com.kmall.api.entity.OrderGoodsRestoreVo;
|
|
import com.kmall.api.entity.OrderGoodsVo;
|
|
import com.kmall.api.entity.OrderGoodsVo;
|
|
@@ -82,9 +81,7 @@ import com.kmall.manager.manager.print.ticket.TicketPrintUtil;
|
|
import com.kmall.manager.manager.redis.JedisUtil;
|
|
import com.kmall.manager.manager.redis.JedisUtil;
|
|
import com.kmall.manager.manager.wechat.WechatUtil;
|
|
import com.kmall.manager.manager.wechat.WechatUtil;
|
|
import com.kmall.manager.manager.wechat.wxglobal.dto.WechatGlobalRefundApiResult;
|
|
import com.kmall.manager.manager.wechat.wxglobal.dto.WechatGlobalRefundApiResult;
|
|
-import com.qiniu.util.Json;
|
|
|
|
import okhttp3.Request;
|
|
import okhttp3.Request;
|
|
-import org.apache.shiro.crypto.hash.Hash;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -2066,9 +2063,9 @@ public class OrderServiceImpl implements OrderService {
|
|
List<GoodsEntity> goodsEntities = new ArrayList<>();
|
|
List<GoodsEntity> goodsEntities = new ArrayList<>();
|
|
|
|
|
|
// TODO 根据商品条码、sku、门店id查询相对应的商品信息,并组装成对象
|
|
// TODO 根据商品条码、sku、门店id查询相对应的商品信息,并组装成对象
|
|
- List<QueryGoodsVo> queryGoodsVoList = new ArrayList<>();
|
|
|
|
|
|
+ List<QueryGoodsVO> queryGoodsVOList = new ArrayList<>();
|
|
goodsList.forEach(map -> {
|
|
goodsList.forEach(map -> {
|
|
- QueryGoodsVo queryGoodsVo = new QueryGoodsVo();
|
|
|
|
|
|
+ QueryGoodsVO queryGoodsVo = new QueryGoodsVO();
|
|
queryGoodsVo.setProdBarcode((String) map.get("prodBarcode"));
|
|
queryGoodsVo.setProdBarcode((String) map.get("prodBarcode"));
|
|
queryGoodsVo.setSku((String) map.get("goodsSn"));
|
|
queryGoodsVo.setSku((String) map.get("goodsSn"));
|
|
queryGoodsVo.setStoreId(storeId);
|
|
queryGoodsVo.setStoreId(storeId);
|
|
@@ -2076,18 +2073,18 @@ public class OrderServiceImpl implements OrderService {
|
|
queryGoodsVo.setRetailPrice(new BigDecimal(String.valueOf(map.get("retailPrice"))));
|
|
queryGoodsVo.setRetailPrice(new BigDecimal(String.valueOf(map.get("retailPrice"))));
|
|
queryGoodsVo.setGoodsTaxes(new BigDecimal(String.valueOf(map.get("goodstaxes"))));
|
|
queryGoodsVo.setGoodsTaxes(new BigDecimal(String.valueOf(map.get("goodstaxes"))));
|
|
queryGoodsVo.setDisCountedPrice(new BigDecimal(String.valueOf(map.get("disCountedPrice"))));
|
|
queryGoodsVo.setDisCountedPrice(new BigDecimal(String.valueOf(map.get("disCountedPrice"))));
|
|
- queryGoodsVoList.add(queryGoodsVo);
|
|
|
|
|
|
+ queryGoodsVOList.add(queryGoodsVo);
|
|
});
|
|
});
|
|
// 将在循环中查询数据库改为一次性查询
|
|
// 将在循环中查询数据库改为一次性查询
|
|
- List<GoodsEntity> goodsEntityList = goodsService.queryGoodsStockByQueryGoodsVoList(queryGoodsVoList);
|
|
|
|
|
|
+ List<GoodsEntity> goodsEntityList = goodsService.queryGoodsStockByQueryGoodsVoList(queryGoodsVOList);
|
|
// 复制集合数据
|
|
// 复制集合数据
|
|
ListUtils listUtils = BeanUtils.instantiate(ListUtils.class);
|
|
ListUtils listUtils = BeanUtils.instantiate(ListUtils.class);
|
|
- listUtils.copyList(goodsEntityList, queryGoodsVoList);
|
|
|
|
|
|
+ listUtils.copyList(goodsEntityList, queryGoodsVOList);
|
|
// 用来存储是否达到满赠条件的map
|
|
// 用来存储是否达到满赠条件的map
|
|
Map<String, BigDecimal> categoryConditionMap = new HashMap<>();
|
|
Map<String, BigDecimal> categoryConditionMap = new HashMap<>();
|
|
Map<String, BigDecimal> brandConditionMap = new HashMap<>();
|
|
Map<String, BigDecimal> brandConditionMap = new HashMap<>();
|
|
|
|
|
|
- for (QueryGoodsVo goodsEntity : queryGoodsVoList) {
|
|
|
|
|
|
+ for (QueryGoodsVO goodsEntity : queryGoodsVOList) {
|
|
OrderGoodsEntity orderGoodsEntity = new OrderGoodsEntity();
|
|
OrderGoodsEntity orderGoodsEntity = new OrderGoodsEntity();
|
|
// 要购买的数量
|
|
// 要购买的数量
|
|
Integer sellVolume = goodsEntity.getSellVolume();
|
|
Integer sellVolume = goodsEntity.getSellVolume();
|
|
@@ -3980,20 +3977,27 @@ public class OrderServiceImpl implements OrderService {
|
|
* @return 商品集合
|
|
* @return 商品集合
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public List<GoodsDetailsDto> calculateOrderDiscountPrice(CalculateOrderDiscountPriceVo calculateOrderDiscountPriceVo) {
|
|
|
|
|
|
+ public CalculateOrderDiscountPriceResponseVO calculateOrderDiscountPrice(CalculateOrderDiscountPriceVO calculateOrderDiscountPriceVo) {
|
|
if (Objects.isNull(calculateOrderDiscountPriceVo)) {
|
|
if (Objects.isNull(calculateOrderDiscountPriceVo)) {
|
|
LOGGER.error("计算活动优惠价格,请求参数为null!");
|
|
LOGGER.error("计算活动优惠价格,请求参数为null!");
|
|
throw new ServiceException("计算活动优惠价格,请求参数为null!");
|
|
throw new ServiceException("计算活动优惠价格,请求参数为null!");
|
|
}
|
|
}
|
|
|
|
+ CalculateOrderDiscountPriceResponseVO calculateOrderDiscountPriceResponseVO = new CalculateOrderDiscountPriceResponseVO();
|
|
String storeId = calculateOrderDiscountPriceVo.getStoreId();
|
|
String storeId = calculateOrderDiscountPriceVo.getStoreId();
|
|
|
|
+ String memberCode = calculateOrderDiscountPriceVo.getMemberCode();
|
|
List<GoodsDetailsDto> goodsDetailsDtos = calculateOrderDiscountPriceVo.getGoodsList();
|
|
List<GoodsDetailsDto> goodsDetailsDtos = calculateOrderDiscountPriceVo.getGoodsList();
|
|
- List<QueryGoodsVo> goodsVos = goodsDetailsDtos.stream().map(good -> {
|
|
|
|
- QueryGoodsVo queryGoodsVo = new QueryGoodsVo();
|
|
|
|
|
|
+ BigDecimal orderTotalPrice = BigDecimal.ZERO;
|
|
|
|
+ List<QueryGoodsVO> goodsVos = new ArrayList<>();
|
|
|
|
+ for (GoodsDetailsDto good : goodsDetailsDtos) {
|
|
|
|
+ QueryGoodsVO queryGoodsVo = new QueryGoodsVO();
|
|
BeanUtils.copyProperties(good, queryGoodsVo);
|
|
BeanUtils.copyProperties(good, queryGoodsVo);
|
|
queryGoodsVo.setSku(good.getGoodsSn());
|
|
queryGoodsVo.setSku(good.getGoodsSn());
|
|
queryGoodsVo.setStoreId(Integer.parseInt(storeId));
|
|
queryGoodsVo.setStoreId(Integer.parseInt(storeId));
|
|
- return queryGoodsVo;
|
|
|
|
- }).collect(Collectors.toList());
|
|
|
|
|
|
+ orderTotalPrice = orderTotalPrice.add(good.getActualPaymentAmount());
|
|
|
|
+ goodsVos.add(queryGoodsVo);
|
|
|
|
+ }
|
|
|
|
+ calculateOrderDiscountPriceResponseVO.setOrderTotalPrice(orderTotalPrice);
|
|
|
|
+ calculateOrderDiscountPriceResponseVO.setGoodsDetailsDtos(goodsDetailsDtos);
|
|
|
|
|
|
// 查询商品表
|
|
// 查询商品表
|
|
List<GoodsEntity> goodsEntities = goodsService.queryGoodsStockByQueryGoodsVoList(goodsVos);
|
|
List<GoodsEntity> goodsEntities = goodsService.queryGoodsStockByQueryGoodsVoList(goodsVos);
|
|
@@ -4003,7 +4007,15 @@ public class OrderServiceImpl implements OrderService {
|
|
* 参数: 当前时间 门店id
|
|
* 参数: 当前时间 门店id
|
|
*/
|
|
*/
|
|
List<MkActivitiesEntity> mkActivitiesEntityList = mkActivitiesService.queryByNow(storeId, DateUtils.format(new Date(), "yyyy-MM-dd"));
|
|
List<MkActivitiesEntity> mkActivitiesEntityList = mkActivitiesService.queryByNow(storeId, DateUtils.format(new Date(), "yyyy-MM-dd"));
|
|
-
|
|
|
|
|
|
+ // 活动优先级判定,特价>打折>满减/满赠>优惠券>积分抵扣;
|
|
|
|
+// List<Constants.ActivityTopicEnum> activityTopicEnums = Arrays.asList(Constants.ActivityTopicEnum.values());
|
|
|
|
+// for (MkActivitiesEntity mkActivitiesEntity : mkActivitiesEntityList) {
|
|
|
|
+// for (Constants.ActivityTopicEnum activityTopicEnum : activityTopicEnums) {
|
|
|
|
+// if (activityTopicEnum.get) {
|
|
|
|
+//
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
/*
|
|
/*
|
|
* 活动相关规则:
|
|
* 活动相关规则:
|
|
* 1. 优先优惠券再去计算积分
|
|
* 1. 优先优惠券再去计算积分
|
|
@@ -4011,8 +4023,8 @@ public class OrderServiceImpl implements OrderService {
|
|
* 3. 任何活动都优先于积分计算
|
|
* 3. 任何活动都优先于积分计算
|
|
* 4. 活动之间具有互斥性
|
|
* 4. 活动之间具有互斥性
|
|
*/
|
|
*/
|
|
- if (CollectionUtils.isEmpty(mkActivitiesEntityList)) {
|
|
|
|
- LOGGER.info("当前时间门店【{}】,无相关活动信息!", storeId);
|
|
|
|
|
|
+ if (CollectionUtils.isEmpty(mkActivitiesEntityList) && org.springframework.util.StringUtils.isEmpty(memberCode)) {
|
|
|
|
+ LOGGER.info("门店【{}】,在当前时间无相关活动信息!", storeId);
|
|
for (GoodsDetailsDto goodsDetailsDto : goodsDetailsDtos) {
|
|
for (GoodsDetailsDto goodsDetailsDto : goodsDetailsDtos) {
|
|
GoodsEntity goodsEntity = new GoodsEntity();
|
|
GoodsEntity goodsEntity = new GoodsEntity();
|
|
BeanUtils.copyProperties(goodsDetailsDto, goodsEntity);
|
|
BeanUtils.copyProperties(goodsDetailsDto, goodsEntity);
|
|
@@ -4022,136 +4034,199 @@ public class OrderServiceImpl implements OrderService {
|
|
// 预估税
|
|
// 预估税
|
|
goodsDetailsDto.setGoodstaxes(String.valueOf(tax.multiply(new BigDecimal(goodsDetailsDto.getSellVolume()))));
|
|
goodsDetailsDto.setGoodstaxes(String.valueOf(tax.multiply(new BigDecimal(goodsDetailsDto.getSellVolume()))));
|
|
}
|
|
}
|
|
- return goodsDetailsDtos;
|
|
|
|
|
|
+ calculateOrderDiscountPriceResponseVO.setGoodsDetailsDtos(goodsDetailsDtos);
|
|
|
|
+ return calculateOrderDiscountPriceResponseVO;
|
|
}
|
|
}
|
|
|
|
|
|
List<Integer> brandIdList = goodsEntities.stream().map(GoodsEntity::getBrandId).collect(Collectors.toList());
|
|
List<Integer> brandIdList = goodsEntities.stream().map(GoodsEntity::getBrandId).collect(Collectors.toList());
|
|
List<Integer> categoryIdList = goodsEntities.stream().map(GoodsEntity::getCategoryId).collect(Collectors.toList());
|
|
List<Integer> categoryIdList = goodsEntities.stream().map(GoodsEntity::getCategoryId).collect(Collectors.toList());
|
|
-
|
|
|
|
- AtomicBoolean activityFlag = new AtomicBoolean(false);
|
|
|
|
|
|
+ // 活动互斥标识
|
|
|
|
+ AtomicBoolean activityFlag = new AtomicBoolean(true);
|
|
// 判断活动类型,并确定购物栏中商品是否满足活动条件
|
|
// 判断活动类型,并确定购物栏中商品是否满足活动条件
|
|
mkActivitiesEntityList.forEach(mkActivitiesEntity -> {
|
|
mkActivitiesEntityList.forEach(mkActivitiesEntity -> {
|
|
String mkaStoreId = mkActivitiesEntity.getMkaStoreId();
|
|
String mkaStoreId = mkActivitiesEntity.getMkaStoreId();
|
|
Long mkaId = mkActivitiesEntity.getMkaId();
|
|
Long mkaId = mkActivitiesEntity.getMkaId();
|
|
String mkaTopic = mkActivitiesEntity.getMkaTopic();
|
|
String mkaTopic = mkActivitiesEntity.getMkaTopic();
|
|
Constants.ActivityTopicEnum activityTopicEnum = Constants.ActivityTopicEnum.valueOf(mkaTopic);
|
|
Constants.ActivityTopicEnum activityTopicEnum = Constants.ActivityTopicEnum.valueOf(mkaTopic);
|
|
- switch (activityTopicEnum) {
|
|
|
|
- case MZ:
|
|
|
|
- // 判断商品是否符合满赠活动要求
|
|
|
|
- MkActivitiesFullGiftEntity mkActivitiesFullGiftEntity = mkActivitiesFullGiftService.queryObjectByMkaIdAndStoreId(mkaId.intValue(), storeId);
|
|
|
|
- if (Objects.isNull(mkActivitiesFullGiftEntity)) {
|
|
|
|
- LOGGER.error("查询满赠活动信息结果为空!mka_id:{}, store_id:{}", mkaId, storeId);
|
|
|
|
- throw new ServiceException(String.format("查询满赠活动信息结果为空!mka_id:%s, store_id:%s", mkaId, storeId));
|
|
|
|
- }
|
|
|
|
- Long brandId = mkActivitiesFullGiftEntity.getBrandId();
|
|
|
|
- Long categoryId = mkActivitiesFullGiftEntity.getCategoryId();
|
|
|
|
- Constants.ActivityType fullGiftActivityType = Constants.ActivityType.valueOf(mkActivitiesFullGiftEntity.getFullGiftType());
|
|
|
|
- switch (fullGiftActivityType) {
|
|
|
|
- case BRAND:
|
|
|
|
- if (brandIdList.contains(brandId.intValue())) {
|
|
|
|
- // 活动包含该商品品牌,此次订单该品牌商品
|
|
|
|
- List<GoodsEntity> goodsEntityList = goodsEntities.stream().filter(goodsEntity -> brandId.intValue() == goodsEntity.getBrandId()).collect(Collectors.toList());
|
|
|
|
- AtomicReference<BigDecimal> brandTotalPrice = new AtomicReference<>(BigDecimal.ZERO);
|
|
|
|
- goodsEntityList.forEach(goodsEntity -> {
|
|
|
|
- brandTotalPrice.set(brandTotalPrice.get().add(goodsEntity.getRetailPrice()));
|
|
|
|
- });
|
|
|
|
- if (brandTotalPrice.get().compareTo(mkActivitiesFullGiftEntity.getQualifiedAmount()) >= 0) {
|
|
|
|
- // 满足满赠条件
|
|
|
|
- String giftGoodsSn = mkActivitiesFullGiftEntity.getGiftGoodsSn();
|
|
|
|
- String giftBarcode = mkActivitiesFullGiftEntity.getGiftBarcode();
|
|
|
|
- GoodsEntity goodsEntity = goodsService.queryGoodsStockByBarcodeAndStoreIdAndSku(giftBarcode, Integer.parseInt(mkaStoreId), giftGoodsSn);
|
|
|
|
- GoodsDetailsDto goodsDetailsDto = new GoodsDetailsDto();
|
|
|
|
- BeanUtils.copyProperties(goodsEntity, goodsDetailsDto);
|
|
|
|
- // 除了限时促销(需要向海关备案),其它活动都拿海关备案价来算税款
|
|
|
|
- BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity, goodsEntity.getRetailPrice(), goodsService).setScale(3, RoundingMode.HALF_UP);
|
|
|
|
- goodsDetailsDto.setGoodstaxes(String.valueOf(tax.multiply(new BigDecimal(goodsDetailsDto.getSellVolume()))));
|
|
|
|
- goodsDetailsDto.setActualPaymentAmount(BigDecimal.ZERO);
|
|
|
|
- goodsDetailsDto.setActivity("满赠商品");
|
|
|
|
- goodsDetailsDto.setGiftNumber(mkActivitiesFullGiftEntity.getGiftNumber());
|
|
|
|
- goodsDetailsDto.setDiscountedPrice(goodsEntity.getRetailPrice());
|
|
|
|
- // 添加进商品详情列表
|
|
|
|
- goodsDetailsDtos.add(goodsDetailsDto);
|
|
|
|
- }
|
|
|
|
|
|
+ // 活动之间的优先级:特价>打折>满减/满赠>优惠券>积分抵扣
|
|
|
|
+ if (activityTopicEnum == Constants.ActivityTopicEnum.LSCX && activityFlag.get()) {
|
|
|
|
+ // 判断商品是否符合限时特价活动要求
|
|
|
|
+ List<MkActivitiesPromotionEntity> mkActivitiesPromotionEntities = mkActivitiesPromotionService.queryListByMkaIdAndStoreId(mkaId.intValue(), storeId);
|
|
|
|
+ if (CollectionUtils.isEmpty(mkActivitiesPromotionEntities)) {
|
|
|
|
+ LOGGER.error("查询临时促销活动信息结果为空!mka_id:{}, store_id:{}", mkaId, storeId);
|
|
|
|
+ throw new ServiceException(String.format("查询临时促销活动信息结果为空!mka_id:%s, store_id:%s", mkaId, storeId));
|
|
|
|
+ }
|
|
|
|
+ // 限时特价,直接替换实际支付价即可,并且拿特价计算税款
|
|
|
|
+ mkActivitiesPromotionEntities.forEach(mkActivitiesPromotionEntity -> {
|
|
|
|
+ String entityBarcode = mkActivitiesPromotionEntity.getBarcode();
|
|
|
|
+ String entityGoodsSn = mkActivitiesPromotionEntity.getGoodsSn();
|
|
|
|
+ BigDecimal activityPrice = mkActivitiesPromotionEntity.getActivityPrice();
|
|
|
|
+ String shopSn = mkActivitiesPromotionEntity.getShopSn();
|
|
|
|
+ goodsEntities.forEach(goodsEntity -> {
|
|
|
|
+ String sku = goodsEntity.getSku();
|
|
|
|
+ String prodBarcode = goodsEntity.getProdBarcode();
|
|
|
|
+ String storeId2 = String.valueOf(goodsEntity.getStoreId());
|
|
|
|
+ BigDecimal retailPrice = goodsEntity.getRetailPrice();
|
|
|
|
+ if (entityBarcode.equals(prodBarcode) && entityGoodsSn.equals(sku) && shopSn.equals(storeId2)) {
|
|
|
|
+ GoodsDetailsDto goodsDetailsDto = new GoodsDetailsDto();
|
|
|
|
+ BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity, activityPrice, goodsService).setScale(3, RoundingMode.HALF_UP);
|
|
|
|
+ BeanUtils.copyProperties(goodsDetailsDto, goodsEntity);
|
|
|
|
+ goodsDetailsDto.setActualPaymentAmount(activityPrice);
|
|
|
|
+ goodsDetailsDto.setGoodstaxes(String.valueOf(tax.multiply(new BigDecimal(goodsDetailsDto.getSellVolume()))));
|
|
|
|
+ goodsDetailsDto.setActivity("限时促销");
|
|
|
|
+ goodsDetailsDto.setDiscountedPrice(retailPrice.subtract(activityPrice));
|
|
|
|
+ goodsDetailsDtos.add(goodsDetailsDto);
|
|
|
|
+ activityFlag.set(false);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ } else if (activityTopicEnum == Constants.ActivityTopicEnum.MZ && activityFlag.get()) {
|
|
|
|
+ // 判断商品是否符合满赠活动要求
|
|
|
|
+ MkActivitiesFullGiftEntity mkActivitiesFullGiftEntity = mkActivitiesFullGiftService.queryObjectByMkaIdAndStoreId(mkaId.intValue(), storeId);
|
|
|
|
+ if (Objects.isNull(mkActivitiesFullGiftEntity)) {
|
|
|
|
+ LOGGER.error("查询满赠活动信息结果为空!mka_id:{}, store_id:{}", mkaId, storeId);
|
|
|
|
+ throw new ServiceException(String.format("查询满赠活动信息结果为空!mka_id:%s, store_id:%s", mkaId, storeId));
|
|
|
|
+ }
|
|
|
|
+ Long brandId = mkActivitiesFullGiftEntity.getBrandId();
|
|
|
|
+ Long categoryId = mkActivitiesFullGiftEntity.getCategoryId();
|
|
|
|
+ Constants.ActivityType fullGiftActivityType = Constants.ActivityType.valueOf(mkActivitiesFullGiftEntity.getFullGiftType());
|
|
|
|
+ switch (fullGiftActivityType) {
|
|
|
|
+ case BRAND:
|
|
|
|
+ if (brandIdList.contains(brandId.intValue())) {
|
|
|
|
+ // 活动包含该商品品牌,此次订单该品牌商品
|
|
|
|
+ List<GoodsEntity> goodsEntityList = goodsEntities.stream().filter(goodsEntity -> brandId.intValue() == goodsEntity.getBrandId()).collect(Collectors.toList());
|
|
|
|
+ AtomicReference<BigDecimal> brandTotalPrice = new AtomicReference<>(BigDecimal.ZERO);
|
|
|
|
+ goodsEntityList.forEach(goodsEntity -> {
|
|
|
|
+ brandTotalPrice.set(brandTotalPrice.get().add(goodsEntity.getRetailPrice()));
|
|
|
|
+ });
|
|
|
|
+ if (brandTotalPrice.get().compareTo(mkActivitiesFullGiftEntity.getQualifiedAmount()) >= 0) {
|
|
|
|
+ // 满足满赠条件
|
|
|
|
+ String giftGoodsSn = mkActivitiesFullGiftEntity.getGiftGoodsSn();
|
|
|
|
+ String giftBarcode = mkActivitiesFullGiftEntity.getGiftBarcode();
|
|
|
|
+ GoodsEntity goodsEntity = goodsService.queryGoodsStockByBarcodeAndStoreIdAndSku(giftBarcode, Integer.parseInt(mkaStoreId), giftGoodsSn);
|
|
|
|
+ GoodsDetailsDto goodsDetailsDto = new GoodsDetailsDto();
|
|
|
|
+ BeanUtils.copyProperties(goodsEntity, goodsDetailsDto);
|
|
|
|
+ // 除了限时促销(需要向海关备案),其它活动都拿海关备案价来算税款
|
|
|
|
+ BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity, goodsEntity.getRetailPrice(), goodsService).setScale(3, RoundingMode.HALF_UP);
|
|
|
|
+ goodsDetailsDto.setGoodstaxes(String.valueOf(tax.multiply(new BigDecimal(goodsDetailsDto.getSellVolume()))));
|
|
|
|
+ goodsDetailsDto.setActualPaymentAmount(BigDecimal.ZERO);
|
|
|
|
+ goodsDetailsDto.setActivity("满赠商品");
|
|
|
|
+ goodsDetailsDto.setGiftNumber(mkActivitiesFullGiftEntity.getGiftNumber());
|
|
|
|
+ goodsDetailsDto.setDiscountedPrice(goodsEntity.getRetailPrice());
|
|
|
|
+ // 添加进商品详情列表
|
|
|
|
+ goodsDetailsDtos.add(goodsDetailsDto);
|
|
|
|
+ activityFlag.set(false);
|
|
}
|
|
}
|
|
- break;
|
|
|
|
- case CATEGORY:
|
|
|
|
- if (categoryIdList.contains(categoryId.intValue())) {
|
|
|
|
- // 活动包含该商品分类
|
|
|
|
- List<GoodsEntity> goodsEntityList = goodsEntities.stream().filter(goodsEntity -> brandId.equals(mkActivitiesFullGiftEntity.getCategoryId())).collect(Collectors.toList());
|
|
|
|
- AtomicReference<BigDecimal> categoryTotalPrice = new AtomicReference<>(BigDecimal.ZERO);
|
|
|
|
- goodsEntityList.forEach(goodsEntity -> {
|
|
|
|
- categoryTotalPrice.set(categoryTotalPrice.get().add(goodsEntity.getRetailPrice()));
|
|
|
|
- });
|
|
|
|
- if (categoryTotalPrice.get().compareTo(mkActivitiesFullGiftEntity.getQualifiedAmount()) >= 0) {
|
|
|
|
- // 满足满赠条件
|
|
|
|
- String giftGoodsSn = mkActivitiesFullGiftEntity.getGiftGoodsSn();
|
|
|
|
- String giftBarcode = mkActivitiesFullGiftEntity.getGiftBarcode();
|
|
|
|
- GoodsEntity goodsEntity = goodsService.queryGoodsStockByBarcodeAndStoreIdAndSku(giftBarcode, Integer.parseInt(mkaStoreId), giftGoodsSn);
|
|
|
|
- GoodsDetailsDto goodsDetailsDto = new GoodsDetailsDto();
|
|
|
|
- BeanUtils.copyProperties(goodsEntity, goodsDetailsDto);
|
|
|
|
- // 除了限时促销(需要向海关备案),其它活动都拿海关备案价来算税款
|
|
|
|
- BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity, goodsEntity.getRetailPrice(), goodsService).setScale(3, RoundingMode.HALF_UP);
|
|
|
|
- goodsDetailsDto.setGoodstaxes(String.valueOf(tax.multiply(new BigDecimal(goodsDetailsDto.getSellVolume()))));
|
|
|
|
- goodsDetailsDto.setActualPaymentAmount(BigDecimal.ZERO);
|
|
|
|
- goodsDetailsDto.setActivity("满赠商品");
|
|
|
|
- goodsDetailsDto.setGiftNumber(mkActivitiesFullGiftEntity.getGiftNumber());
|
|
|
|
- goodsDetailsDto.setDiscountedPrice(goodsEntity.getRetailPrice());
|
|
|
|
- // 添加进商品详情列表
|
|
|
|
- goodsDetailsDtos.add(goodsDetailsDto);
|
|
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case CATEGORY:
|
|
|
|
+ if (categoryIdList.contains(categoryId.intValue())) {
|
|
|
|
+ // 活动包含该商品分类
|
|
|
|
+ List<GoodsEntity> goodsEntityList = goodsEntities.stream().filter(goodsEntity -> brandId.equals(mkActivitiesFullGiftEntity.getCategoryId())).collect(Collectors.toList());
|
|
|
|
+ AtomicReference<BigDecimal> categoryTotalPrice = new AtomicReference<>(BigDecimal.ZERO);
|
|
|
|
+ goodsEntityList.forEach(goodsEntity -> {
|
|
|
|
+ categoryTotalPrice.set(categoryTotalPrice.get().add(goodsEntity.getRetailPrice()));
|
|
|
|
+ });
|
|
|
|
+ if (categoryTotalPrice.get().compareTo(mkActivitiesFullGiftEntity.getQualifiedAmount()) >= 0) {
|
|
|
|
+ // 满足满赠条件
|
|
|
|
+ String giftGoodsSn = mkActivitiesFullGiftEntity.getGiftGoodsSn();
|
|
|
|
+ String giftBarcode = mkActivitiesFullGiftEntity.getGiftBarcode();
|
|
|
|
+ GoodsEntity goodsEntity = goodsService.queryGoodsStockByBarcodeAndStoreIdAndSku(giftBarcode, Integer.parseInt(mkaStoreId), giftGoodsSn);
|
|
|
|
+ GoodsDetailsDto goodsDetailsDto = new GoodsDetailsDto();
|
|
|
|
+ BeanUtils.copyProperties(goodsEntity, goodsDetailsDto);
|
|
|
|
+ // 除了限时促销(需要向海关备案),其它活动都拿海关备案价来算税款
|
|
|
|
+ BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity, goodsEntity.getRetailPrice(), goodsService).setScale(3, RoundingMode.HALF_UP);
|
|
|
|
+ goodsDetailsDto.setGoodstaxes(String.valueOf(tax.multiply(new BigDecimal(goodsDetailsDto.getSellVolume()))));
|
|
|
|
+ goodsDetailsDto.setActualPaymentAmount(BigDecimal.ZERO);
|
|
|
|
+ goodsDetailsDto.setActivity("满赠商品");
|
|
|
|
+ goodsDetailsDto.setGiftNumber(mkActivitiesFullGiftEntity.getGiftNumber());
|
|
|
|
+ goodsDetailsDto.setDiscountedPrice(goodsEntity.getRetailPrice());
|
|
|
|
+ // 添加进商品详情列表
|
|
|
|
+ goodsDetailsDtos.add(goodsDetailsDto);
|
|
|
|
+ activityFlag.set(false);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ LOGGER.error("未知满赠类型【{},{}】!请联系管理员!", fullGiftActivityType.getActivityType(), fullGiftActivityType.getActivityTypeCode());
|
|
|
|
+ throw new ServiceException(String.format("未知满赠类型【%s,%s】!请联系管理员!", fullGiftActivityType.getActivityType(), fullGiftActivityType.getActivityTypeCode()));
|
|
|
|
+ }
|
|
|
|
+ } else if (activityTopicEnum == Constants.ActivityTopicEnum.YHJ && activityFlag.get()) {
|
|
|
|
+ // 判断商品是否符合优惠券活动要求
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
+ params.put("shop_sn", storeId);
|
|
|
|
+ params.put("mka_id", mkaId);
|
|
|
|
+ List<MkActivitiesCouponEntity> mkActivitiesCouponEntities = mkActivitiesCouponService.queryList(params);
|
|
|
|
+ if (CollectionUtils.isEmpty(mkActivitiesCouponEntities)) {
|
|
|
|
+ LOGGER.error("查询优惠券活动信息结果为空!mka_id:{}, store_id:{}", mkaId, storeId);
|
|
|
|
+ throw new ServiceException(String.format("查询优惠券活动信息结果为空!mka_id:%s, store_id:%s", mkaId, storeId));
|
|
|
|
+ }
|
|
|
|
+ MkActivitiesCouponEntity mkActivitiesCouponEntity = mkActivitiesCouponEntities.get(0);
|
|
|
|
+ Integer couponEntityBrandId = mkActivitiesCouponEntity.getBrandId();
|
|
|
|
+ Integer couponEntityCategoryId = mkActivitiesCouponEntity.getCategoryId();
|
|
|
|
+ Integer couponEntityStoreId = Integer.parseInt(mkActivitiesCouponEntity.getShopSn());
|
|
|
|
+ BigDecimal couponPrice = mkActivitiesCouponEntity.getCouponPrice();
|
|
|
|
+ Constants.ActivityType couponActivityType = Constants.ActivityType.valueOf(mkActivitiesCouponEntity.getActivityType());
|
|
|
|
+ switch (couponActivityType) {
|
|
|
|
+ case BRAND:
|
|
|
|
+ goodsEntities.forEach(goodsEntity -> {
|
|
|
|
+ if (couponEntityBrandId.equals(goodsEntity.getBrandId())) {
|
|
|
|
+ BigDecimal retailPrice = goodsEntity.getRetailPrice();
|
|
|
|
+ String sku = goodsEntity.getSku();
|
|
|
|
+ String prodBarcode = goodsEntity.getProdBarcode();
|
|
|
|
+ if (couponPrice.compareTo(retailPrice) <= 0) {
|
|
|
|
+ LOGGER.error("优惠券优惠金额【{}】大于或等于商品【条码:{},sku:{}】的零售价【{}】,请检查优惠券金额设置!", couponPrice, prodBarcode, sku, retailPrice);
|
|
|
|
+ throw new ServiceException(String.format("优惠券优惠金额【%s】大于或等于商品【条码:%s,sku:%s】的零售价【%s】,请检查优惠券金额设置!", couponPrice, prodBarcode, sku, retailPrice));
|
|
}
|
|
}
|
|
|
|
+ BigDecimal discountAfterPrice = retailPrice.subtract(couponPrice);
|
|
|
|
+ GoodsDetailsDto goodsDetailsDto = new GoodsDetailsDto();
|
|
|
|
+ BeanUtils.copyProperties(goodsEntity, goodsDetailsDto);
|
|
|
|
+ // 除了限时促销(需要向海关备案),其它活动都拿海关备案价来算税款
|
|
|
|
+ BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity, goodsEntity.getRetailPrice(), goodsService).setScale(3, RoundingMode.HALF_UP);
|
|
|
|
+ goodsDetailsDto.setActualPaymentAmount(discountAfterPrice);
|
|
|
|
+ goodsDetailsDto.setGoodstaxes(String.valueOf(tax.multiply(new BigDecimal(goodsDetailsDto.getSellVolume()))));
|
|
|
|
+ goodsDetailsDto.setActivity("优惠券活动");
|
|
|
|
+ goodsDetailsDto.setDiscountedPrice(retailPrice.subtract(discountAfterPrice));
|
|
|
|
+ goodsDetailsDtos.add(goodsDetailsDto);
|
|
|
|
+ activityFlag.set(false);
|
|
}
|
|
}
|
|
- break;
|
|
|
|
- default:
|
|
|
|
- LOGGER.error("未知满赠类型【{},{}】!请联系管理员!", fullGiftActivityType.getActivityType(), fullGiftActivityType.getActivityTypeCode());
|
|
|
|
- throw new ServiceException(String.format("未知满赠类型【%s,%s】!请联系管理员!", fullGiftActivityType.getActivityType(), fullGiftActivityType.getActivityTypeCode()));
|
|
|
|
- }
|
|
|
|
- break;
|
|
|
|
- case YHJ:
|
|
|
|
- // 判断商品是否符合优惠券活动要求
|
|
|
|
- Map<String, Object> params = new HashMap<>();
|
|
|
|
- params.put("shop_sn", storeId);
|
|
|
|
- params.put("mka_id", mkaId);
|
|
|
|
- List<MkActivitiesCouponEntity> mkActivitiesCouponEntities = mkActivitiesCouponService.queryList(params);
|
|
|
|
- if (CollectionUtils.isEmpty(mkActivitiesCouponEntities)) {
|
|
|
|
- LOGGER.error("查询优惠券活动信息结果为空!mka_id:{}, store_id:{}", mkaId, storeId);
|
|
|
|
- throw new ServiceException(String.format("查询优惠券活动信息结果为空!mka_id:%s, store_id:%s", mkaId, storeId));
|
|
|
|
- }
|
|
|
|
- MkActivitiesCouponEntity mkActivitiesCouponEntity = mkActivitiesCouponEntities.get(0);
|
|
|
|
- Integer couponEntityBrandId = mkActivitiesCouponEntity.getBrandId();
|
|
|
|
- Integer couponEntityCategoryId = mkActivitiesCouponEntity.getCategoryId();
|
|
|
|
- Integer couponEntityStoreId = Integer.parseInt(mkActivitiesCouponEntity.getShopSn());
|
|
|
|
- BigDecimal couponPrice = mkActivitiesCouponEntity.getCouponPrice();
|
|
|
|
- Constants.ActivityType couponActivityType = Constants.ActivityType.valueOf(mkActivitiesCouponEntity.getActivityType());
|
|
|
|
- switch (couponActivityType) {
|
|
|
|
- case BRAND:
|
|
|
|
- goodsEntities.forEach(goodsEntity -> {
|
|
|
|
- if (couponEntityBrandId.equals(goodsEntity.getBrandId())) {
|
|
|
|
- BigDecimal retailPrice = goodsEntity.getRetailPrice();
|
|
|
|
- String sku = goodsEntity.getSku();
|
|
|
|
- String prodBarcode = goodsEntity.getProdBarcode();
|
|
|
|
- if (couponPrice.compareTo(retailPrice) <= 0) {
|
|
|
|
- LOGGER.error("优惠券优惠金额【{}】大于或等于商品【条码:{},sku:{}】的零售价【{}】,请检查优惠券金额设置!", couponPrice, prodBarcode, sku, retailPrice);
|
|
|
|
- throw new ServiceException(String.format("优惠券优惠金额【%s】大于或等于商品【条码:%s,sku:%s】的零售价【%s】,请检查优惠券金额设置!", couponPrice, prodBarcode, sku, retailPrice));
|
|
|
|
- }
|
|
|
|
- BigDecimal discountAfterPrice = retailPrice.subtract(couponPrice);
|
|
|
|
- GoodsDetailsDto goodsDetailsDto = new GoodsDetailsDto();
|
|
|
|
- BeanUtils.copyProperties(goodsEntity, goodsDetailsDto);
|
|
|
|
- // 除了限时促销(需要向海关备案),其它活动都拿海关备案价来算税款
|
|
|
|
- BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity, goodsEntity.getRetailPrice(), goodsService).setScale(3, RoundingMode.HALF_UP);
|
|
|
|
- goodsDetailsDto.setActualPaymentAmount(discountAfterPrice);
|
|
|
|
- goodsDetailsDto.setGoodstaxes(String.valueOf(tax.multiply(new BigDecimal(goodsDetailsDto.getSellVolume()))));
|
|
|
|
- goodsDetailsDto.setActivity("优惠券活动");
|
|
|
|
- goodsDetailsDto.setDiscountedPrice(retailPrice.subtract(discountAfterPrice));
|
|
|
|
- goodsDetailsDtos.add(goodsDetailsDto);
|
|
|
|
|
|
+ });
|
|
|
|
+ break;
|
|
|
|
+ case CATEGORY:
|
|
|
|
+ goodsEntities.forEach(goodsEntity -> {
|
|
|
|
+ if (couponEntityCategoryId.equals(goodsEntity.getCategoryId())) {
|
|
|
|
+ BigDecimal retailPrice = goodsEntity.getRetailPrice();
|
|
|
|
+ String sku = goodsEntity.getSku();
|
|
|
|
+ String prodBarcode = goodsEntity.getProdBarcode();
|
|
|
|
+ if (couponPrice.compareTo(retailPrice) <= 0) {
|
|
|
|
+ LOGGER.error("优惠券优惠金额【{}】大于或等于商品【条码:{},sku:{}】的零售价【{}】,请检查优惠券金额设置!", couponPrice, prodBarcode, sku, retailPrice);
|
|
|
|
+ throw new ServiceException(String.format("优惠券优惠金额【%s】大于或等于商品【条码:%s,sku:%s】的零售价【%s】,请检查优惠券金额设置!", couponPrice, prodBarcode, sku, retailPrice));
|
|
}
|
|
}
|
|
- });
|
|
|
|
- break;
|
|
|
|
- case CATEGORY:
|
|
|
|
|
|
+ BigDecimal discountAfterPrice = retailPrice.subtract(couponPrice);
|
|
|
|
+ GoodsDetailsDto goodsDetailsDto = new GoodsDetailsDto();
|
|
|
|
+ BeanUtils.copyProperties(goodsEntity, goodsDetailsDto);
|
|
|
|
+ // 除了限时促销(需要向海关备案),其它活动都拿海关备案价来算税款
|
|
|
|
+ BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity, goodsEntity.getRetailPrice(), goodsService).setScale(3, RoundingMode.HALF_UP);
|
|
|
|
+ goodsDetailsDto.setActualPaymentAmount(discountAfterPrice);
|
|
|
|
+ goodsDetailsDto.setGoodstaxes(String.valueOf(tax.multiply(new BigDecimal(goodsDetailsDto.getSellVolume()))));
|
|
|
|
+ goodsDetailsDto.setActivity("优惠券活动");
|
|
|
|
+ goodsDetailsDto.setDiscountedPrice(retailPrice.subtract(discountAfterPrice));
|
|
|
|
+ goodsDetailsDtos.add(goodsDetailsDto);
|
|
|
|
+ activityFlag.set(false);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ break;
|
|
|
|
+ case PRODUCT:
|
|
|
|
+ mkActivitiesCouponEntities.forEach(mkActivitiesCouponEntity1 -> {
|
|
|
|
+ // 单个商品优惠券,有多条记录
|
|
|
|
+ String activityProductBarcode = mkActivitiesCouponEntity1.getBarcode();
|
|
|
|
+ String activitySku = mkActivitiesCouponEntity1.getGoodsSn();
|
|
goodsEntities.forEach(goodsEntity -> {
|
|
goodsEntities.forEach(goodsEntity -> {
|
|
- if (couponEntityCategoryId.equals(goodsEntity.getCategoryId())) {
|
|
|
|
|
|
+ String sku = goodsEntity.getSku();
|
|
|
|
+ String prodBarcode = goodsEntity.getProdBarcode();
|
|
|
|
+ // 条码、sku、门店都需一致
|
|
|
|
+ if (activitySku.equals(sku) && activityProductBarcode.equals(prodBarcode) && couponEntityStoreId.equals(goodsEntity.getStoreId())) {
|
|
BigDecimal retailPrice = goodsEntity.getRetailPrice();
|
|
BigDecimal retailPrice = goodsEntity.getRetailPrice();
|
|
- String sku = goodsEntity.getSku();
|
|
|
|
- String prodBarcode = goodsEntity.getProdBarcode();
|
|
|
|
if (couponPrice.compareTo(retailPrice) <= 0) {
|
|
if (couponPrice.compareTo(retailPrice) <= 0) {
|
|
LOGGER.error("优惠券优惠金额【{}】大于或等于商品【条码:{},sku:{}】的零售价【{}】,请检查优惠券金额设置!", couponPrice, prodBarcode, sku, retailPrice);
|
|
LOGGER.error("优惠券优惠金额【{}】大于或等于商品【条码:{},sku:{}】的零售价【{}】,请检查优惠券金额设置!", couponPrice, prodBarcode, sku, retailPrice);
|
|
throw new ServiceException(String.format("优惠券优惠金额【%s】大于或等于商品【条码:%s,sku:%s】的零售价【%s】,请检查优惠券金额设置!", couponPrice, prodBarcode, sku, retailPrice));
|
|
throw new ServiceException(String.format("优惠券优惠金额【%s】大于或等于商品【条码:%s,sku:%s】的零售价【%s】,请检查优惠券金额设置!", couponPrice, prodBarcode, sku, retailPrice));
|
|
@@ -4166,92 +4241,98 @@ public class OrderServiceImpl implements OrderService {
|
|
goodsDetailsDto.setActivity("优惠券活动");
|
|
goodsDetailsDto.setActivity("优惠券活动");
|
|
goodsDetailsDto.setDiscountedPrice(retailPrice.subtract(discountAfterPrice));
|
|
goodsDetailsDto.setDiscountedPrice(retailPrice.subtract(discountAfterPrice));
|
|
goodsDetailsDtos.add(goodsDetailsDto);
|
|
goodsDetailsDtos.add(goodsDetailsDto);
|
|
|
|
+ activityFlag.set(false);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
- break;
|
|
|
|
- case PRODUCT:
|
|
|
|
- mkActivitiesCouponEntities.forEach(mkActivitiesCouponEntity1 -> {
|
|
|
|
- // 单个商品优惠券,有多条记录
|
|
|
|
- String activityProductBarcode = mkActivitiesCouponEntity1.getBarcode();
|
|
|
|
- String activitySku = mkActivitiesCouponEntity1.getGoodsSn();
|
|
|
|
- goodsEntities.forEach(goodsEntity -> {
|
|
|
|
- String sku = goodsEntity.getSku();
|
|
|
|
- String prodBarcode = goodsEntity.getProdBarcode();
|
|
|
|
- // 条码、sku、门店都需一致
|
|
|
|
- if (activitySku.equals(sku) && activityProductBarcode.equals(prodBarcode) && couponEntityStoreId.equals(goodsEntity.getStoreId())) {
|
|
|
|
- BigDecimal retailPrice = goodsEntity.getRetailPrice();
|
|
|
|
- if (couponPrice.compareTo(retailPrice) <= 0) {
|
|
|
|
- LOGGER.error("优惠券优惠金额【{}】大于或等于商品【条码:{},sku:{}】的零售价【{}】,请检查优惠券金额设置!", couponPrice, prodBarcode, sku, retailPrice);
|
|
|
|
- throw new ServiceException(String.format("优惠券优惠金额【%s】大于或等于商品【条码:%s,sku:%s】的零售价【%s】,请检查优惠券金额设置!", couponPrice, prodBarcode, sku, retailPrice));
|
|
|
|
- }
|
|
|
|
- BigDecimal discountAfterPrice = retailPrice.subtract(couponPrice);
|
|
|
|
- GoodsDetailsDto goodsDetailsDto = new GoodsDetailsDto();
|
|
|
|
- BeanUtils.copyProperties(goodsEntity, goodsDetailsDto);
|
|
|
|
- // 除了限时促销(需要向海关备案),其它活动都拿海关备案价来算税款
|
|
|
|
- BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity, goodsEntity.getRetailPrice(), goodsService).setScale(3, RoundingMode.HALF_UP);
|
|
|
|
- goodsDetailsDto.setActualPaymentAmount(discountAfterPrice);
|
|
|
|
- goodsDetailsDto.setGoodstaxes(String.valueOf(tax.multiply(new BigDecimal(goodsDetailsDto.getSellVolume()))));
|
|
|
|
- goodsDetailsDto.setActivity("优惠券活动");
|
|
|
|
- goodsDetailsDto.setDiscountedPrice(retailPrice.subtract(discountAfterPrice));
|
|
|
|
- goodsDetailsDtos.add(goodsDetailsDto);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- });
|
|
|
|
- break;
|
|
|
|
- default:
|
|
|
|
- LOGGER.error("未知的优惠券活动分类类型:【{},{}】,请联系管理员!", activityTopicEnum.getTopicCode(), activityTopicEnum.getTopicName());
|
|
|
|
- throw new ServiceException(String.format("未知的优惠券活动分类类型:【%s,%s】,请联系管理员!", activityTopicEnum.getTopicCode(), activityTopicEnum.getTopicName()));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- break;
|
|
|
|
- case LSCX:
|
|
|
|
- // 判断商品是否符合限时特价活动要求
|
|
|
|
- List<MkActivitiesPromotionEntity> mkActivitiesPromotionEntities = mkActivitiesPromotionService.queryListByMkaIdAndStoreId(mkaId.intValue(), storeId);
|
|
|
|
- if (CollectionUtils.isEmpty(mkActivitiesPromotionEntities)) {
|
|
|
|
- LOGGER.error("查询临时促销活动信息结果为空!mka_id:{}, store_id:{}", mkaId, storeId);
|
|
|
|
- throw new ServiceException(String.format("查询临时促销活动信息结果为空!mka_id:%s, store_id:%s", mkaId, storeId));
|
|
|
|
- }
|
|
|
|
- // 限时特价,直接替换实际支付价即可,并且拿特价计算税款
|
|
|
|
- mkActivitiesPromotionEntities.forEach(mkActivitiesPromotionEntity -> {
|
|
|
|
- String entityBarcode = mkActivitiesPromotionEntity.getBarcode();
|
|
|
|
- String entityGoodsSn = mkActivitiesPromotionEntity.getGoodsSn();
|
|
|
|
- BigDecimal activityPrice = mkActivitiesPromotionEntity.getActivityPrice();
|
|
|
|
- String shopSn = mkActivitiesPromotionEntity.getShopSn();
|
|
|
|
- goodsEntities.forEach(goodsEntity -> {
|
|
|
|
- String sku = goodsEntity.getSku();
|
|
|
|
- String prodBarcode = goodsEntity.getProdBarcode();
|
|
|
|
- String storeId2 = String.valueOf(goodsEntity.getStoreId());
|
|
|
|
- BigDecimal retailPrice = goodsEntity.getRetailPrice();
|
|
|
|
- if (entityBarcode.equals(prodBarcode) && entityGoodsSn.equals(sku) && shopSn.equals(storeId2)) {
|
|
|
|
- GoodsDetailsDto goodsDetailsDto = new GoodsDetailsDto();
|
|
|
|
- BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity, activityPrice, goodsService).setScale(3, RoundingMode.HALF_UP);
|
|
|
|
- BeanUtils.copyProperties(goodsDetailsDto, goodsEntity);
|
|
|
|
- goodsDetailsDto.setActualPaymentAmount(activityPrice);
|
|
|
|
- goodsDetailsDto.setGoodstaxes(String.valueOf(tax.multiply(new BigDecimal(goodsDetailsDto.getSellVolume()))));
|
|
|
|
- goodsDetailsDto.setActivity("限时促销");
|
|
|
|
- goodsDetailsDto.setDiscountedPrice(retailPrice.subtract(activityPrice));
|
|
|
|
- goodsDetailsDtos.add(goodsDetailsDto);
|
|
|
|
- }
|
|
|
|
});
|
|
});
|
|
- });
|
|
|
|
- break;
|
|
|
|
- default:
|
|
|
|
- LOGGER.error("未知的满赠活动分类类型:【{},{}】,请联系管理员!", activityTopicEnum.getTopicCode(), activityTopicEnum.getTopicName());
|
|
|
|
- throw new ServiceException(String.format("未知的满赠活动分类类型:【%s,%s】,请联系管理员!", activityTopicEnum.getTopicCode(), activityTopicEnum.getTopicName()));
|
|
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ LOGGER.error("未知的优惠券活动分类类型:【{},{}】,请联系管理员!", activityTopicEnum.getTopicCode(), activityTopicEnum.getTopicName());
|
|
|
|
+ throw new ServiceException(String.format("未知的优惠券活动分类类型:【%s,%s】,请联系管理员!", activityTopicEnum.getTopicCode(), activityTopicEnum.getTopicName()));
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ LOGGER.error("未知的满赠活动分类类型:【{},{}】,请联系管理员!", activityTopicEnum.getTopicCode(), activityTopicEnum.getTopicName());
|
|
|
|
+ throw new ServiceException(String.format("未知的满赠活动分类类型:【%s,%s】,请联系管理员!", activityTopicEnum.getTopicCode(), activityTopicEnum.getTopicName()));
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
- // TODO 计算完活动优惠后,计算积分抵扣。
|
|
|
|
- String memberCode = calculateOrderDiscountPriceVo.getMemberCode();
|
|
|
|
- try {
|
|
|
|
- haiKongMemberTemplate.getMemberInfoByCode("{\"code\":" + memberCode + "}");
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- throw new ServiceException(e);
|
|
|
|
|
|
+ // 计算完活动优惠后,计算积分抵扣。(活动与积分抵扣不互斥)
|
|
|
|
+ if (!org.springframework.util.StringUtils.isEmpty(memberCode)) {
|
|
|
|
+ String memberInfoByCodeResponseJson;
|
|
|
|
+ Response<MemberInfoDTO> response;
|
|
|
|
+ try {
|
|
|
|
+ // 查询会员信息
|
|
|
|
+ memberInfoByCodeResponseJson = haiKongMemberTemplate.getMemberInfoByCode("{\"code\":" + memberCode + "}");
|
|
|
|
+ response = JacksonUtil.fromListJson(memberInfoByCodeResponseJson, new TypeReference<Response<MemberInfoDTO>>() {
|
|
|
|
+ });
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ LOGGER.error("请求会员系统失败或处理响应失败!", e);
|
|
|
|
+ throw new ServiceException(e);
|
|
|
|
+ }
|
|
|
|
+ BigDecimal afterDiscountPrice;
|
|
|
|
+ if (Objects.nonNull(response) && response.getSuccess()) {
|
|
|
|
+ MemberInfoDTO memberInfoDTO = response.getData();
|
|
|
|
+ Integer score = memberInfoDTO.getScore();
|
|
|
|
+ if (Objects.nonNull(score) && score > 0) {
|
|
|
|
+ // 有积分
|
|
|
|
+ afterDiscountPrice = calculatePreferentialPrice(orderTotalPrice, score, storeId, memberCode);
|
|
|
|
+ calculateOrderDiscountPriceResponseVO.setOrderTotalPrice(afterDiscountPrice);
|
|
|
|
+ // 订单完成后再添加积分消费记录,以及同步积分信息
|
|
|
|
+ }
|
|
|
|
+ } else if (Objects.nonNull(response)) {
|
|
|
|
+ LOGGER.error("查询会员信息失败!响应结果:{}", memberInfoByCodeResponseJson);
|
|
|
|
+ throw new ServiceException(String.format("错误码:%s,错误信息:%s", response.getErrorCode(), response.getErrorMessage()));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
- return goodsDetailsDtos;
|
|
|
|
|
|
+ calculateOrderDiscountPriceResponseVO.setGoodsDetailsDtos(goodsDetailsDtos);
|
|
|
|
+ orderTotalPrice = BigDecimal.ZERO;
|
|
|
|
+ for (GoodsDetailsDto goodsDetailsDto : goodsDetailsDtos) {
|
|
|
|
+ orderTotalPrice = orderTotalPrice.add(goodsDetailsDto.getActualPaymentAmount());
|
|
|
|
+ }
|
|
|
|
+ calculateOrderDiscountPriceResponseVO.setOrderTotalPrice(orderTotalPrice);
|
|
|
|
+ return calculateOrderDiscountPriceResponseVO;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 计算积分抵扣后的订单总金额
|
|
|
|
+ * @param orderTotalPrice 订单商品详情
|
|
|
|
+ * @param score 积分
|
|
|
|
+ * @param storeId 门店id
|
|
|
|
+ * @param memberCode 会员码
|
|
|
|
+ * @return 积分抵扣后的订单总金额
|
|
|
|
+ */
|
|
|
|
+ private BigDecimal calculatePreferentialPrice(BigDecimal orderTotalPrice, Integer score, String storeId, String memberCode) {
|
|
|
|
+ // 1. 判断是否有积分,是否需要计算积分抵扣后的价格
|
|
|
|
+ AtomicBoolean isCalculateScorePrice = new AtomicBoolean(false);
|
|
|
|
+ if (Objects.nonNull(score) && score > 0) {
|
|
|
|
+ isCalculateScorePrice.set(true);
|
|
|
|
+ }
|
|
|
|
+ // 2. 计算积分抵扣后的总价格
|
|
|
|
+ if (isCalculateScorePrice.get()) {
|
|
|
|
+ // 3-1. 计算总价的50%,百分比可以进行设置
|
|
|
|
+ BigDecimal halfPrice = orderTotalPrice.multiply(new BigDecimal("0.5")).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
+ Integer scoreLimit = haiKongProperties.getScoreLimit();
|
|
|
|
+ if (score < scoreLimit) {
|
|
|
|
+ LOGGER.warn("用户【{}】的积分数量为:{},最低需要30积分才能抵扣!", memberCode, score);
|
|
|
|
+ return orderTotalPrice;
|
|
|
|
+ } else {
|
|
|
|
+ // 3-2. 计算出积分能抵扣的价格
|
|
|
|
+ int scoreMayDeductionPrice = (int) (score / scoreLimit);
|
|
|
|
+ BigDecimal scoreMayDeductionPriceDecimal = new BigDecimal(scoreMayDeductionPrice);
|
|
|
|
+ // 3-3. 计算积分抵扣后的价格
|
|
|
|
+ if (halfPrice.compareTo(scoreMayDeductionPriceDecimal) > 0) {
|
|
|
|
+ // 积分能抵扣的金额大于订单总额的50%,按50%抵扣
|
|
|
|
+ scoreMayDeductionPriceDecimal = halfPrice;
|
|
|
|
+ }
|
|
|
|
+ orderTotalPrice = orderTotalPrice.subtract(scoreMayDeductionPriceDecimal);
|
|
|
|
+ LOGGER.info("会员【{}】,积分抵扣前剩余:{},积分抵扣订单金额后剩余:{},积分抵扣后的订单总额为:{}", memberCode, score, scoreMayDeductionPriceDecimal.multiply(new BigDecimal(scoreLimit)), orderTotalPrice);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ LOGGER.info("会员【{}】的积分为0,不参加积分抵扣!", memberCode);
|
|
|
|
+ }
|
|
|
|
+ return orderTotalPrice;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* 设置订单数据
|
|
* 设置订单数据
|