From a375feabfca0d88be9cb62062d59b93fcef365ac Mon Sep 17 00:00:00 2001 From: Chopper Date: Fri, 6 May 2022 15:51:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=94=AE=E5=90=8E=E6=B5=81=E6=B0=B4=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=8C=E5=94=AE=E5=90=8E=E4=BB=A3=E7=A0=81=E8=A2=AB?= =?UTF-8?q?=E5=A4=9A=E4=B8=AA=E5=9C=B0=E6=96=B9=E8=B0=83=E7=94=A8=E7=9A=84?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E4=BC=98=E5=8C=96=EF=BC=8C=E4=BB=A5=E5=90=8E?= =?UTF-8?q?=E5=8F=AA=E6=9C=89=E4=B8=80=E4=B8=AA=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/lili/event/impl/PaymentExecute.java | 70 +++++++------------ .../cn/lili/modules/payment/kit/Payment.java | 12 +--- .../modules/payment/kit/RefundSupport.java | 26 ------- .../kit/plugin/alipay/AliPayPlugin.java | 25 ------- .../kit/plugin/wallet/WalletPlugin.java | 17 +---- .../kit/plugin/wechat/WechatPlugin.java | 6 -- 6 files changed, 28 insertions(+), 128 deletions(-) diff --git a/consumer/src/main/java/cn/lili/event/impl/PaymentExecute.java b/consumer/src/main/java/cn/lili/event/impl/PaymentExecute.java index 6889c867e..058ff7936 100644 --- a/consumer/src/main/java/cn/lili/event/impl/PaymentExecute.java +++ b/consumer/src/main/java/cn/lili/event/impl/PaymentExecute.java @@ -5,6 +5,7 @@ import cn.lili.event.OrderStatusChangeEvent; import cn.lili.modules.order.order.entity.dos.Order; import cn.lili.modules.order.order.entity.dto.OrderMessage; +import cn.lili.modules.order.order.entity.enums.OrderStatusEnum; import cn.lili.modules.order.order.entity.enums.PayStatusEnum; import cn.lili.modules.order.order.service.OrderService; import cn.lili.modules.payment.entity.RefundLog; @@ -33,52 +34,33 @@ public class PaymentExecute implements OrderStatusChangeEvent { @Override public void orderChange(OrderMessage orderMessage) { - switch (orderMessage.getNewStatus()) { - case CANCELLED: - Order order = orderService.getBySn(orderMessage.getOrderSn()); + if (orderMessage.getNewStatus() == OrderStatusEnum.CANCELLED) { + Order order = orderService.getBySn(orderMessage.getOrderSn()); - //如果未付款,则不去要退回相关代码执行 - if (order.getPayStatus().equals(PayStatusEnum.UNPAID.name())) { - return; - } - PaymentMethodEnum paymentMethodEnum = PaymentMethodEnum.valueOf(order.getPaymentMethod()); - //进行退款操作 - switch (paymentMethodEnum) { - case WALLET: - case ALIPAY: - case WECHAT: - //获取支付方式 - Payment payment = - (Payment) SpringContextUtil.getBean(paymentMethodEnum.getPlugin()); - - RefundLog refundLog = RefundLog.builder() - .isRefund(false) - .totalAmount(order.getFlowPrice()) - .payPrice(order.getFlowPrice()) - .memberId(order.getMemberId()) - .paymentName(order.getPaymentMethod()) - .afterSaleNo("订单取消") - .orderSn(order.getSn()) - .paymentReceivableNo(order.getReceivableNo()) - .outOrderNo("AF" + SnowFlake.getIdStr()) - .outOrderNo("AF" + SnowFlake.getIdStr()) - .refundReason("订单取消") - .build(); - payment.cancel(refundLog); - break; - case BANK_TRANSFER: - break; - default: - log.error("订单支付执行异常,订单编号:{}", orderMessage.getOrderSn()); - break; - } - break; - default: - break; - } + //如果未付款,则不去要退回相关代码执行 + if (order.getPayStatus().equals(PayStatusEnum.UNPAID.name())) { + return; + } + PaymentMethodEnum paymentMethodEnum = PaymentMethodEnum.valueOf(order.getPaymentMethod()); + //获取支付方式 + Payment payment = + (Payment) SpringContextUtil.getBean(paymentMethodEnum.getPlugin()); + RefundLog refundLog = RefundLog.builder() + .isRefund(false) + .totalAmount(order.getFlowPrice()) + .payPrice(order.getFlowPrice()) + .memberId(order.getMemberId()) + .paymentName(order.getPaymentMethod()) + .afterSaleNo("订单取消") + .orderSn(order.getSn()) + .paymentReceivableNo(order.getReceivableNo()) + .outOrderNo("AF" + SnowFlake.getIdStr()) + .outOrderNo("AF" + SnowFlake.getIdStr()) + .refundReason("订单取消") + .build(); + payment.refund(refundLog); + } } - - } diff --git a/framework/src/main/java/cn/lili/modules/payment/kit/Payment.java b/framework/src/main/java/cn/lili/modules/payment/kit/Payment.java index 4046dc1a7..f67c26192 100644 --- a/framework/src/main/java/cn/lili/modules/payment/kit/Payment.java +++ b/framework/src/main/java/cn/lili/modules/payment/kit/Payment.java @@ -83,17 +83,6 @@ default void refund(RefundLog refundLog) { throw new ServiceException(ResultCode.PAY_ERROR); } - - /** - * 取消支付订单 - * - * @param refundLog 支付参数 - */ - default void cancel(RefundLog refundLog) { - throw new ServiceException(ResultCode.PAY_ERROR); - } - - /** * 回调 * @@ -131,6 +120,7 @@ default void refundNotify(HttpServletRequest request) { default String callbackUrl(String api, PaymentMethodEnum paymentMethodEnum) { return api + "/buyer/payment/cashier/callback/" + paymentMethodEnum.name(); } + /** * 支付异步通知地址 * diff --git a/framework/src/main/java/cn/lili/modules/payment/kit/RefundSupport.java b/framework/src/main/java/cn/lili/modules/payment/kit/RefundSupport.java index e8b758598..3e3d059e6 100644 --- a/framework/src/main/java/cn/lili/modules/payment/kit/RefundSupport.java +++ b/framework/src/main/java/cn/lili/modules/payment/kit/RefundSupport.java @@ -75,7 +75,6 @@ public void refund(AfterSale afterSale) { * * @return void * @Author ftyy - * @Description //TODO * @Date 17:33 2021/11/18 * @Param [afterSale] **/ @@ -89,31 +88,6 @@ private void updateReturnGoodsNumber(AfterSale afterSale) { orderItemService.updateById(orderItem); } - /** - * 订单取消 - * - * @param afterSale - */ - public void cancel(AfterSale afterSale) { - - Order order = orderService.getBySn(afterSale.getOrderSn()); - RefundLog refundLog = RefundLog.builder() - .isRefund(false) - .totalAmount(afterSale.getActualRefundPrice()) - .payPrice(afterSale.getActualRefundPrice()) - .memberId(afterSale.getMemberId()) - .paymentName(order.getPaymentMethod()) - .afterSaleNo(afterSale.getSn()) - .paymentReceivableNo(order.getReceivableNo()) - .outOrderNo("AF" + SnowFlake.getIdStr()) - .orderSn(afterSale.getOrderSn()) - .refundReason(afterSale.getReason()) - .build(); - PaymentMethodEnum paymentMethodEnum = PaymentMethodEnum.paymentNameOf(order.getPaymentMethod()); - Payment payment = (Payment) SpringContextUtil.getBean(paymentMethodEnum.getPlugin()); - payment.refund(refundLog); - } - /** * 退款通知 diff --git a/framework/src/main/java/cn/lili/modules/payment/kit/plugin/alipay/AliPayPlugin.java b/framework/src/main/java/cn/lili/modules/payment/kit/plugin/alipay/AliPayPlugin.java index b4a8a0944..9641d7516 100644 --- a/framework/src/main/java/cn/lili/modules/payment/kit/plugin/alipay/AliPayPlugin.java +++ b/framework/src/main/java/cn/lili/modules/payment/kit/plugin/alipay/AliPayPlugin.java @@ -211,31 +211,6 @@ public void refund(RefundLog refundLog) { } - @Override - public void cancel(RefundLog refundLog) { - AlipayTradeCancelModel model = new AlipayTradeCancelModel(); - //这里取支付回调时返回的流水 - if (StringUtils.isNotEmpty(refundLog.getPaymentReceivableNo())) { - model.setTradeNo(refundLog.getPaymentReceivableNo()); - } else { - log.error("退款时,支付参数为空导致异常:{}", refundLog); - throw new ServiceException(ResultCode.ALIPAY_PARAMS_EXCEPTION); - } - try { - //与阿里进行交互 - AlipayTradeCancelResponse alipayTradeCancelResponse = AliPayApi.tradeCancelToResponse(model); - if (alipayTradeCancelResponse.isSuccess()) { - refundLog.setIsRefund(true); - refundLog.setReceivableNo(refundLog.getOutOrderNo()); - } else { - refundLog.setErrorMessage(String.format("错误码:%s,错误原因:%s", alipayTradeCancelResponse.getSubCode(), alipayTradeCancelResponse.getSubMsg())); - } - refundLogService.save(refundLog); - } catch (Exception e) { - log.error("支付宝退款异常", e); - } - } - @Override public void refundNotify(HttpServletRequest request) { //不需要实现 diff --git a/framework/src/main/java/cn/lili/modules/payment/kit/plugin/wallet/WalletPlugin.java b/framework/src/main/java/cn/lili/modules/payment/kit/plugin/wallet/WalletPlugin.java index 9a2d1edc0..434085db5 100644 --- a/framework/src/main/java/cn/lili/modules/payment/kit/plugin/wallet/WalletPlugin.java +++ b/framework/src/main/java/cn/lili/modules/payment/kit/plugin/wallet/WalletPlugin.java @@ -96,21 +96,6 @@ public ResultMessage mpPay(HttpServletRequest request, PayParam payParam return ResultUtil.success(ResultCode.PAY_SUCCESS); } - @Override - public void cancel(RefundLog refundLog) { - - try { - memberWalletService.increase(new MemberWalletUpdateDTO(refundLog.getTotalAmount(), - refundLog.getMemberId(), - "取消[" + refundLog.getOrderSn() + "]订单,退还金额[" + refundLog.getTotalAmount() + "]", - DepositServiceTypeEnum.WALLET_REFUND.name())); - refundLog.setIsRefund(true); - refundLogService.save(refundLog); - } catch (Exception e) { - log.error("订单取消错误", e); - } - } - /** * 保存支付日志 * @@ -134,7 +119,7 @@ public void refund(RefundLog refundLog) { try { memberWalletService.increase(new MemberWalletUpdateDTO(refundLog.getTotalAmount(), refundLog.getMemberId(), - "售后[" + refundLog.getAfterSaleNo() + "]审批,退还金额[" + refundLog.getTotalAmount() + "]", + "订单[" + refundLog.getOrderSn() + "],售后单[" + refundLog.getAfterSaleNo() + "],退还金额[" + refundLog.getTotalAmount() + "]", DepositServiceTypeEnum.WALLET_REFUND.name())); refundLog.setIsRefund(true); refundLogService.save(refundLog); diff --git a/framework/src/main/java/cn/lili/modules/payment/kit/plugin/wechat/WechatPlugin.java b/framework/src/main/java/cn/lili/modules/payment/kit/plugin/wechat/WechatPlugin.java index a32e8572e..5eaf7b60b 100644 --- a/framework/src/main/java/cn/lili/modules/payment/kit/plugin/wechat/WechatPlugin.java +++ b/framework/src/main/java/cn/lili/modules/payment/kit/plugin/wechat/WechatPlugin.java @@ -554,12 +554,6 @@ public void refund(RefundLog refundLog) { } - @Override - public void cancel(RefundLog refundLog) { - this.refund(refundLog); - } - - @Override public void refundNotify(HttpServletRequest request) { String timestamp = request.getHeader("Wechatpay-Timestamp");