| | |
| | | import cn.lili.common.utils.CurrencyUtil; |
| | | import cn.lili.common.utils.StringUtils; |
| | | import cn.lili.modules.order.cart.entity.dto.MemberCouponDTO; |
| | | import cn.lili.modules.order.cart.entity.dto.SkuMapDTO; |
| | | import cn.lili.modules.order.cart.entity.dto.TradeDTO; |
| | | import cn.lili.modules.order.cart.entity.enums.RenderStepEnums; |
| | | import cn.lili.modules.order.cart.entity.vo.CartSkuVO; |
| | |
| | | |
| | | //接收具体优惠券信息 |
| | | MemberCoupon coupon = memberCouponDTO.getMemberCoupon(); |
| | | |
| | | Integer goodsNum = tradeDTO.getSkuList().stream().map(CartSkuVO::getNum).reduce(Integer::sum).get(); |
| | | |
| | | //处理一个极端情况,如果优惠券满减金额大于订单金额 |
| | | if (coupon.getCouponType().equals(CouponTypeEnum.PRICE.name()) && coupon.getPrice() > countPrice) { |
| | | if (coupon.getCouponType().equals(CouponTypeEnum.PRICE.name()) |
| | | && coupon.getPrice() > countPrice |
| | | && coupon.getGoodsUseLimitNum() >= goodsNum) { |
| | | //将符合优惠券的金额写入,即最大扣减金额 |
| | | coupon.setPrice(countPrice); |
| | | } |
| | |
| | | * @param memberCouponDTO 用于计算优惠券结算详情 |
| | | */ |
| | | private void renderCouponPrice(Map<String, Double> couponMap, TradeDTO tradeDTO, MemberCoupon coupon, MemberCouponDTO memberCouponDTO) { |
| | | List<SkuMapDTO> skuMapDTOList = new ArrayList<>(); |
| | | for (String skuId : couponMap.keySet()) { |
| | | skuMapDTOList.add(new SkuMapDTO(skuId, couponMap.get(skuId))); |
| | | } |
| | | skuMapDTOList.sort((o1, o2) -> o2.getPrice().compareTo(o1.getPrice())); |
| | | //分发优惠券 |
| | | PromotionPriceUtil.recountPrice(tradeDTO, memberCouponDTO.getSkuDetail(), memberCouponDTO.getMemberCoupon().getPrice(), |
| | | Boolean.TRUE.equals(coupon.getPlatformFlag()) ? |
| | | PromotionTypeEnum.PLATFORM_COUPON : PromotionTypeEnum.COUPON, memberCouponDTO.getMemberCoupon().getCouponId()); |
| | | PromotionPriceUtil.recountPrice(tradeDTO, memberCouponDTO.getSkuDetail(), |
| | | memberCouponDTO.getMemberCoupon().getPrice(), |
| | | Boolean.TRUE.equals(coupon.getPlatformFlag()) ? PromotionTypeEnum.PLATFORM_COUPON : PromotionTypeEnum.COUPON, |
| | | memberCouponDTO.getMemberCoupon().getCouponId(), |
| | | memberCouponDTO.getMemberCoupon().getGoodsUseLimitNum()); |
| | | //如果是平台券 则需要计算商家承担比例 |
| | | if (Boolean.TRUE.equals(coupon.getPlatformFlag()) && coupon.getStoreCommission() > 0) { |
| | | |
| | | Integer i = coupon.getGoodsUseLimitNum(); |
| | | //循环所有优惠券 |
| | | for (String skuId : couponMap.keySet()) { |
| | | for (SkuMapDTO skuMapDTO : skuMapDTOList) { |
| | | |
| | | for (CartSkuVO cartSkuVO : tradeDTO.getSkuList()) { |
| | | //写入平台优惠券承担比例 |
| | | if (cartSkuVO.getGoodsSku().getId().equals(skuId)) { |
| | | //写入店铺承担比例 |
| | | if (cartSkuVO.getGoodsSku().getId().equals(skuMapDTO.getSkuId())) { |
| | | if (i == null) { |
| | | cartSkuVO.getPriceDetailDTO().setSiteCouponPoint(coupon.getStoreCommission()); |
| | | } else { |
| | | if (i > 0) { |
| | | //写入店铺承担比例 |
| | | if (i >= cartSkuVO.getNum()) { |
| | | cartSkuVO.getPriceDetailDTO().setSiteCouponPoint(coupon.getStoreCommission()); |
| | | } else { |
| | | cartSkuVO.getPriceDetailDTO().setSiteCouponPoint(coupon.getStoreCommission() * i / cartSkuVO.getNum()); |
| | | } |
| | | i = i - cartSkuVO.getNum(); |
| | | } else { |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | * @param coupon 优惠券信息 |
| | | */ |
| | | private void renderCouponDiscount(Map<String, Double> couponMap, TradeDTO tradeDTO, MemberCoupon coupon) { |
| | | |
| | | //循环所有优惠券 |
| | | for (String skuId : couponMap.keySet()) { |
| | | |
| | |
| | | } |
| | | priceDetailDTO.setCouponPrice(CurrencyUtil.add(priceDetailDTO.getCouponPrice(), discountCouponPrice)); |
| | | |
| | | } else { |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |