【代码评审】商城:满减送订单

This commit is contained in:
YunaiV 2024-08-29 23:30:59 +08:00
parent 7a7ca4293c
commit d60374d646
9 changed files with 19 additions and 12 deletions

View File

@ -36,6 +36,7 @@ public interface CouponApi {
*/ */
CouponRespDTO validateCoupon(@Valid CouponValidReqDTO validReqDTO); CouponRespDTO validateCoupon(@Valid CouponValidReqDTO validReqDTO);
// TODO @puhui999Map<Long, Integer> 优惠劵 会不会好点
/** /**
* 管理员给指定用户批量发送优惠券 * 管理员给指定用户批量发送优惠券
* *

View File

@ -181,6 +181,7 @@ public class CouponServiceImpl implements CouponService {
@Override @Override
public void takeCouponsByAdmin(List<Long> templateIds, List<Integer> counts, Long userId) { public void takeCouponsByAdmin(List<Long> templateIds, List<Integer> counts, Long userId) {
// TODO @puhui999要不要循环调用上面的 takeCoupon 方法按道理说赠送也不会很多张如果某次发卷失败可以打个 error log
// 1. 获得优惠券模版 // 1. 获得优惠券模版
List<CouponTemplateDO> templateList = couponTemplateService.getCouponTemplateList(templateIds); List<CouponTemplateDO> templateList = couponTemplateService.getCouponTemplateList(templateIds);
if (CollUtil.isEmpty(templateList)) { if (CollUtil.isEmpty(templateList)) {

View File

@ -31,9 +31,9 @@ public interface TradeOrderApi {
/** /**
* 取消支付订单 * 取消支付订单
* *
* @param userId 用户编号 * @param userId 用户编号
* @param orderId 订单编号 * @param orderId 订单编号
* @param cancelType 取消类型 * @param cancelType 取消类型
*/ */
void cancelPaidOrder(Long userId, Long orderId, Integer cancelType); void cancelPaidOrder(Long userId, Long orderId, Integer cancelType);

View File

@ -291,6 +291,8 @@ public class TradeOrderDO extends BaseDO {
* VIP 减免金额单位 * VIP 减免金额单位
*/ */
private Integer vipPrice; private Integer vipPrice;
// TODO @puhui999:1建议命名要 giveXXX不然不好理解哈2是不是搞成 Map 好点哈
/** /**
* 赠送的优惠劵编号的数组 * 赠送的优惠劵编号的数组
* *

View File

@ -201,7 +201,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus()); order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus());
order.setProductCount(getSumValue(calculateRespBO.getItems(), TradePriceCalculateRespBO.OrderItem::getCount, Integer::sum)); order.setProductCount(getSumValue(calculateRespBO.getItems(), TradePriceCalculateRespBO.OrderItem::getCount, Integer::sum));
order.setUserIp(getClientIP()).setTerminal(getTerminal()); order.setUserIp(getClientIP()).setTerminal(getTerminal());
// 优惠券 // 使用 + 赠送优惠券
order.setCouponIds(calculateRespBO.getCouponIds()).setCouponCounts(calculateRespBO.getCouponCounts()); order.setCouponIds(calculateRespBO.getCouponIds()).setCouponCounts(calculateRespBO.getCouponCounts());
// 支付 + 退款信息 // 支付 + 退款信息
order.setAdjustPrice(0).setPayStatus(false); order.setAdjustPrice(0).setPayStatus(false);
@ -861,17 +861,17 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void cancelPaidOrder(Long userId, Long orderId, Integer cancelType) { public void cancelPaidOrder(Long userId, Long orderId, Integer cancelType) {
// 1. 这里校验下 cancelType 只允许拼团关闭 // 1.1 这里校验下 cancelType 只允许拼团关闭
if (!TradeOrderCancelTypeEnum.COMBINATION_CLOSE.getType().equals(cancelType)) { if (ObjUtil.notEqual(TradeOrderCancelTypeEnum.COMBINATION_CLOSE.getType(), cancelType)) {
return; return;
} }
// 1.1 检验订单存在 // 1.2 检验订单存在
TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(orderId, userId); TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(orderId, userId);
if (order == null) { if (order == null) {
throw exception(ORDER_NOT_FOUND); throw exception(ORDER_NOT_FOUND);
} }
// 1.2 校验订单是否支付 // 1.3 校验订单是否支付
if (!order.getPayStatus()) { if (!order.getPayStatus()) {
throw exception(ORDER_CANCEL_PAID_FAIL, "已支付"); throw exception(ORDER_CANCEL_PAID_FAIL, "已支付");
} }

View File

@ -51,7 +51,7 @@ public class TradeCouponOrderHandler implements TradeOrderHandler {
if (CollUtil.isEmpty(order.getCouponIds())) { if (CollUtil.isEmpty(order.getCouponIds())) {
return; return;
} }
// TODO @puhui999: 收回优惠券再考虑一下是直接删除券还是改个状态 // TODO @puhui999: 收回优惠券再考虑一下是直接删除券还是改个状态建议是已作废
} }
} }

View File

@ -72,6 +72,7 @@ public class TradePriceCalculateRespBO {
*/ */
private Boolean freeDelivery; private Boolean freeDelivery;
// TODO @puhui999感觉要不要试着改成 Map<Long, Integer> giveCoupons貌似整体会更好理解一点
/** /**
* 赠送的优惠劵编号的数组 * 赠送的优惠劵编号的数组
*/ */

View File

@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.member.api.address.MemberAddressApi; import cn.iocoder.yudao.module.member.api.address.MemberAddressApi;
import cn.iocoder.yudao.module.member.api.address.dto.MemberAddressRespDTO; import cn.iocoder.yudao.module.member.api.address.dto.MemberAddressRespDTO;
import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO;
@ -56,7 +57,7 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator {
return; return;
} }
// 校验是不是存在商品不能门店自提或者不能快递发货的情况就是说配送方式不匹配哈 // 校验是不是存在商品不能门店自提或者不能快递发货的情况就是说配送方式不匹配哈
if (anyMatch(result.getItems(), item -> !item.getDeliveryTypes().contains(param.getDeliveryType()))) { if (CollectionUtils.anyMatch(result.getItems(), item -> !item.getDeliveryTypes().contains(param.getDeliveryType()))) {
throw exception(PRICE_CALCULATE_DELIVERY_PRICE_TYPE_ILLEGAL); throw exception(PRICE_CALCULATE_DELIVERY_PRICE_TYPE_ILLEGAL);
} }

View File

@ -25,6 +25,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
import static cn.iocoder.yudao.module.trade.service.price.calculator.TradePriceCalculatorHelper.formatPrice; import static cn.iocoder.yudao.module.trade.service.price.calculator.TradePriceCalculatorHelper.formatPrice;
// TODO @puhui999相关的单测建议改一改
/** /**
* 满减送活动的 {@link TradePriceCalculator} 实现类 * 满减送活动的 {@link TradePriceCalculator} 实现类
* *
@ -94,8 +95,8 @@ public class TradeRewardActivityPriceCalculator implements TradePriceCalculator
if (rule.getGivePoint()) { if (rule.getGivePoint()) {
List<Integer> dividePoints = TradePriceCalculatorHelper.dividePrice(orderItems, rule.getPoint()); List<Integer> dividePoints = TradePriceCalculatorHelper.dividePrice(orderItems, rule.getPoint());
for (int i = 0; i < orderItems.size(); i++) { for (int i = 0; i < orderItems.size(); i++) {
TradePriceCalculateRespBO.OrderItem orderItem = orderItems.get(i);
// 商品可能赠送了积分所以这里要加上 // 商品可能赠送了积分所以这里要加上
TradePriceCalculateRespBO.OrderItem orderItem = orderItems.get(i);
orderItem.setGivePoint(orderItem.getGivePoint() + dividePoints.get(i)); orderItem.setGivePoint(orderItem.getGivePoint() + dividePoints.get(i));
} }
} }
@ -189,7 +190,7 @@ public class TradeRewardActivityPriceCalculator implements TradePriceCalculator
Integer price = TradePriceCalculatorHelper.calculateTotalPayPrice(orderItems); Integer price = TradePriceCalculatorHelper.calculateTotalPayPrice(orderItems);
assert count != null && price != null; assert count != null && price != null;
// 2. 构建不满足时的提示信息-按最低档规则算 // 2. 构建不满足时的提示信息按最低档规则算
String meetTip = "满减送:购满 {} {},可以减 {} 元"; String meetTip = "满减送:购满 {} {},可以减 {} 元";
List<RewardActivityMatchRespDTO.Rule> rules = new ArrayList<>(rewardActivity.getRules()); List<RewardActivityMatchRespDTO.Rule> rules = new ArrayList<>(rewardActivity.getRules());
rules.sort(Comparator.comparing(RewardActivityMatchRespDTO.Rule::getLimit)); // 按优惠门槛降序 rules.sort(Comparator.comparing(RewardActivityMatchRespDTO.Rule::getLimit)); // 按优惠门槛降序