Skip to content

Commit

Permalink
售后流水问题,售后代码被多个地方调用的方式优化,以后只有一个入口
Browse files Browse the repository at this point in the history
  • Loading branch information
chopper711 committed May 6, 2022
1 parent e9d5e70 commit a375fea
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 128 deletions.
70 changes: 26 additions & 44 deletions consumer/src/main/java/cn/lili/event/impl/PaymentExecute.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}


}
12 changes: 1 addition & 11 deletions framework/src/main/java/cn/lili/modules/payment/kit/Payment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


/**
* 回调
*
Expand Down Expand Up @@ -131,6 +120,7 @@ default void refundNotify(HttpServletRequest request) {
default String callbackUrl(String api, PaymentMethodEnum paymentMethodEnum) {
return api + "/buyer/payment/cashier/callback/" + paymentMethodEnum.name();
}

/**
* 支付异步通知地址
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public void refund(AfterSale afterSale) {
*
* @return void
* @Author ftyy
* @Description //TODO
* @Date 17:33 2021/11/18
* @Param [afterSale]
**/
Expand All @@ -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);
}


/**
* 退款通知
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
//不需要实现
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,6 @@ public ResultMessage<Object> 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);
}
}

/**
* 保存支付日志
*
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit a375fea

Please sign in to comment.