From 5dcb3db5d7ae8c205a7f2f61354211c7604b8f54 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 19 Jul 2023 09:50:24 +0800 Subject: [PATCH] =?UTF-8?q?mall=20+=20pay=EF=BC=9A=201.=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E8=AE=A2=E5=8D=95=E7=AE=A1=E7=90=86=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/order/PayOrderController.java | 25 ++--- .../admin/order/vo/PayOrderDetailsRespVO.java | 14 +-- .../pay/convert/order/PayOrderConvert.java | 14 ++- .../service/order/PayOrderServiceImpl.java | 24 +++- .../service/refund/PayRefundServiceImpl.java | 2 +- yudao-ui-admin/src/views/pay/order/index.vue | 103 +++++------------- 6 files changed, 73 insertions(+), 109 deletions(-) diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/PayOrderController.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/PayOrderController.java index 6acc41ceb..5bbf5c96b 100755 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/PayOrderController.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/PayOrderController.java @@ -56,31 +56,20 @@ public class PayOrderController { return success(PayOrderConvert.INSTANCE.convert(payOrderService.getOrder(id))); } - // TODO 芋艿:看看怎么优化下; @GetMapping("/get-detail") @Operation(summary = "获得支付订单详情") @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('pay:order:query')") public CommonResult getOrderDetail(@RequestParam("id") Long id) { PayOrderDO order = payOrderService.getOrder(id); - if (ObjectUtil.isNull(order)) { - return success(new PayOrderDetailsRespVO()); + if (order == null) { + return success(null); } - PayAppDO appDO = appService.getApp(order.getAppId()); - PayChannelEnum channelEnum = PayChannelEnum.getByCode(order.getChannelCode()); - - // TODO @aquan:文案,都是前端 format; - PayOrderDetailsRespVO respVO = PayOrderConvert.INSTANCE.orderDetailConvert(order); - respVO.setAppName(ObjectUtil.isNotNull(appDO) ? appDO.getName() : "未知应用"); - respVO.setChannelCodeName(ObjectUtil.isNotNull(channelEnum) ? channelEnum.getName() : "未知渠道"); - - PayOrderExtensionDO extensionDO = orderExtensionService.getOrderExtension(order.getSuccessExtensionId()); - if (ObjectUtil.isNotNull(extensionDO)) { - respVO.setPayOrderExtension(PayOrderConvert.INSTANCE.orderDetailExtensionConvert(extensionDO)); - } - - return success(respVO); + // 拼接返回 + PayAppDO app = appService.getApp(order.getAppId()); + PayOrderExtensionDO orderExtension = orderExtensionService.getOrderExtension(order.getSuccessExtensionId()); + return success(PayOrderConvert.INSTANCE.convert(order, orderExtension, app)); } @PostMapping("/submit") @@ -90,6 +79,7 @@ public class PayOrderController { return success(respVO); } + // TODO 芋艿:优化 @GetMapping("/page") @Operation(summary = "获得支付订单分页") @PreAuthorize("@ss.hasPermission('pay:order:query')") @@ -116,6 +106,7 @@ public class PayOrderController { return success(new PageResult<>(pageList, pageResult.getTotal())); } + // TODO 芋艿:优化 @GetMapping("/export-excel") @Operation(summary = "导出支付订单Excel") @PreAuthorize("@ss.hasPermission('pay:order:export')") diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/vo/PayOrderDetailsRespVO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/vo/PayOrderDetailsRespVO.java index 759450c93..a6a5f684a 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/vo/PayOrderDetailsRespVO.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/vo/PayOrderDetailsRespVO.java @@ -13,32 +13,30 @@ import java.time.LocalDateTime; @ToString(callSuper = true) public class PayOrderDetailsRespVO extends PayOrderBaseVO { - @Schema(description = "支付订单编号") + @Schema(description = "支付订单编号", required = true, example = "1024") private Long id; - @Schema(description = "应用名称") + @Schema(description = "应用名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道源码") private String appName; - @Schema(description = "渠道编号名称") - private String channelCodeName; - - @Schema(description = "创建时间") + @Schema(description = "创建时间", required = true) private LocalDateTime createTime; /** * 支付订单扩展 */ - private PayOrderExtension payOrderExtension; + private PayOrderExtension extension; @Data @Schema(description = "支付订单扩展") public static class PayOrderExtension { - @Schema(description = "支付订单号") + @Schema(description = "支付订单号", required = true, example = "1024") private String no; @Schema(description = "支付异步通知的内容") private String channelNotifyData; + } } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/order/PayOrderConvert.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/order/PayOrderConvert.java index 647fe3dbb..e9f0ebf43 100755 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/order/PayOrderConvert.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/order/PayOrderConvert.java @@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO; import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderRespDTO; import cn.iocoder.yudao.module.pay.controller.admin.order.vo.*; import cn.iocoder.yudao.module.pay.controller.app.order.vo.AppPayOrderSubmitRespVO; +import cn.iocoder.yudao.module.pay.dal.dataobject.app.PayAppDO; import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderDO; import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderExtensionDO; import org.mapstruct.Mapper; @@ -30,9 +31,16 @@ public interface PayOrderConvert { PayOrderRespDTO convert2(PayOrderDO order); - PayOrderDetailsRespVO orderDetailConvert(PayOrderDO bean); - - PayOrderDetailsRespVO.PayOrderExtension orderDetailExtensionConvert(PayOrderExtensionDO bean); + default PayOrderDetailsRespVO convert(PayOrderDO order, PayOrderExtensionDO orderExtension, PayAppDO app) { + PayOrderDetailsRespVO respVO = convertDetail(order); + respVO.setExtension(convert(orderExtension)); + if (app != null) { + respVO.setAppName(app.getName()); + } + return respVO; + } + PayOrderDetailsRespVO convertDetail(PayOrderDO bean); + PayOrderDetailsRespVO.PayOrderExtension convert(PayOrderExtensionDO bean); List convertList(List list); diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java index 997a3f08a..e7551ba57 100755 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java @@ -5,6 +5,7 @@ import cn.hutool.core.lang.Pair; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.StrUtil; +import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; import cn.iocoder.yudao.framework.pay.config.PayProperties; @@ -161,7 +162,7 @@ public class PayOrderServiceImpl implements PayOrderService { // 4. 如果调用直接支付成功,则直接更新支付单状态为成功。例如说:付款码支付,免密支付时,就直接验证支付成功 if (unifiedOrderResp != null) { - notifyPayOrder(channel, unifiedOrderResp); + getSelf().notifyPayOrder(channel, unifiedOrderResp); // 如有渠道错误码,则抛出业务异常,提示用户 if (StrUtil.isNotEmpty(unifiedOrderResp.getChannelErrorCode())) { throw exception(ORDER_SUBMIT_CHANNEL_ERROR, unifiedOrderResp.getChannelErrorCode(), @@ -234,11 +235,17 @@ public class PayOrderServiceImpl implements PayOrderService { // 校验支付渠道是否有效 PayChannelDO channel = channelService.validPayChannel(channelId); // 更新支付订单为已支付 - TenantUtils.execute(channel.getTenantId(), () -> notifyPayOrder(channel, notify)); + TenantUtils.execute(channel.getTenantId(), () -> getSelf().notifyPayOrder(channel, notify)); } - // TODO 芋艿:事务问题 - private void notifyPayOrder(PayChannelDO channel, PayOrderRespDTO notify) { + /** + * 通知并更新订单的支付结果 + * + * @param channel 支付渠道 + * @param notify 通知 + */ + @Transactional(rollbackFor = Exception.class) // 注意,如果是方法内调用该方法,需要通过 getSelf().notifyPayOrder(channel, notify) 调用,否则事务不生效 + public void notifyPayOrder(PayChannelDO channel, PayOrderRespDTO notify) { // 情况一:支付成功的回调 if (PayOrderStatusRespEnum.isSuccess(notify.getStatus())) { notifyOrderSuccess(channel, notify); @@ -396,4 +403,13 @@ public class PayOrderServiceImpl implements PayOrderService { } } + /** + * 获得自身的代理对象,解决 AOP 生效问题 + * + * @return 自己 + */ + private PayOrderServiceImpl getSelf() { + return SpringUtil.getBean(getClass()); + } + } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/refund/PayRefundServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/refund/PayRefundServiceImpl.java index bf45349a7..516c137e8 100755 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/refund/PayRefundServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/refund/PayRefundServiceImpl.java @@ -137,7 +137,7 @@ public class PayRefundServiceImpl implements PayRefundService { .setOutRefundNo(refund.getNo()) .setNotifyUrl(genChannelRefundNotifyUrl(channel)) .setReason(reqDTO.getReason()); - PayRefundRespDTO refundRespDTO = client.unifiedRefund(unifiedReqDTO); // TODO 增加一个 channelErrorCode、channelErrorMsg 字段 + PayRefundRespDTO refundRespDTO = client.unifiedRefund(unifiedReqDTO); // 2.3 处理退款返回 notifyRefund(channel, refundRespDTO); diff --git a/yudao-ui-admin/src/views/pay/order/index.vue b/yudao-ui-admin/src/views/pay/order/index.vue index 6f3fe5006..661b30c4e 100755 --- a/yudao-ui-admin/src/views/pay/order/index.vue +++ b/yudao-ui-admin/src/views/pay/order/index.vue @@ -11,7 +11,7 @@ - + @@ -24,13 +24,13 @@ - - @@ -102,6 +102,7 @@ + @@ -124,7 +125,7 @@ @@ -134,7 +135,7 @@ - + {{ orderDetail.appName }} @@ -149,8 +150,8 @@ {{ orderDetail.channelOrderNo }} - - {{ orderDetail.payOrderExtension.no }} + + {{ orderDetail.extension.no }} @@ -176,7 +177,9 @@ - {{ orderDetail.channelCodeName }} + + + {{ orderDetail.userIp }} @@ -194,7 +197,7 @@ {{ orderDetail.body }} - {{ orderDetail.payOrderExtension.channelNotifyData }} + {{ orderDetail.extension.channelNotifyData }} @@ -204,34 +207,6 @@