7.1 修复一些bug、补充功能
This commit is contained in:
parent
bf96839cae
commit
16433ffdc2
@ -1,22 +1,30 @@
|
||||
package edu.whut.domain.activity.service.discount;
|
||||
|
||||
import edu.whut.domain.activity.adapter.repository.IActivityRepository;
|
||||
import edu.whut.domain.activity.model.valobj.DiscountTypeEnum;
|
||||
import edu.whut.domain.activity.model.valobj.GroupBuyActivityDiscountVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 折扣计算服务抽象类
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public abstract class AbstractDiscountCalculateService implements IDiscountCalculateService {
|
||||
|
||||
|
||||
final protected IActivityRepository repository;
|
||||
@Override
|
||||
public BigDecimal calculate(String userId, BigDecimal originalPrice, GroupBuyActivityDiscountVO.GroupBuyDiscount groupBuyDiscount) {
|
||||
// 1. 人群标签过滤, 只有当 discountType = TAG 时才检查用户是否在标签范围内
|
||||
if (DiscountTypeEnum.TAG.equals(groupBuyDiscount.getDiscountType())){
|
||||
boolean isCrowdRange = filterTagId(userId, groupBuyDiscount.getTagId());
|
||||
if (!isCrowdRange) return originalPrice; // 不在标签范围 → 无优惠
|
||||
if (!isCrowdRange) {
|
||||
log.info("折扣优惠计算拦截,用户不再优惠人群标签范围内 userId:{}", userId);
|
||||
return originalPrice;
|
||||
}
|
||||
}
|
||||
// 2. 折扣优惠计算
|
||||
return doCalculate(originalPrice, groupBuyDiscount);
|
||||
@ -24,8 +32,7 @@ public abstract class AbstractDiscountCalculateService implements IDiscountCalcu
|
||||
|
||||
// 人群过滤 - 限定人群优惠
|
||||
private boolean filterTagId(String userId, String tagId) {
|
||||
|
||||
return true;
|
||||
return repository.isTagCrowdRange(tagId, userId);
|
||||
}
|
||||
//留给子类实现的抽象方法,真正去算“直减多少 / 满减多少 / N 元购”
|
||||
protected abstract BigDecimal doCalculate(BigDecimal originalPrice, GroupBuyActivityDiscountVO.GroupBuyDiscount groupBuyDiscount);
|
||||
|
@ -98,9 +98,9 @@ public class MarketNode extends AbstractGroupBuyMarketSupport<MarketProductEntit
|
||||
}
|
||||
|
||||
// 折扣价格
|
||||
BigDecimal deductionPrice = discountCalculateService.calculate(requestParameter.getUserId(), skuVO.getOriginalPrice(), groupBuyDiscount);
|
||||
//设置折扣价格到上下文中
|
||||
dynamicContext.setDeductionPrice(deductionPrice);
|
||||
BigDecimal payPrice = discountCalculateService.calculate(requestParameter.getUserId(), skuVO.getOriginalPrice(), groupBuyDiscount);
|
||||
dynamicContext.setDeductionPrice(skuVO.getOriginalPrice().subtract(payPrice));
|
||||
dynamicContext.setPayPrice(payPrice);
|
||||
|
||||
return router(requestParameter, dynamicContext);
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import java.util.Objects;
|
||||
@ -41,7 +42,7 @@ import java.util.Objects;
|
||||
@RestController
|
||||
@CrossOrigin("*")
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/v1/gbm/trade/")
|
||||
@RequestMapping("/api/v1/gbm/trade")
|
||||
public class MarketTradeController implements IMarketTradeService {
|
||||
|
||||
private final IIndexGroupBuyMarketService indexGroupBuyMarketService;
|
||||
@ -54,6 +55,7 @@ public class MarketTradeController implements IMarketTradeService {
|
||||
* @param lockMarketPayOrderRequestDTO 请求参数
|
||||
* @return 统一响应结果
|
||||
*/
|
||||
@PostMapping("/lock_market_pay_order")
|
||||
@Override
|
||||
public Response<LockMarketPayOrderResponseDTO> lockMarketPayOrder(LockMarketPayOrderRequestDTO lockMarketPayOrderRequestDTO) {
|
||||
try {
|
||||
@ -108,6 +110,15 @@ public class MarketTradeController implements IMarketTradeService {
|
||||
.goodsId(goodsId)
|
||||
.activityId(activityId)
|
||||
.build());
|
||||
|
||||
// 人群限定
|
||||
if (!trialBalance.getIsVisible() || !trialBalance.getIsEnable()){
|
||||
return Response.<LockMarketPayOrderResponseDTO>builder()
|
||||
.code(ResponseCode.E0007.getCode())
|
||||
.info(ResponseCode.E0007.getInfo())
|
||||
.build();
|
||||
}
|
||||
|
||||
//获取拼团活动配置信息
|
||||
GroupBuyActivityDiscountVO discountVO = trialBalance.getGroupBuyActivityDiscountVO();
|
||||
|
||||
@ -129,6 +140,7 @@ public class MarketTradeController implements IMarketTradeService {
|
||||
.goodsName(trialBalance.getGoodsName())
|
||||
.originalPrice(trialBalance.getOriginalPrice())
|
||||
.deductionPrice(trialBalance.getDeductionPrice())
|
||||
.payPrice(trialBalance.getPayPrice())
|
||||
.outTradeNo(outTradeNo)
|
||||
.build());
|
||||
|
||||
|
@ -19,6 +19,10 @@ public enum ResponseCode {
|
||||
E0004("E0004", "拼团活动切量拦截"),
|
||||
E0005("E0005", "拼团组队失败,记录更新为0"),
|
||||
E0006("E0006", "拼团组队完结,锁单量已达成"),
|
||||
E0007("E0007", "拼团人群限定,不可参与"),
|
||||
E0101("E0101", "拼团活动未生效"),
|
||||
E0102("E0102", "不在拼团活动有效时间内"),
|
||||
E0103("E0103", "当前用户参与此拼团次数已达上限"),
|
||||
;
|
||||
|
||||
private String code;
|
||||
|
Loading…
x
Reference in New Issue
Block a user