退款接口

This commit is contained in:
kuang.yifei@iwhalecloud.com 2022-06-22 17:39:45 +08:00
parent cbdf1fa14c
commit 67ca3401fd
1 changed files with 26 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package com.ghy.web.controller.pay;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.ghy.common.adapay.model.AdapayStatusEnum; import com.ghy.common.adapay.model.AdapayStatusEnum;
import com.ghy.common.adapay.model.PaymentDTO;
import com.ghy.common.core.domain.AjaxResult; import com.ghy.common.core.domain.AjaxResult;
import com.ghy.order.domain.OrderMaster; import com.ghy.order.domain.OrderMaster;
import com.ghy.order.service.OrderMasterService; import com.ghy.order.service.OrderMasterService;
@ -35,6 +36,31 @@ public class PayController {
@Resource @Resource
private FinancialMasterService financialMasterService; private FinancialMasterService financialMasterService;
/**
* 撤销支付
*
* @param orderMasterId 主订单ID
* @param refundAmt 退款金额 保留两位小数
*/
@PostMapping("refund")
@ResponseBody
public AjaxResult refund(Long orderMasterId, String refundAmt) throws BaseAdaPayException {
OrderMaster orderMaster = orderMasterService.selectById(orderMasterId);
Assert.notNull(orderMaster, "找不到对应的订单");
FinancialMaster financialMaster = financialMasterService.selectByOrderMasterId(orderMasterId);
PaymentDTO payment = financialMasterService.selectPaymentById(financialMaster.getPaymentId());
Assert.notNull(payment, "找不到支付记录");
Assert.notNull(financialMaster, "找不到订单");
Assert.isTrue(financialMaster.getPayStatus() == 1, "订单未支付");
Assert.hasText(financialMaster.getPaymentId(), "找不到订单的支付记录,请联系管理员");
JSONObject response = adapayService.refund(orderMaster.getDeptId(), financialMaster.getPaymentId(),payment.getOrderNo(), refundAmt);
if (AdapayStatusEnum.succeeded.code.equals(response.getString("status"))) {
return AjaxResult.success();
} else {
return AjaxResult.error(response.getString("error_msg"));
}
}
/** /**
* 撤销支付 * 撤销支付
* *