Commit 63fcc699306f40270ed3ffe048b9b4bcbb3226e6
1 parent
710f29d9
【代码优化】商城: 取消支付订单
Showing
6 changed files
with
28 additions
and
18 deletions
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java
| @@ -27,6 +27,7 @@ import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStat | @@ -27,6 +27,7 @@ import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStat | ||
| 27 | import cn.iocoder.yudao.module.system.api.social.SocialClientApi; | 27 | import cn.iocoder.yudao.module.system.api.social.SocialClientApi; |
| 28 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxaSubscribeMessageSendReqDTO; | 28 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxaSubscribeMessageSendReqDTO; |
| 29 | import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi; | 29 | import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi; |
| 30 | +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderCancelTypeEnum; | ||
| 30 | import jakarta.annotation.Nullable; | 31 | import jakarta.annotation.Nullable; |
| 31 | import jakarta.annotation.Resource; | 32 | import jakarta.annotation.Resource; |
| 32 | import lombok.extern.slf4j.Slf4j; | 33 | import lombok.extern.slf4j.Slf4j; |
| @@ -37,7 +38,10 @@ import org.springframework.transaction.annotation.Transactional; | @@ -37,7 +38,10 @@ import org.springframework.transaction.annotation.Transactional; | ||
| 37 | import org.springframework.validation.annotation.Validated; | 38 | import org.springframework.validation.annotation.Validated; |
| 38 | 39 | ||
| 39 | import java.time.LocalDateTime; | 40 | import java.time.LocalDateTime; |
| 40 | -import java.util.*; | 41 | +import java.util.ArrayList; |
| 42 | +import java.util.Collection; | ||
| 43 | +import java.util.List; | ||
| 44 | +import java.util.Map; | ||
| 41 | 45 | ||
| 42 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 46 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 43 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; | 47 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; |
| @@ -335,7 +339,8 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | @@ -335,7 +339,8 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | ||
| 335 | List<CombinationRecordDO> headAndRecords = updateBatchCombinationRecords(headRecord, | 339 | List<CombinationRecordDO> headAndRecords = updateBatchCombinationRecords(headRecord, |
| 336 | CombinationRecordStatusEnum.FAILED); | 340 | CombinationRecordStatusEnum.FAILED); |
| 337 | // 2. 订单取消 | 341 | // 2. 订单取消 |
| 338 | - headAndRecords.forEach(item -> tradeOrderApi.cancelPaidOrder(item.getUserId(), item.getOrderId())); | 342 | + headAndRecords.forEach(item -> tradeOrderApi.cancelPaidOrder(item.getUserId(), item.getOrderId(), |
| 343 | + TradeOrderCancelTypeEnum.COMBINATION_CLOSE)); | ||
| 339 | } | 344 | } |
| 340 | 345 | ||
| 341 | /** | 346 | /** |
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java
| 1 | package cn.iocoder.yudao.module.trade.api.order; | 1 | package cn.iocoder.yudao.module.trade.api.order; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; | 3 | import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; |
| 4 | +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderCancelTypeEnum; | ||
| 4 | 5 | ||
| 5 | import java.util.Collection; | 6 | import java.util.Collection; |
| 6 | import java.util.List; | 7 | import java.util.List; |
| @@ -31,9 +32,10 @@ public interface TradeOrderApi { | @@ -31,9 +32,10 @@ public interface TradeOrderApi { | ||
| 31 | /** | 32 | /** |
| 32 | * 取消支付订单 | 33 | * 取消支付订单 |
| 33 | * | 34 | * |
| 34 | - * @param userId 用户编号 | ||
| 35 | - * @param orderId 订单编号 | 35 | + * @param userId 用户编号 |
| 36 | + * @param orderId 订单编号 | ||
| 37 | + * @param cancelTypeEnum 取消类型 | ||
| 36 | */ | 38 | */ |
| 37 | - void cancelPaidOrder(Long userId, Long orderId); | 39 | + void cancelPaidOrder(Long userId, Long orderId, TradeOrderCancelTypeEnum cancelTypeEnum); |
| 38 | 40 | ||
| 39 | } | 41 | } |
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderCancelTypeEnum.java
| @@ -17,7 +17,8 @@ public enum TradeOrderCancelTypeEnum implements IntArrayValuable { | @@ -17,7 +17,8 @@ public enum TradeOrderCancelTypeEnum implements IntArrayValuable { | ||
| 17 | 17 | ||
| 18 | PAY_TIMEOUT(10, "超时未支付"), | 18 | PAY_TIMEOUT(10, "超时未支付"), |
| 19 | AFTER_SALE_CLOSE(20, "退款关闭"), | 19 | AFTER_SALE_CLOSE(20, "退款关闭"), |
| 20 | - MEMBER_CANCEL(30, "买家取消"); | 20 | + MEMBER_CANCEL(30, "买家取消"), |
| 21 | + COMBINATION_CLOSE(40, "拼团关闭"); | ||
| 21 | 22 | ||
| 22 | public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(TradeOrderCancelTypeEnum::getType).toArray(); | 23 | public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(TradeOrderCancelTypeEnum::getType).toArray(); |
| 23 | 24 |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java
| @@ -2,12 +2,13 @@ package cn.iocoder.yudao.module.trade.api.order; | @@ -2,12 +2,13 @@ package cn.iocoder.yudao.module.trade.api.order; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; | 3 | import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; |
| 4 | import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; | 4 | import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; |
| 5 | +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderCancelTypeEnum; | ||
| 5 | import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; | 6 | import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; |
| 6 | import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService; | 7 | import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService; |
| 8 | +import jakarta.annotation.Resource; | ||
| 7 | import org.springframework.stereotype.Service; | 9 | import org.springframework.stereotype.Service; |
| 8 | import org.springframework.validation.annotation.Validated; | 10 | import org.springframework.validation.annotation.Validated; |
| 9 | 11 | ||
| 10 | -import jakarta.annotation.Resource; | ||
| 11 | import java.util.Collection; | 12 | import java.util.Collection; |
| 12 | import java.util.List; | 13 | import java.util.List; |
| 13 | 14 | ||
| @@ -36,8 +37,8 @@ public class TradeOrderApiImpl implements TradeOrderApi { | @@ -36,8 +37,8 @@ public class TradeOrderApiImpl implements TradeOrderApi { | ||
| 36 | } | 37 | } |
| 37 | 38 | ||
| 38 | @Override | 39 | @Override |
| 39 | - public void cancelPaidOrder(Long userId, Long orderId) { | ||
| 40 | - tradeOrderUpdateService.cancelPaidOrder(userId, orderId); | 40 | + public void cancelPaidOrder(Long userId, Long orderId, TradeOrderCancelTypeEnum cancelTypeEnum) { |
| 41 | + tradeOrderUpdateService.cancelPaidOrder(userId, orderId, cancelTypeEnum); | ||
| 41 | } | 42 | } |
| 42 | 43 | ||
| 43 | } | 44 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java
| 1 | package cn.iocoder.yudao.module.trade.service.order; | 1 | package cn.iocoder.yudao.module.trade.service.order; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.common.enums.TerminalEnum; | ||
| 4 | import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDeliveryReqVO; | 3 | import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDeliveryReqVO; |
| 5 | import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderRemarkReqVO; | 4 | import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderRemarkReqVO; |
| 6 | import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderUpdateAddressReqVO; | 5 | import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderUpdateAddressReqVO; |
| @@ -10,7 +9,7 @@ import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettle | @@ -10,7 +9,7 @@ import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettle | ||
| 10 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementRespVO; | 9 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementRespVO; |
| 11 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO; | 10 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO; |
| 12 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; | 11 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; |
| 13 | - | 12 | +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderCancelTypeEnum; |
| 14 | import jakarta.validation.constraints.NotNull; | 13 | import jakarta.validation.constraints.NotNull; |
| 15 | 14 | ||
| 16 | /** | 15 | /** |
| @@ -188,12 +187,14 @@ public interface TradeOrderUpdateService { | @@ -188,12 +187,14 @@ public interface TradeOrderUpdateService { | ||
| 188 | void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId); | 187 | void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId); |
| 189 | 188 | ||
| 190 | // TODO 芋艿:拼团取消,不调这个接口哈; | 189 | // TODO 芋艿:拼团取消,不调这个接口哈; |
| 190 | + | ||
| 191 | /** | 191 | /** |
| 192 | * 取消支付订单 | 192 | * 取消支付订单 |
| 193 | * | 193 | * |
| 194 | - * @param userId 用户编号 | ||
| 195 | - * @param orderId 订单编号 | 194 | + * @param userId 用户编号 |
| 195 | + * @param orderId 订单编号 | ||
| 196 | + * @param cancelTypeEnum 取消类型 | ||
| 196 | */ | 197 | */ |
| 197 | - void cancelPaidOrder(Long userId, Long orderId); | 198 | + void cancelPaidOrder(Long userId, Long orderId, TradeOrderCancelTypeEnum cancelTypeEnum); |
| 198 | 199 | ||
| 199 | } | 200 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java
| @@ -858,13 +858,13 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | @@ -858,13 +858,13 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | ||
| 858 | 858 | ||
| 859 | @Override | 859 | @Override |
| 860 | @Transactional(rollbackFor = Exception.class) | 860 | @Transactional(rollbackFor = Exception.class) |
| 861 | - public void cancelPaidOrder(Long userId, Long orderId) { | ||
| 862 | - // TODO @puhui999:可能要加一个拼团取消;TradeOrderCancelTypeEnum.AFTER_SALE_CLOSE;然后参数传入下; | 861 | + public void cancelPaidOrder(Long userId, Long orderId, TradeOrderCancelTypeEnum cancelTypeEnum) { |
| 863 | // 1.1 检验订单存在 | 862 | // 1.1 检验订单存在 |
| 864 | TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(orderId, userId); | 863 | TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(orderId, userId); |
| 865 | if (order == null) { | 864 | if (order == null) { |
| 866 | throw exception(ORDER_NOT_FOUND); | 865 | throw exception(ORDER_NOT_FOUND); |
| 867 | } | 866 | } |
| 867 | + | ||
| 868 | // 1.2 校验订单是否支付 | 868 | // 1.2 校验订单是否支付 |
| 869 | if (!order.getPayStatus()) { | 869 | if (!order.getPayStatus()) { |
| 870 | throw exception(ORDER_CANCEL_PAID_FAIL, "已支付"); | 870 | throw exception(ORDER_CANCEL_PAID_FAIL, "已支付"); |
| @@ -875,13 +875,13 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | @@ -875,13 +875,13 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | ||
| 875 | } | 875 | } |
| 876 | 876 | ||
| 877 | // 2.1 取消订单 | 877 | // 2.1 取消订单 |
| 878 | - cancelOrder0(order, TradeOrderCancelTypeEnum.AFTER_SALE_CLOSE); | 878 | + cancelOrder0(order, cancelTypeEnum); |
| 879 | // 2.2 创建退款单 | 879 | // 2.2 创建退款单 |
| 880 | payRefundApi.createRefund(new PayRefundCreateReqDTO() | 880 | payRefundApi.createRefund(new PayRefundCreateReqDTO() |
| 881 | .setAppKey(tradeOrderProperties.getPayAppKey()).setUserIp(getClientIP()) // 支付应用 | 881 | .setAppKey(tradeOrderProperties.getPayAppKey()).setUserIp(getClientIP()) // 支付应用 |
| 882 | .setMerchantOrderId(String.valueOf(order.getId())) // 支付单号 | 882 | .setMerchantOrderId(String.valueOf(order.getId())) // 支付单号 |
| 883 | .setMerchantRefundId(String.valueOf(order.getId())) | 883 | .setMerchantRefundId(String.valueOf(order.getId())) |
| 884 | - .setReason("取消支付订单").setPrice(order.getPayPrice()));// 价格信息 | 884 | + .setReason(cancelTypeEnum.getName()).setPrice(order.getPayPrice()));// 价格信息 |
| 885 | } | 885 | } |
| 886 | 886 | ||
| 887 | /** | 887 | /** |