Commit cccad2c6c1974dc7c98fcfaa12c86321bab7bf6f
1 parent
c4943e97
【代码评审】商城:取消拼团的支付单
Showing
7 changed files
with
35 additions
and
33 deletions
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/common/PromotionProductScopeEnum.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.enums.common; |
| 2 | 2 | |
| 3 | -import cn.hutool.core.util.ObjUtil; | |
| 4 | 3 | import cn.iocoder.yudao.framework.common.core.IntArrayValuable; |
| 5 | 4 | import lombok.AllArgsConstructor; |
| 6 | 5 | import lombok.Getter; |
| 7 | 6 | |
| 8 | 7 | import java.util.Arrays; |
| 8 | +import java.util.Objects; | |
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * 营销的商品范围枚举 |
| ... | ... | @@ -37,15 +37,15 @@ public enum PromotionProductScopeEnum implements IntArrayValuable { |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | public static boolean isAll(Integer scope) { |
| 40 | - return ObjUtil.equal(scope, ALL.scope); | |
| 40 | + return Objects.equals(scope, ALL.scope); | |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | public static boolean isSpu(Integer scope) { |
| 44 | - return ObjUtil.equal(scope, SPU.scope); | |
| 44 | + return Objects.equals(scope, SPU.scope); | |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | public static boolean isCategory(Integer scope) { |
| 48 | - return ObjUtil.equal(scope, CATEGORY.scope); | |
| 48 | + return Objects.equals(scope, CATEGORY.scope); | |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java
| ... | ... | @@ -53,6 +53,7 @@ public class AppActivityController { |
| 53 | 53 | private DiscountActivityService discountActivityService; |
| 54 | 54 | @Resource |
| 55 | 55 | private RewardActivityService rewardActivityService; |
| 56 | + | |
| 56 | 57 | @Resource |
| 57 | 58 | private ProductSpuApi productSpuApi; |
| 58 | 59 | |
| ... | ... | @@ -91,7 +92,7 @@ public class AppActivityController { |
| 91 | 92 | // 4. 限时折扣活动 |
| 92 | 93 | getDiscountActivities(spuIds, now, activityList); |
| 93 | 94 | // 5. 满减送活动 |
| 94 | - getRewardActivities(spuIds, now, activityList); | |
| 95 | + getRewardActivityList(spuIds, now, activityList); | |
| 95 | 96 | return activityList; |
| 96 | 97 | } |
| 97 | 98 | |
| ... | ... | @@ -148,23 +149,9 @@ public class AppActivityController { |
| 148 | 149 | item.getName(), productMap.get(item.getId()), item.getStartTime(), item.getEndTime()))); |
| 149 | 150 | } |
| 150 | 151 | |
| 151 | - private static void buildAppActivityRespVO(RewardActivityDO rewardActivity, Collection<Long> spuIds, | |
| 152 | - List<AppActivityRespVO> activityList) { | |
| 153 | - for (Long spuId : spuIds) { | |
| 154 | - // 校验商品是否已经加入过活动 | |
| 155 | - if (anyMatch(activityList, appActivity -> ObjUtil.equal(appActivity.getId(), rewardActivity.getId()) && | |
| 156 | - ObjUtil.equal(appActivity.getSpuId(), spuId))) { | |
| 157 | - continue; | |
| 158 | - } | |
| 159 | - activityList.add(new AppActivityRespVO(rewardActivity.getId(), | |
| 160 | - PromotionTypeEnum.REWARD_ACTIVITY.getType(), rewardActivity.getName(), spuId, | |
| 161 | - rewardActivity.getStartTime(), rewardActivity.getEndTime())); | |
| 162 | - } | |
| 163 | - } | |
| 164 | - | |
| 165 | - private void getRewardActivities(Collection<Long> spuIds, LocalDateTime now, List<AppActivityRespVO> activityList) { | |
| 152 | + private void getRewardActivityList(Collection<Long> spuIds, LocalDateTime now, List<AppActivityRespVO> activityList) { | |
| 166 | 153 | // 1.1 获得所有的活动 |
| 167 | - List<RewardActivityDO> rewardActivityList = rewardActivityService.getRewardActivityByStatusAndDateTimeLt( | |
| 154 | + List<RewardActivityDO> rewardActivityList = rewardActivityService.getRewardActivityListByStatusAndDateTimeLt( | |
| 168 | 155 | CommonStatusEnum.ENABLE.getStatus(), now); |
| 169 | 156 | if (CollUtil.isEmpty(rewardActivityList)) { |
| 170 | 157 | return; |
| ... | ... | @@ -196,4 +183,18 @@ public class AppActivityController { |
| 196 | 183 | } |
| 197 | 184 | } |
| 198 | 185 | |
| 186 | + private static void buildAppActivityRespVO(RewardActivityDO rewardActivity, Collection<Long> spuIds, | |
| 187 | + List<AppActivityRespVO> activityList) { | |
| 188 | + for (Long spuId : spuIds) { | |
| 189 | + // 校验商品是否已经加入过活动 | |
| 190 | + if (anyMatch(activityList, appActivity -> ObjUtil.equal(appActivity.getId(), rewardActivity.getId()) && | |
| 191 | + ObjUtil.equal(appActivity.getSpuId(), spuId))) { | |
| 192 | + continue; | |
| 193 | + } | |
| 194 | + activityList.add(new AppActivityRespVO(rewardActivity.getId(), | |
| 195 | + PromotionTypeEnum.REWARD_ACTIVITY.getType(), rewardActivity.getName(), spuId, | |
| 196 | + rewardActivity.getStartTime(), rewardActivity.getEndTime())); | |
| 197 | + } | |
| 198 | + } | |
| 199 | + | |
| 199 | 200 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityService.java
| ... | ... | @@ -79,6 +79,6 @@ public interface RewardActivityService { |
| 79 | 79 | * @param dateTime 当前日期时间 |
| 80 | 80 | * @return 满减送活动列表 |
| 81 | 81 | */ |
| 82 | - List<RewardActivityDO> getRewardActivityByStatusAndDateTimeLt(Integer status, LocalDateTime dateTime); | |
| 82 | + List<RewardActivityDO> getRewardActivityListByStatusAndDateTimeLt(Integer status, LocalDateTime dateTime); | |
| 83 | 83 | |
| 84 | 84 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityServiceImpl.java
| ... | ... | @@ -165,7 +165,7 @@ public class RewardActivityServiceImpl implements RewardActivityService { |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | @Override |
| 168 | - public List<RewardActivityDO> getRewardActivityByStatusAndDateTimeLt(Integer status, LocalDateTime dateTime) { | |
| 168 | + public List<RewardActivityDO> getRewardActivityListByStatusAndDateTimeLt(Integer status, LocalDateTime dateTime) { | |
| 169 | 169 | return rewardActivityMapper.selectListByStatusAndDateTimeLt(status, dateTime); |
| 170 | 170 | } |
| 171 | 171 | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java
| ... | ... | @@ -186,15 +186,14 @@ public interface TradeOrderUpdateService { |
| 186 | 186 | */ |
| 187 | 187 | void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId); |
| 188 | 188 | |
| 189 | - // TODO 芋艿:拼团取消,不调这个接口哈; | |
| 190 | - | |
| 189 | + // TODO @puhui999:不传递枚举哈。因为 rpc 不好支持。 | |
| 191 | 190 | /** |
| 192 | 191 | * 取消支付订单 |
| 193 | 192 | * |
| 194 | 193 | * @param userId 用户编号 |
| 195 | 194 | * @param orderId 订单编号 |
| 196 | - * @param cancelTypeEnum 取消类型 | |
| 195 | + * @param cancelType 取消类型 | |
| 197 | 196 | */ |
| 198 | - void cancelPaidOrder(Long userId, Long orderId, TradeOrderCancelTypeEnum cancelTypeEnum); | |
| 197 | + void cancelPaidOrder(Long userId, Long orderId, TradeOrderCancelTypeEnum cancelType); | |
| 199 | 198 | |
| 200 | 199 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java
| ... | ... | @@ -858,7 +858,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { |
| 858 | 858 | |
| 859 | 859 | @Override |
| 860 | 860 | @Transactional(rollbackFor = Exception.class) |
| 861 | - public void cancelPaidOrder(Long userId, Long orderId, TradeOrderCancelTypeEnum cancelTypeEnum) { | |
| 861 | + public void cancelPaidOrder(Long userId, Long orderId, TradeOrderCancelTypeEnum cancelType) { | |
| 862 | + // TODO @puhui999:这里校验下 cancelType 只允许拼团关闭; | |
| 862 | 863 | // 1.1 检验订单存在 |
| 863 | 864 | TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(orderId, userId); |
| 864 | 865 | if (order == null) { |
| ... | ... | @@ -875,13 +876,13 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { |
| 875 | 876 | } |
| 876 | 877 | |
| 877 | 878 | // 2.1 取消订单 |
| 878 | - cancelOrder0(order, cancelTypeEnum); | |
| 879 | + cancelOrder0(order, cancelType); | |
| 879 | 880 | // 2.2 创建退款单 |
| 880 | 881 | payRefundApi.createRefund(new PayRefundCreateReqDTO() |
| 881 | 882 | .setAppKey(tradeOrderProperties.getPayAppKey()).setUserIp(getClientIP()) // 支付应用 |
| 882 | 883 | .setMerchantOrderId(String.valueOf(order.getId())) // 支付单号 |
| 883 | 884 | .setMerchantRefundId(String.valueOf(order.getId())) |
| 884 | - .setReason(cancelTypeEnum.getName()).setPrice(order.getPayPrice()));// 价格信息 | |
| 885 | + .setReason(cancelType.getName()).setPrice(order.getPayPrice()));// 价格信息 | |
| 885 | 886 | } |
| 886 | 887 | |
| 887 | 888 | /** | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeRewardActivityPriceCalculator.java
| ... | ... | @@ -52,7 +52,7 @@ public class TradeRewardActivityPriceCalculator implements TradePriceCalculator |
| 52 | 52 | private void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result, |
| 53 | 53 | RewardActivityMatchRespDTO rewardActivity) { |
| 54 | 54 | // 1.1 获得满减送的订单项(商品)列表 |
| 55 | - List<TradePriceCalculateRespBO.OrderItem> orderItems = filterMatchCouponOrderItems(result, rewardActivity); | |
| 55 | + List<TradePriceCalculateRespBO.OrderItem> orderItems = filterMatchActivityOrderItems(result, rewardActivity); | |
| 56 | 56 | if (CollUtil.isEmpty(orderItems)) { |
| 57 | 57 | return; |
| 58 | 58 | } |
| ... | ... | @@ -93,8 +93,9 @@ public class TradeRewardActivityPriceCalculator implements TradePriceCalculator |
| 93 | 93 | * @param rewardActivity 满减送活动 |
| 94 | 94 | * @return 订单项(商品)列表 |
| 95 | 95 | */ |
| 96 | - private List<TradePriceCalculateRespBO.OrderItem> filterMatchCouponOrderItems(TradePriceCalculateRespBO result, | |
| 97 | - RewardActivityMatchRespDTO rewardActivity) { | |
| 96 | + private List<TradePriceCalculateRespBO.OrderItem> filterMatchActivityOrderItems(TradePriceCalculateRespBO result, | |
| 97 | + RewardActivityMatchRespDTO rewardActivity) { | |
| 98 | + // TODO @puhui999:是不是得根据类型过滤哈 | |
| 98 | 99 | return filterList(result.getItems(), |
| 99 | 100 | orderItem -> CollUtil.contains(rewardActivity.getProductScopeValues(), orderItem.getSpuId())); |
| 100 | 101 | } | ... | ... |