Commit d1b8e03b5b2451eef18c4523c4e02fd384373bf3
1 parent
490e91d0
!221 feat(pay): 支持通过支付订单号查询支付订单
Showing
4 changed files
with
31 additions
and
5 deletions
yudao-module-pay/src/main/java/cn/iocoder/yudao/module/pay/controller/app/order/AppPayOrderController.java
| 1 | package cn.iocoder.yudao.module.pay.controller.app.order; | 1 | package cn.iocoder.yudao.module.pay.controller.app.order; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.text.CharSequenceUtil; | ||
| 3 | import cn.hutool.core.util.ObjUtil; | 4 | import cn.hutool.core.util.ObjUtil; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 6 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| @@ -46,13 +47,21 @@ public class AppPayOrderController { | @@ -46,13 +47,21 @@ public class AppPayOrderController { | ||
| 46 | @GetMapping("/get") | 47 | @GetMapping("/get") |
| 47 | @Operation(summary = "获得支付订单") | 48 | @Operation(summary = "获得支付订单") |
| 48 | @Parameters({ | 49 | @Parameters({ |
| 49 | - @Parameter(name = "id", description = "编号", required = true, example = "1024"), | 50 | + @Parameter(name = "id", description = "编号", example = "1024"), |
| 51 | + @Parameter(name = "no", description = "支付订单号", example = "Pxxx"), | ||
| 50 | @Parameter(name = "sync", description = "是否同步", example = "true") | 52 | @Parameter(name = "sync", description = "是否同步", example = "true") |
| 51 | }) | 53 | }) |
| 52 | - public CommonResult<PayOrderRespVO> getOrder(@RequestParam("id") Long id, | 54 | + public CommonResult<PayOrderRespVO> getOrder(@RequestParam(value = "id", required = false) Long id, |
| 55 | + @RequestParam(value = "no", required = false) String no, | ||
| 53 | @RequestParam(value = "sync", required = false) Boolean sync) { | 56 | @RequestParam(value = "sync", required = false) Boolean sync) { |
| 54 | - PayOrderDO order = payOrderService.getOrder(id); | ||
| 55 | - if (order== null) { | 57 | + PayOrderDO order = null; |
| 58 | + if (CharSequenceUtil.isNotEmpty(no)) { | ||
| 59 | + order = payOrderService.getOrder(no); | ||
| 60 | + } | ||
| 61 | + if (ObjUtil.isNull(order) && ObjUtil.isNotNull(id)) { | ||
| 62 | + order = payOrderService.getOrder(id); | ||
| 63 | + } | ||
| 64 | + if (order == null) { | ||
| 56 | return success(null); | 65 | return success(null); |
| 57 | } | 66 | } |
| 58 | // 重要:校验订单是否是当前用户,避免越权 | 67 | // 重要:校验订单是否是当前用户,避免越权 |
| @@ -65,7 +74,7 @@ public class AppPayOrderController { | @@ -65,7 +74,7 @@ public class AppPayOrderController { | ||
| 65 | if (Boolean.TRUE.equals(sync) && PayOrderStatusEnum.isWaiting(order.getStatus())) { | 74 | if (Boolean.TRUE.equals(sync) && PayOrderStatusEnum.isWaiting(order.getStatus())) { |
| 66 | payOrderService.syncOrderQuietly(order.getId()); | 75 | payOrderService.syncOrderQuietly(order.getId()); |
| 67 | // 重新查询,因为同步后,可能会有变化 | 76 | // 重新查询,因为同步后,可能会有变化 |
| 68 | - order = payOrderService.getOrder(id); | 77 | + order = payOrderService.getOrder(order.getId()); |
| 69 | } | 78 | } |
| 70 | return success(BeanUtils.toBean(order, PayOrderRespVO.class)); | 79 | return success(BeanUtils.toBean(order, PayOrderRespVO.class)); |
| 71 | } | 80 | } |
yudao-module-pay/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/order/PayOrderMapper.java
| @@ -48,6 +48,10 @@ public interface PayOrderMapper extends BaseMapperX<PayOrderDO> { | @@ -48,6 +48,10 @@ public interface PayOrderMapper extends BaseMapperX<PayOrderDO> { | ||
| 48 | PayOrderDO::getMerchantOrderId, merchantOrderId); | 48 | PayOrderDO::getMerchantOrderId, merchantOrderId); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | + default PayOrderDO selectByNo(String no) { | ||
| 52 | + return selectOne(PayOrderDO::getNo, no); | ||
| 53 | + } | ||
| 54 | + | ||
| 51 | default int updateByIdAndStatus(Long id, Integer status, PayOrderDO update) { | 55 | default int updateByIdAndStatus(Long id, Integer status, PayOrderDO update) { |
| 52 | return update(update, new LambdaQueryWrapper<PayOrderDO>() | 56 | return update(update, new LambdaQueryWrapper<PayOrderDO>() |
| 53 | .eq(PayOrderDO::getId, id).eq(PayOrderDO::getStatus, status)); | 57 | .eq(PayOrderDO::getId, id).eq(PayOrderDO::getStatus, status)); |
yudao-module-pay/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderService.java
| @@ -34,6 +34,14 @@ public interface PayOrderService { | @@ -34,6 +34,14 @@ public interface PayOrderService { | ||
| 34 | /** | 34 | /** |
| 35 | * 获得支付订单 | 35 | * 获得支付订单 |
| 36 | * | 36 | * |
| 37 | + * @param no 支付订单号 | ||
| 38 | + * @return 支付订单 | ||
| 39 | + */ | ||
| 40 | + PayOrderDO getOrder(String no); | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * 获得支付订单 | ||
| 44 | + * | ||
| 37 | * @param appId 应用编号 | 45 | * @param appId 应用编号 |
| 38 | * @param merchantOrderId 商户订单编号 | 46 | * @param merchantOrderId 商户订单编号 |
| 39 | * @return 支付订单 | 47 | * @return 支付订单 |
yudao-module-pay/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java
| @@ -80,6 +80,11 @@ public class PayOrderServiceImpl implements PayOrderService { | @@ -80,6 +80,11 @@ public class PayOrderServiceImpl implements PayOrderService { | ||
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | @Override | 82 | @Override |
| 83 | + public PayOrderDO getOrder(String no) { | ||
| 84 | + return orderMapper.selectByNo(no); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + @Override | ||
| 83 | public PayOrderDO getOrder(Long appId, String merchantOrderId) { | 88 | public PayOrderDO getOrder(Long appId, String merchantOrderId) { |
| 84 | return orderMapper.selectByAppIdAndMerchantOrderId(appId, merchantOrderId); | 89 | return orderMapper.selectByAppIdAndMerchantOrderId(appId, merchantOrderId); |
| 85 | } | 90 | } |