trade:【交易售后】回调退款

This commit is contained in:
YunaiV
2022-11-17 01:05:12 +08:00
parent 67050eeaa8
commit ee1d362a7c
12 changed files with 134 additions and 8 deletions

View File

@@ -5,16 +5,15 @@ import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSal
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleConfirmReqVO;
import cn.iocoder.yudao.module.trade.service.aftersale.TradeAfterSaleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
@@ -46,4 +45,13 @@ public class TradeAfterSaleController {
return success(true);
}
@PostMapping("/refund")
@ApiOperation(value = "确认退款", notes = "提供给【pay】支付服务退款成功后进行回调")
@ApiImplicitParam(name = "payRefundId", value = "支付退款编号", required = true, example = "18888")
@PermitAll
public CommonResult<Boolean> refundAfterSale(@RequestParam("payRefundId") Long payRefundId) {
afterSaleService.refundAfterSale(payRefundId);
return success(true);
}
}

View File

@@ -125,12 +125,17 @@ public class TradeAfterSaleDO extends BaseDO {
*/
private Integer refundPrice;
/**
* 支付退款编号 TODO
* 支付退款编号
*
* 对接 pay-module-biz 支付服务的退款订单编号,即 PayRefundDO 的 id 编号
*/
private Long payRefundId;
// TODO 芋艿看看是否有必要冗余order_number、order_amount、flow_trade_no、out_refund_no、pay_type、return_money_sts、refund_time
/**
* 退款时间
*
* 退款成功后,才记录该时间
*/
private LocalDateTime refundTime;
// ========== 退货相关 ==========
/**

View File

@@ -13,4 +13,8 @@ public interface TradeAfterSaleMapper extends BaseMapperX<TradeAfterSaleDO> {
.eq(TradeAfterSaleDO::getId, id).eq(TradeAfterSaleDO::getStatus, status));
}
default TradeAfterSaleDO selectByPayRefundId(Long payRefundId) {
return selectOne(TradeAfterSaleDO::getPayRefundId, payRefundId);
}
}

View File

@@ -49,4 +49,11 @@ public interface TradeAfterSaleService {
*/
void confirmAfterSale(Long userId, String userIp, TradeAfterSaleConfirmReqVO confirmReqVO);
/**
* 确认退款由【pay】支付服务回调
*
* @param payRefundId 支付退款编号
*/
void refundAfterSale(Long payRefundId);
}

View File

@@ -4,6 +4,8 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.iocoder.yudao.module.pay.api.refund.PayRefundApi;
import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundCreateReqDTO;
import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundRespDTO;
import cn.iocoder.yudao.module.pay.enums.refund.PayRefundStatusEnum;
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleAuditReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleConfirmReqVO;
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSaleCreateReqVO;
@@ -276,4 +278,42 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService {
// TODO 发送售后消息
}
@Override
public void refundAfterSale(Long payRefundId) {
// 校验退款单
PayRefundRespDTO payRefund = validatePayRefundSuccess(payRefundId);
// 校验售后单的状态,并状态待退款
TradeAfterSaleDO afterSale = tradeAfterSaleMapper.selectByPayRefundId(payRefundId);
if (afterSale == null) {
throw exception(AFTER_SALE_NOT_FOUND);
}
if (ObjectUtil.notEqual(afterSale.getStatus(), TradeAfterSaleStatusEnum.WAIT_REFUND.getStatus())) {
throw exception(AFTER_SALE_REFUND_FAIL_STATUS_NOT_WAIT_REFUND);
}
// 更新售后单的状态为【已完成】
updateAfterSaleStatus(afterSale.getId(), TradeAfterSaleStatusEnum.WAIT_REFUND.getStatus(), new TradeAfterSaleDO()
.setStatus(TradeAfterSaleStatusEnum.COMPLETE.getStatus()).setRefundTime(payRefund.getSuccessTime()));
// 更新交易订单项的售后状态为【已完成】
tradeOrderService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(),
TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(), TradeOrderItemAfterSaleStatusEnum.SUCCESS.getStatus());
// TODO 记录售后日志
// TODO 发送售后消息
}
private PayRefundRespDTO validatePayRefundSuccess(Long payRefundId) {
PayRefundRespDTO payRefund = payRefundApi.getPayRefund(payRefundId);
if (payRefund == null) {
throw exception(AFTER_SALE_REFUND_FAIL_PAY_REFUND_NOT_FOUND);
}
if (PayRefundStatusEnum.isSuccess(payRefund.getStatus())) {
throw exception(AFTER_SALE_REFUND_FAIL_PAY_REFUND_STATUS_NOT_SUCCESS);
}
return payRefund;
}
}