From d7236068b98d9f471fb90a0f296d50fe33167927 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Fri, 4 Oct 2024 13:08:55 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=8A=9F=E8=83=BD=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E3=80=91=E5=95=86=E5=9F=8E:=20APP=20=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E7=A7=AF=E5=88=86=E5=95=86=E5=9F=8E=E6=B4=BB=E5=8A=A8=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E4=BB=B7=E6=A0=BC=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/price/TradePriceServiceImpl.java | 2 +- .../TradePointActivityPriceCalculator.java | 22 ++++++++++++++----- .../TradePointUsePriceCalculator.java | 6 +++++ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/TradePriceServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/TradePriceServiceImpl.java index fcf095055..560056a56 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/TradePriceServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/TradePriceServiceImpl.java @@ -69,7 +69,7 @@ public class TradePriceServiceImpl implements TradePriceService { .buildCalculateResp(calculateReqBO, spuList, skuList); priceCalculators.forEach(calculator -> calculator.calculate(calculateReqBO, calculateRespBO)); // 2.2 如果最终支付金额小于等于 0,则抛出业务异常 - if (calculateRespBO.getPrice().getPayPrice() <= 0) { + if (calculateReqBO.getPointActivityId() == null && calculateRespBO.getPrice().getPayPrice() <= 0) { log.error("[calculatePrice][价格计算不正确,请求 calculateReqDTO({}),结果 priceCalculate({})]", calculateReqBO, calculateRespBO); throw exception(PRICE_CALCULATE_PAY_PRICE_ILLEGAL); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePointActivityPriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePointActivityPriceCalculator.java index a220584c7..3bec8e343 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePointActivityPriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePointActivityPriceCalculator.java @@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.trade.service.price.calculator; import cn.hutool.core.lang.Assert; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import cn.iocoder.yudao.module.member.api.user.MemberUserApi; +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.promotion.api.point.PointActivityApi; import cn.iocoder.yudao.module.promotion.api.point.dto.PointValidateJoinRespDTO; import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; @@ -30,16 +32,26 @@ public class TradePointActivityPriceCalculator implements TradePriceCalculator { @Resource private PointActivityApi pointActivityApi; + @Resource + private MemberUserApi memberUserApi; @Resource private TradeOrderQueryService tradeOrderQueryService; @Override public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) { - // 1. 判断订单类型是否为积分商城活动 + // 1.1 判断订单类型是否为积分商城活动 if (ObjectUtil.notEqual(result.getType(), TradeOrderTypeEnum.POINT.getType())) { return; } + // 1.2 初始化积分 + MemberUserRespDTO user = memberUserApi.getUser(param.getUserId()); + result.setTotalPoint(user.getPoint()).setUsePoint(0); + + // 1.3 校验用户积分余额 + if (user.getPoint() == null || user.getPoint() <= 0) { + return; + } Assert.isTrue(param.getItems().size() == 1, "积分商城兑换商品时,只允许选择一个商品"); // 2. 校验是否可以参与积分商城活动 @@ -49,12 +61,10 @@ public class TradePointActivityPriceCalculator implements TradePriceCalculator { orderItem.getSkuId(), orderItem.getCount()); // 3.1 记录优惠明细 - int discountPrice = 0; + int discountPrice = orderItem.getPayPrice(); // 情况一:单使用积分兑换 Assert.isTrue(activity.getPoint() >= 1, "积分商城商品兑换积分必须大于 1"); - // 情况一:单使用积分兑换 - if (activity.getPrice() == null || activity.getPrice() == 0) { - discountPrice = orderItem.getPayPrice(); - } else { // 情况二:积分 + 金额 + result.setUsePoint(activity.getPoint()); + if (activity.getPrice() != null && activity.getPrice() > 0) { // 情况二:积分 + 金额 discountPrice = orderItem.getPayPrice() - activity.getPrice() * orderItem.getCount(); } TradePriceCalculatorHelper.addPromotion(result, orderItem, diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePointUsePriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePointUsePriceCalculator.java index 8dc2b30d0..055515351 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePointUsePriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePointUsePriceCalculator.java @@ -1,12 +1,14 @@ package cn.iocoder.yudao.module.trade.service.price.calculator; import cn.hutool.core.util.BooleanUtil; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.module.member.api.config.MemberConfigApi; import cn.iocoder.yudao.module.member.api.config.dto.MemberConfigRespDTO; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; import jakarta.annotation.Resource; @@ -37,6 +39,10 @@ public class TradePointUsePriceCalculator implements TradePriceCalculator { @Override public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) { + // 判断订单类型是否不为积分商城活动 + if (ObjectUtil.equal(result.getType(), TradeOrderTypeEnum.POINT.getType())) { + return; + } // 0. 初始化积分 MemberUserRespDTO user = memberUserApi.getUser(param.getUserId()); result.setTotalPoint(user.getPoint()).setUsePoint(0);