|  | @@ -4086,19 +4086,22 @@ public class OrderServiceImpl implements OrderService {
 | 
	
		
			
				|  |  |          List<Integer> categoryIdList = goodsEntities.stream().map(GoodsEntity::getCategoryId).collect(Collectors.toList());
 | 
	
		
			
				|  |  |          // 活动互斥标识
 | 
	
		
			
				|  |  |          AtomicBoolean activityFlag = new AtomicBoolean(true);
 | 
	
		
			
				|  |  | -        // 判断活动类型,并确定购物栏中商品是否满足活动条件
 | 
	
		
			
				|  |  | -        mkActivitiesEntityList.forEach(mkActivitiesEntity -> {
 | 
	
		
			
				|  |  | +        // 判断活动类型并排序,再确定购物栏中商品是否满足活动条件
 | 
	
		
			
				|  |  | +        mkActivitiesEntityList.stream().sorted().forEach(mkActivitiesEntity -> {
 | 
	
		
			
				|  |  |              String mkaStoreId = mkActivitiesEntity.getMkaStoreId();
 | 
	
		
			
				|  |  |              Long mkaId = mkActivitiesEntity.getMkaId();
 | 
	
		
			
				|  |  |              String mkaTopic = mkActivitiesEntity.getMkaTopic();
 | 
	
		
			
				|  |  | -            Constants.ActivityTopicEnum activityTopicEnum = Constants.ActivityTopicEnum.valueOf(mkaTopic);
 | 
	
		
			
				|  |  | +            if (org.springframework.util.StringUtils.isEmpty(mkaTopic)) {
 | 
	
		
			
				|  |  | +                LOGGER.error("活动主题为空!请检查活动设置!");
 | 
	
		
			
				|  |  | +                throw new ServiceException("价活动主题为空!请检查活动设置!");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            Constants.ActivityTopicEnum activityTopicEnum = Constants.ActivityTopicEnum.valueOf(mkaTopic.toUpperCase());
 | 
	
		
			
				|  |  |              // 活动之间的优先级:特价>打折>满减/满赠>优惠券>积分抵扣
 | 
	
		
			
				|  |  |              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 -> {
 | 
	
	
		
			
				|  | @@ -4129,148 +4132,140 @@ public class OrderServiceImpl implements OrderService {
 | 
	
		
			
				|  |  |                  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);
 | 
	
		
			
				|  |  | +                } else {
 | 
	
		
			
				|  |  | +                    Long brandId = mkActivitiesFullGiftEntity.getBrandId();
 | 
	
		
			
				|  |  | +                    Long categoryId = mkActivitiesFullGiftEntity.getCategoryId();
 | 
	
		
			
				|  |  | +                    Constants.ActivityType fullGiftActivityType = Constants.ActivityType.valueOf(mkActivitiesFullGiftEntity.getFullGiftType());
 | 
	
		
			
				|  |  | +                    switch (fullGiftActivityType) {
 | 
	
		
			
				|  |  | +                        case BRAND:
 | 
	
		
			
				|  |  | +                            if (Objects.isNull(brandId)) {
 | 
	
		
			
				|  |  | +                                LOGGER.error("满赠活动品牌编号为空,计算失败!请检查活动设置!活动ID:{}", mkActivitiesFullGiftEntity.getMkaId());
 | 
	
		
			
				|  |  | +                                throw new ServiceException(String.format("满赠活动品牌编号为空,计算失败!请检查活动设置!活动ID:%s", mkActivitiesFullGiftEntity.getMkaId()));
 | 
	
		
			
				|  |  |                              }
 | 
	
		
			
				|  |  | -                        }
 | 
	
		
			
				|  |  | -                        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);
 | 
	
		
			
				|  |  | +                            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;
 | 
	
		
			
				|  |  | -                    default:
 | 
	
		
			
				|  |  | -                        LOGGER.error("未知满赠类型【{},{}】!请联系管理员!", fullGiftActivityType.getActivityType(), fullGiftActivityType.getActivityTypeCode());
 | 
	
		
			
				|  |  | -                        throw new ServiceException(String.format("未知满赠类型【%s,%s】!请联系管理员!", fullGiftActivityType.getActivityType(), fullGiftActivityType.getActivityTypeCode()));
 | 
	
		
			
				|  |  | +                            break;
 | 
	
		
			
				|  |  | +                        case CATEGORY:
 | 
	
		
			
				|  |  | +                            if (Objects.isNull(categoryId)) {
 | 
	
		
			
				|  |  | +                                LOGGER.error("满赠活动分类编号为空,计算失败!请检查活动设置!活动ID:{}", mkActivitiesFullGiftEntity.getMkaId());
 | 
	
		
			
				|  |  | +                                throw new ServiceException(String.format("满赠活动分类编号为空,计算失败!请检查活动设置!活动ID:%s", mkActivitiesFullGiftEntity.getMkaId()));
 | 
	
		
			
				|  |  | +                            }
 | 
	
		
			
				|  |  | +                            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()) {
 | 
	
		
			
				|  |  | +            } else if (activityTopicEnum == Constants.ActivityTopicEnum.YHQ && activityFlag.get()) {
 | 
	
		
			
				|  |  |                  // 判断商品是否符合优惠券活动要求
 | 
	
		
			
				|  |  | -                Map<String, Object> params = new HashMap<>();
 | 
	
		
			
				|  |  | -                params.put("shop_sn", storeId);
 | 
	
		
			
				|  |  | -                params.put("mka_id", mkaId);
 | 
	
		
			
				|  |  | -                List<MkActivitiesCouponEntity> mkActivitiesCouponEntities = mkActivitiesCouponService.queryList(params);
 | 
	
		
			
				|  |  | +                List<MkActivitiesCouponEntity> mkActivitiesCouponEntities = mkActivitiesCouponService.queryListByMkaIdAndStoreId(mkaId, storeId);
 | 
	
		
			
				|  |  |                  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);
 | 
	
		
			
				|  |  | +                    LOGGER.error("查询优惠券活动信息结果为空!活动ID:{}, 门店编号:{}", mkaId, storeId);
 | 
	
		
			
				|  |  | +                } else {
 | 
	
		
			
				|  |  | +                    MkActivitiesCouponEntity mkActivitiesCouponEntity = mkActivitiesCouponEntities.get(0);
 | 
	
		
			
				|  |  | +                    Integer couponEntityBrandId = mkActivitiesCouponEntity.getBrandId();
 | 
	
		
			
				|  |  | +                    Integer couponEntityCategoryId = mkActivitiesCouponEntity.getCategoryId();
 | 
	
		
			
				|  |  | +                    String shopSn = mkActivitiesCouponEntity.getShopSn();
 | 
	
		
			
				|  |  | +                    if (org.springframework.util.StringUtils.isEmpty(shopSn)) {
 | 
	
		
			
				|  |  | +                        LOGGER.error("优惠券活动门店编号为空,计算失败!请检查活动设置!活动ID:{}", mkActivitiesCouponEntity.getMkaId());
 | 
	
		
			
				|  |  | +                        throw new ServiceException(String.format("优惠券活动门店编号为空,计算失败!请检查活动设置!活动ID:%s", mkActivitiesCouponEntity.getMkaId()));
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    Integer couponEntityStoreId = Integer.parseInt(shopSn);
 | 
	
		
			
				|  |  | +                    BigDecimal couponPrice = mkActivitiesCouponEntity.getCouponPrice();
 | 
	
		
			
				|  |  | +                    Constants.ActivityType couponActivityType = Constants.ActivityType.customValueOf(mkActivitiesCouponEntity.getActivityType());
 | 
	
		
			
				|  |  | +                    if (Objects.isNull(couponActivityType)) {
 | 
	
		
			
				|  |  | +                        LOGGER.error("错误的优惠券优惠类型:【{}】,请检查活动设置!活动ID:{}", mkActivitiesCouponEntity.getActivityType(), mkActivitiesCouponEntity.getMkaId());
 | 
	
		
			
				|  |  | +                        throw new ServiceException(String.format("错误的优惠券优惠类型:【%s】,请检查活动设置!活动ID:%s", mkActivitiesCouponEntity.getActivityType(), mkActivitiesCouponEntity.getMkaId()));
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    switch (couponActivityType) {
 | 
	
		
			
				|  |  | +                        case BRAND:
 | 
	
		
			
				|  |  | +                            if (Objects.isNull(couponEntityBrandId)) {
 | 
	
		
			
				|  |  | +                                LOGGER.error("优惠券活动品牌编号为空,计算失败!请检查活动设置!活动ID:{}", mkActivitiesCouponEntity.getMkaId());
 | 
	
		
			
				|  |  | +                                throw new ServiceException(String.format("优惠券活动品牌编号为空,计算失败!请检查活动设置!活动ID:%s", mkActivitiesCouponEntity.getMkaId()));
 | 
	
		
			
				|  |  |                              }
 | 
	
		
			
				|  |  | -                        });
 | 
	
		
			
				|  |  | -                        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));
 | 
	
		
			
				|  |  | +                            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);
 | 
	
		
			
				|  |  |                                  }
 | 
	
		
			
				|  |  | -                                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 CATEGORY:
 | 
	
		
			
				|  |  | +                            if (Objects.isNull(couponEntityCategoryId)) {
 | 
	
		
			
				|  |  | +                                LOGGER.error("优惠券活动分类编号为空,计算失败!请检查活动设置!活动ID:{}", mkActivitiesCouponEntity.getMkaId());
 | 
	
		
			
				|  |  | +                                throw new ServiceException(String.format("优惠券活动分类编号为空,计算失败!请检查活动设置!活动ID:%s", mkActivitiesCouponEntity.getMkaId()));
 | 
	
		
			
				|  |  |                              }
 | 
	
		
			
				|  |  | -                        });
 | 
	
		
			
				|  |  | -                        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())) {
 | 
	
		
			
				|  |  | +                                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));
 | 
	
	
		
			
				|  | @@ -4288,15 +4283,45 @@ public class OrderServiceImpl implements OrderService {
 | 
	
		
			
				|  |  |                                      activityFlag.set(false);
 | 
	
		
			
				|  |  |                                  }
 | 
	
		
			
				|  |  |                              });
 | 
	
		
			
				|  |  | -                        });
 | 
	
		
			
				|  |  | -                        break;
 | 
	
		
			
				|  |  | -                    default:
 | 
	
		
			
				|  |  | -                        LOGGER.error("未知的优惠券活动分类类型:【{},{}】,请联系管理员!", activityTopicEnum.getTopicCode(), activityTopicEnum.getTopicName());
 | 
	
		
			
				|  |  | -                        throw new ServiceException(String.format("未知的优惠券活动分类类型:【%s,%s】,请联系管理员!", activityTopicEnum.getTopicCode(), activityTopicEnum.getTopicName()));
 | 
	
		
			
				|  |  | +                            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);
 | 
	
		
			
				|  |  | +                                        activityFlag.set(false);
 | 
	
		
			
				|  |  | +                                    }
 | 
	
		
			
				|  |  | +                                });
 | 
	
		
			
				|  |  | +                            });
 | 
	
		
			
				|  |  | +                            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()));
 | 
	
		
			
				|  |  | +                LOGGER.error("未知的活动类型:【{},{}】,请检查活动设置!!", activityTopicEnum.getTopicCode(), activityTopicEnum.getTopicName());
 | 
	
		
			
				|  |  | +                throw new ServiceException(String.format("未知的活动类型:【%s,%s】,请检查活动设置!!", activityTopicEnum.getTopicCode(), activityTopicEnum.getTopicName()));
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          });
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -4325,10 +4350,14 @@ public class OrderServiceImpl implements OrderService {
 | 
	
		
			
				|  |  |                  if (Objects.nonNull(score) && score > 0) {
 | 
	
		
			
				|  |  |                      // 有积分
 | 
	
		
			
				|  |  |                      afterDiscountPrice = calculatePreferentialPrice(orderTotalPrice, score, storeId, memberCode);
 | 
	
		
			
				|  |  | +                    LOGGER.info("会员【{}】,当前积分:{},积分抵扣后的订单金额:{},积分抵扣前的订单金额:{}", memberCode, score, afterDiscountPrice, orderTotalPrice);
 | 
	
		
			
				|  |  |                      calculateOrderDiscountPriceResponseVO.setOrderTotalPrice(afterDiscountPrice);
 | 
	
		
			
				|  |  |                      calculateOrderDiscountPriceResponseVO.setGoodsDetailsDtos(goodsDetailsDtos);
 | 
	
		
			
				|  |  |                      // 订单完成后再添加积分消费记录,以及同步积分信息
 | 
	
		
			
				|  |  |                      return calculateOrderDiscountPriceResponseVO;
 | 
	
		
			
				|  |  | +                } else {
 | 
	
		
			
				|  |  | +                    LOGGER.error("会员【{}】积分为0,积分抵扣失败!", memberCode);
 | 
	
		
			
				|  |  | +                    throw new ServiceException(String.format("会员【%s】积分为0,积分抵扣失败!", memberCode));
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              } else {
 | 
	
		
			
				|  |  |                  LOGGER.error("查询会员信息失败!响应结果:{}", memberInfoByCodeResponseJson);
 | 
	
	
		
			
				|  | @@ -4376,7 +4405,7 @@ public class OrderServiceImpl implements OrderService {
 | 
	
		
			
				|  |  |                      scoreMayDeductionPriceDecimal = halfPrice;
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  orderTotalPrice = orderTotalPrice.subtract(scoreMayDeductionPriceDecimal);
 | 
	
		
			
				|  |  | -                LOGGER.info("会员【{}】,积分抵扣前剩余:{},积分抵扣订单金额后剩余:{},积分抵扣后的订单总额为:{}", memberCode, score, (score - scoreMayDeductionPriceDecimal.multiply(new BigDecimal(scoreLimit)).intValue()), orderTotalPrice);
 | 
	
		
			
				|  |  | +                LOGGER.info("会员【{}】,当前积分:{},抵扣订单金额后剩余积分:{}", memberCode, score, (score - scoreMayDeductionPriceDecimal.multiply(new BigDecimal(scoreLimit)).intValue()));
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          } else {
 | 
	
		
			
				|  |  |              LOGGER.info("会员【{}】的积分为0,不参加积分抵扣!", memberCode);
 |