feat(pay): 支持通过订单号查询支付订单
- 在 AppPayOrderController 中增加根据支付订单号查询订单的功能 - 新增 PayOrderMapper 的 selectByNo 方法用于按订单号查询 - 扩展 PayOrderService 接口及实现类以支持订单号查询 - 优化查询逻辑,优先使用订单号查询,其次使用订单ID查询 - 更新接口文档,增加支付订单号参数说明 - 使用 CharSequenceUtil 工具类判断订单号是否为空
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package cn.iocoder.yudao.module.pay.controller.app.order;
|
package cn.iocoder.yudao.module.pay.controller.app.order;
|
||||||
|
|
||||||
|
import cn.hutool.core.text.CharSequenceUtil;
|
||||||
import cn.hutool.core.util.ObjUtil;
|
import cn.hutool.core.util.ObjUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
@@ -46,13 +47,21 @@ public class AppPayOrderController {
|
|||||||
@GetMapping("/get")
|
@GetMapping("/get")
|
||||||
@Operation(summary = "获得支付订单")
|
@Operation(summary = "获得支付订单")
|
||||||
@Parameters({
|
@Parameters({
|
||||||
@Parameter(name = "id", description = "编号", required = true, example = "1024"),
|
@Parameter(name = "id", description = "编号", example = "1024"),
|
||||||
|
@Parameter(name = "no", description = "支付订单号", example = "Pxxx"),
|
||||||
@Parameter(name = "sync", description = "是否同步", example = "true")
|
@Parameter(name = "sync", description = "是否同步", example = "true")
|
||||||
})
|
})
|
||||||
public CommonResult<PayOrderRespVO> getOrder(@RequestParam("id") Long id,
|
public CommonResult<PayOrderRespVO> getOrder(@RequestParam(value = "id", required = false) Long id,
|
||||||
|
@RequestParam(value = "no", required = false) String no,
|
||||||
@RequestParam(value = "sync", required = false) Boolean sync) {
|
@RequestParam(value = "sync", required = false) Boolean sync) {
|
||||||
PayOrderDO order = payOrderService.getOrder(id);
|
PayOrderDO order = null;
|
||||||
if (order== null) {
|
if (CharSequenceUtil.isNotEmpty(no)){
|
||||||
|
order = payOrderService.getOrder(no);
|
||||||
|
}
|
||||||
|
if (ObjUtil.isNull(order) && ObjUtil.isNotNull(id)) {
|
||||||
|
order = payOrderService.getOrder(id);
|
||||||
|
}
|
||||||
|
if (order == null) {
|
||||||
return success(null);
|
return success(null);
|
||||||
}
|
}
|
||||||
// 重要:校验订单是否是当前用户,避免越权
|
// 重要:校验订单是否是当前用户,避免越权
|
||||||
|
|||||||
@@ -48,6 +48,10 @@ public interface PayOrderMapper extends BaseMapperX<PayOrderDO> {
|
|||||||
PayOrderDO::getMerchantOrderId, merchantOrderId);
|
PayOrderDO::getMerchantOrderId, merchantOrderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default PayOrderDO selectByNo(String no) {
|
||||||
|
return selectOne(PayOrderDO::getNo, no);
|
||||||
|
}
|
||||||
|
|
||||||
default int updateByIdAndStatus(Long id, Integer status, PayOrderDO update) {
|
default int updateByIdAndStatus(Long id, Integer status, PayOrderDO update) {
|
||||||
return update(update, new LambdaQueryWrapper<PayOrderDO>()
|
return update(update, new LambdaQueryWrapper<PayOrderDO>()
|
||||||
.eq(PayOrderDO::getId, id).eq(PayOrderDO::getStatus, status));
|
.eq(PayOrderDO::getId, id).eq(PayOrderDO::getStatus, status));
|
||||||
|
|||||||
@@ -30,7 +30,13 @@ public interface PayOrderService {
|
|||||||
* @return 支付订单
|
* @return 支付订单
|
||||||
*/
|
*/
|
||||||
PayOrderDO getOrder(Long id);
|
PayOrderDO getOrder(Long id);
|
||||||
|
/**
|
||||||
|
* 获得支付订单
|
||||||
|
*
|
||||||
|
* @param no 支付订单号
|
||||||
|
* @return 支付订单
|
||||||
|
*/
|
||||||
|
PayOrderDO getOrder(String no);
|
||||||
/**
|
/**
|
||||||
* 获得支付订单
|
* 获得支付订单
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -78,7 +78,10 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|||||||
public PayOrderDO getOrder(Long id) {
|
public PayOrderDO getOrder(Long id) {
|
||||||
return orderMapper.selectById(id);
|
return orderMapper.selectById(id);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public PayOrderDO getOrder(String no) {
|
||||||
|
return orderMapper.selectByNo(no);
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public PayOrderDO getOrder(Long appId, String merchantOrderId) {
|
public PayOrderDO getOrder(Long appId, String merchantOrderId) {
|
||||||
return orderMapper.selectByAppIdAndMerchantOrderId(appId, merchantOrderId);
|
return orderMapper.selectByAppIdAndMerchantOrderId(appId, merchantOrderId);
|
||||||
|
|||||||
Reference in New Issue
Block a user