Commit d60374d646e8087b1e3be0d405d2c4f09ddecc0c
1 parent
7a7ca429
【代码评审】商城:满减送订单
Showing
9 changed files
with
19 additions
and
12 deletions
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/coupon/CouponApi.java
| @@ -36,6 +36,7 @@ public interface CouponApi { | @@ -36,6 +36,7 @@ public interface CouponApi { | ||
| 36 | */ | 36 | */ |
| 37 | CouponRespDTO validateCoupon(@Valid CouponValidReqDTO validReqDTO); | 37 | CouponRespDTO validateCoupon(@Valid CouponValidReqDTO validReqDTO); |
| 38 | 38 | ||
| 39 | + // TODO @puhui999:Map<Long, Integer> 优惠劵 会不会好点。 | ||
| 39 | /** | 40 | /** |
| 40 | * 【管理员】给指定用户批量发送优惠券 | 41 | * 【管理员】给指定用户批量发送优惠券 |
| 41 | * | 42 | * |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponServiceImpl.java
| @@ -181,6 +181,7 @@ public class CouponServiceImpl implements CouponService { | @@ -181,6 +181,7 @@ public class CouponServiceImpl implements CouponService { | ||
| 181 | 181 | ||
| 182 | @Override | 182 | @Override |
| 183 | public void takeCouponsByAdmin(List<Long> templateIds, List<Integer> counts, Long userId) { | 183 | public void takeCouponsByAdmin(List<Long> templateIds, List<Integer> counts, Long userId) { |
| 184 | + // TODO @puhui999:要不要循环调用上面的 takeCoupon 方法?按道理说,赠送也不会很多张。如果某次发卷失败,可以打个 error log; | ||
| 184 | // 1. 获得优惠券模版 | 185 | // 1. 获得优惠券模版 |
| 185 | List<CouponTemplateDO> templateList = couponTemplateService.getCouponTemplateList(templateIds); | 186 | List<CouponTemplateDO> templateList = couponTemplateService.getCouponTemplateList(templateIds); |
| 186 | if (CollUtil.isEmpty(templateList)) { | 187 | if (CollUtil.isEmpty(templateList)) { |
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java
| @@ -31,9 +31,9 @@ public interface TradeOrderApi { | @@ -31,9 +31,9 @@ public interface TradeOrderApi { | ||
| 31 | /** | 31 | /** |
| 32 | * 取消支付订单 | 32 | * 取消支付订单 |
| 33 | * | 33 | * |
| 34 | - * @param userId 用户编号 | ||
| 35 | - * @param orderId 订单编号 | ||
| 36 | - * @param cancelType 取消类型 | 34 | + * @param userId 用户编号 |
| 35 | + * @param orderId 订单编号 | ||
| 36 | + * @param cancelType 取消类型 | ||
| 37 | */ | 37 | */ |
| 38 | void cancelPaidOrder(Long userId, Long orderId, Integer cancelType); | 38 | void cancelPaidOrder(Long userId, Long orderId, Integer cancelType); |
| 39 | 39 |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java
| @@ -291,6 +291,8 @@ public class TradeOrderDO extends BaseDO { | @@ -291,6 +291,8 @@ public class TradeOrderDO extends BaseDO { | ||
| 291 | * VIP 减免金额,单位:分 | 291 | * VIP 减免金额,单位:分 |
| 292 | */ | 292 | */ |
| 293 | private Integer vipPrice; | 293 | private Integer vipPrice; |
| 294 | + | ||
| 295 | + // TODO @puhui999::1)建议命名要 giveXXX;不然不好理解哈;2)是不是搞成 Map 好点哈。 | ||
| 294 | /** | 296 | /** |
| 295 | * 赠送的优惠劵编号的数组 | 297 | * 赠送的优惠劵编号的数组 |
| 296 | * | 298 | * |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java
| @@ -201,7 +201,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | @@ -201,7 +201,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | ||
| 201 | order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus()); | 201 | order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus()); |
| 202 | order.setProductCount(getSumValue(calculateRespBO.getItems(), TradePriceCalculateRespBO.OrderItem::getCount, Integer::sum)); | 202 | order.setProductCount(getSumValue(calculateRespBO.getItems(), TradePriceCalculateRespBO.OrderItem::getCount, Integer::sum)); |
| 203 | order.setUserIp(getClientIP()).setTerminal(getTerminal()); | 203 | order.setUserIp(getClientIP()).setTerminal(getTerminal()); |
| 204 | - // 优惠券 | 204 | + // 使用 + 赠送优惠券 |
| 205 | order.setCouponIds(calculateRespBO.getCouponIds()).setCouponCounts(calculateRespBO.getCouponCounts()); | 205 | order.setCouponIds(calculateRespBO.getCouponIds()).setCouponCounts(calculateRespBO.getCouponCounts()); |
| 206 | // 支付 + 退款信息 | 206 | // 支付 + 退款信息 |
| 207 | order.setAdjustPrice(0).setPayStatus(false); | 207 | order.setAdjustPrice(0).setPayStatus(false); |
| @@ -861,17 +861,17 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | @@ -861,17 +861,17 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | ||
| 861 | @Override | 861 | @Override |
| 862 | @Transactional(rollbackFor = Exception.class) | 862 | @Transactional(rollbackFor = Exception.class) |
| 863 | public void cancelPaidOrder(Long userId, Long orderId, Integer cancelType) { | 863 | public void cancelPaidOrder(Long userId, Long orderId, Integer cancelType) { |
| 864 | - // 1. 这里校验下 cancelType 只允许拼团关闭; | ||
| 865 | - if (!TradeOrderCancelTypeEnum.COMBINATION_CLOSE.getType().equals(cancelType)) { | 864 | + // 1.1 这里校验下 cancelType 只允许拼团关闭; |
| 865 | + if (ObjUtil.notEqual(TradeOrderCancelTypeEnum.COMBINATION_CLOSE.getType(), cancelType)) { | ||
| 866 | return; | 866 | return; |
| 867 | } | 867 | } |
| 868 | - // 1.1 检验订单存在 | 868 | + // 1.2 检验订单存在 |
| 869 | TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(orderId, userId); | 869 | TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(orderId, userId); |
| 870 | if (order == null) { | 870 | if (order == null) { |
| 871 | throw exception(ORDER_NOT_FOUND); | 871 | throw exception(ORDER_NOT_FOUND); |
| 872 | } | 872 | } |
| 873 | 873 | ||
| 874 | - // 1.2 校验订单是否支付 | 874 | + // 1.3 校验订单是否支付 |
| 875 | if (!order.getPayStatus()) { | 875 | if (!order.getPayStatus()) { |
| 876 | throw exception(ORDER_CANCEL_PAID_FAIL, "已支付"); | 876 | throw exception(ORDER_CANCEL_PAID_FAIL, "已支付"); |
| 877 | } | 877 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCouponOrderHandler.java
| @@ -51,7 +51,7 @@ public class TradeCouponOrderHandler implements TradeOrderHandler { | @@ -51,7 +51,7 @@ public class TradeCouponOrderHandler implements TradeOrderHandler { | ||
| 51 | if (CollUtil.isEmpty(order.getCouponIds())) { | 51 | if (CollUtil.isEmpty(order.getCouponIds())) { |
| 52 | return; | 52 | return; |
| 53 | } | 53 | } |
| 54 | - // TODO @puhui999: 收回优惠券再考虑一下,是直接删除券还是改个状态 | 54 | + // TODO @puhui999: 收回优惠券再考虑一下,是直接删除券还是改个状态;建议是【已作废】 |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | } | 57 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateRespBO.java
| @@ -72,6 +72,7 @@ public class TradePriceCalculateRespBO { | @@ -72,6 +72,7 @@ public class TradePriceCalculateRespBO { | ||
| 72 | */ | 72 | */ |
| 73 | private Boolean freeDelivery; | 73 | private Boolean freeDelivery; |
| 74 | 74 | ||
| 75 | + // TODO @puhui999:感觉要不要试着改成 Map<Long, Integer> giveCoupons?貌似整体会更好理解一点。 | ||
| 75 | /** | 76 | /** |
| 76 | * 赠送的优惠劵编号的数组 | 77 | * 赠送的优惠劵编号的数组 |
| 77 | */ | 78 | */ |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java
| @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil; | @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil; | ||
| 4 | import cn.hutool.core.lang.Assert; | 4 | import cn.hutool.core.lang.Assert; |
| 5 | import cn.hutool.core.util.StrUtil; | 5 | import cn.hutool.core.util.StrUtil; |
| 6 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 6 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 7 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | ||
| 7 | import cn.iocoder.yudao.module.member.api.address.MemberAddressApi; | 8 | import cn.iocoder.yudao.module.member.api.address.MemberAddressApi; |
| 8 | import cn.iocoder.yudao.module.member.api.address.dto.MemberAddressRespDTO; | 9 | import cn.iocoder.yudao.module.member.api.address.dto.MemberAddressRespDTO; |
| 9 | import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; | 10 | import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; |
| @@ -56,7 +57,7 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { | @@ -56,7 +57,7 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { | ||
| 56 | return; | 57 | return; |
| 57 | } | 58 | } |
| 58 | // 校验是不是存在商品不能门店自提,或者不能快递发货的情况。就是说,配送方式不匹配哈 | 59 | // 校验是不是存在商品不能门店自提,或者不能快递发货的情况。就是说,配送方式不匹配哈 |
| 59 | - if (anyMatch(result.getItems(), item -> !item.getDeliveryTypes().contains(param.getDeliveryType()))) { | 60 | + if (CollectionUtils.anyMatch(result.getItems(), item -> !item.getDeliveryTypes().contains(param.getDeliveryType()))) { |
| 60 | throw exception(PRICE_CALCULATE_DELIVERY_PRICE_TYPE_ILLEGAL); | 61 | throw exception(PRICE_CALCULATE_DELIVERY_PRICE_TYPE_ILLEGAL); |
| 61 | } | 62 | } |
| 62 | 63 |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeRewardActivityPriceCalculator.java
| @@ -25,6 +25,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. | @@ -25,6 +25,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. | ||
| 25 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; | 25 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; |
| 26 | import static cn.iocoder.yudao.module.trade.service.price.calculator.TradePriceCalculatorHelper.formatPrice; | 26 | import static cn.iocoder.yudao.module.trade.service.price.calculator.TradePriceCalculatorHelper.formatPrice; |
| 27 | 27 | ||
| 28 | +// TODO @puhui999:相关的单测,建议改一改 | ||
| 28 | /** | 29 | /** |
| 29 | * 满减送活动的 {@link TradePriceCalculator} 实现类 | 30 | * 满减送活动的 {@link TradePriceCalculator} 实现类 |
| 30 | * | 31 | * |
| @@ -94,8 +95,8 @@ public class TradeRewardActivityPriceCalculator implements TradePriceCalculator | @@ -94,8 +95,8 @@ public class TradeRewardActivityPriceCalculator implements TradePriceCalculator | ||
| 94 | if (rule.getGivePoint()) { | 95 | if (rule.getGivePoint()) { |
| 95 | List<Integer> dividePoints = TradePriceCalculatorHelper.dividePrice(orderItems, rule.getPoint()); | 96 | List<Integer> dividePoints = TradePriceCalculatorHelper.dividePrice(orderItems, rule.getPoint()); |
| 96 | for (int i = 0; i < orderItems.size(); i++) { | 97 | for (int i = 0; i < orderItems.size(); i++) { |
| 97 | - TradePriceCalculateRespBO.OrderItem orderItem = orderItems.get(i); | ||
| 98 | // 商品可能赠送了积分,所以这里要加上 | 98 | // 商品可能赠送了积分,所以这里要加上 |
| 99 | + TradePriceCalculateRespBO.OrderItem orderItem = orderItems.get(i); | ||
| 99 | orderItem.setGivePoint(orderItem.getGivePoint() + dividePoints.get(i)); | 100 | orderItem.setGivePoint(orderItem.getGivePoint() + dividePoints.get(i)); |
| 100 | } | 101 | } |
| 101 | } | 102 | } |
| @@ -189,7 +190,7 @@ public class TradeRewardActivityPriceCalculator implements TradePriceCalculator | @@ -189,7 +190,7 @@ public class TradeRewardActivityPriceCalculator implements TradePriceCalculator | ||
| 189 | Integer price = TradePriceCalculatorHelper.calculateTotalPayPrice(orderItems); | 190 | Integer price = TradePriceCalculatorHelper.calculateTotalPayPrice(orderItems); |
| 190 | assert count != null && price != null; | 191 | assert count != null && price != null; |
| 191 | 192 | ||
| 192 | - // 2. 构建不满足时的提示信息-按最低档规则算 | 193 | + // 2. 构建不满足时的提示信息:按最低档规则算 |
| 193 | String meetTip = "满减送:购满 {} {},可以减 {} 元"; | 194 | String meetTip = "满减送:购满 {} {},可以减 {} 元"; |
| 194 | List<RewardActivityMatchRespDTO.Rule> rules = new ArrayList<>(rewardActivity.getRules()); | 195 | List<RewardActivityMatchRespDTO.Rule> rules = new ArrayList<>(rewardActivity.getRules()); |
| 195 | rules.sort(Comparator.comparing(RewardActivityMatchRespDTO.Rule::getLimit)); // 按优惠门槛降序 | 196 | rules.sort(Comparator.comparing(RewardActivityMatchRespDTO.Rule::getLimit)); // 按优惠门槛降序 |