mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 07:11:52 +08:00
【功能完善】商城: APP 完善积分商城活动订单价格计算
This commit is contained in:
parent
f01c600492
commit
d7236068b9
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user