diff --git a/open-api/src/main/java/com/api/controller/v1/TradeController.java b/open-api/src/main/java/com/api/controller/v1/TradeController.java index c814b27..5ea29b5 100644 --- a/open-api/src/main/java/com/api/controller/v1/TradeController.java +++ b/open-api/src/main/java/com/api/controller/v1/TradeController.java @@ -9,10 +9,7 @@ import com.hfkj.entity.BsMer; import com.hfkj.entity.BsTradeOrder; import com.hfkj.entity.BsTradeOrderRefund; import com.hfkj.model.ResponseData; -import com.hfkj.openapi.v1.model.RequestQueryTradeModel; -import com.hfkj.openapi.v1.model.RequestRefundTradeModel; -import com.hfkj.openapi.v1.model.RequestTradePreorderModel; -import com.hfkj.openapi.v1.model.ResponseQueryTradeModel; +import com.hfkj.openapi.v1.model.*; import com.hfkj.openapi.v1.service.OpenApiTradeOrderService; import com.hfkj.openapi.v1.utils.SignatureUtil; import com.hfkj.service.BsMerKeyService; @@ -141,7 +138,7 @@ public class TradeController { responseQueryTradeModel.setPayTime(tradeOrder.getPayTime()); responseQueryTradeModel.setSign(SignatureUtil.createSign(responseQueryTradeModel, merKeyService.getKeyByMerNo(body.getMerchantNo()))); - log.info("响应参数:" + JSONObject.toJSONString(responseQueryTradeModel)); + log.info("返回参数:" + JSONObject.toJSONString(responseQueryTradeModel)); return ResponseMsgUtil.success(responseQueryTradeModel); } catch (Exception e) { @@ -168,9 +165,10 @@ public class TradeController { if (refund != null) { throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "退款流水重复"); } - openApiTradeOrderService.refund(body); - return ResponseMsgUtil.success(null); + ResponseRefundTradeModel responseRefundTradeModel = openApiTradeOrderService.refund(body); + log.info("返回参数:" + JSONObject.toJSONString(responseRefundTradeModel)); + return ResponseMsgUtil.success(responseRefundTradeModel); } catch (Exception e) { log.info("出现异常:", e); diff --git a/service/src/main/java/com/hfkj/openapi/v1/model/ResponseRefundTradeModel.java b/service/src/main/java/com/hfkj/openapi/v1/model/ResponseRefundTradeModel.java index bbec990..64a31af 100644 --- a/service/src/main/java/com/hfkj/openapi/v1/model/ResponseRefundTradeModel.java +++ b/service/src/main/java/com/hfkj/openapi/v1/model/ResponseRefundTradeModel.java @@ -43,9 +43,9 @@ public class ResponseRefundTradeModel { private String refundAmount; /** - * 退款原因 + * 退款实际金额 */ - private String refundReason; + private String refundPayerAmount; /** * 退款时间 diff --git a/service/src/main/java/com/hfkj/openapi/v1/service/OpenApiTradeOrderService.java b/service/src/main/java/com/hfkj/openapi/v1/service/OpenApiTradeOrderService.java index 906b42c..86fea9b 100644 --- a/service/src/main/java/com/hfkj/openapi/v1/service/OpenApiTradeOrderService.java +++ b/service/src/main/java/com/hfkj/openapi/v1/service/OpenApiTradeOrderService.java @@ -32,7 +32,7 @@ public interface OpenApiTradeOrderService { * @param refundTrade * @return */ - ResponseRefundTradeModel refund(RequestRefundTradeModel refundTrade); + ResponseRefundTradeModel refund(RequestRefundTradeModel refundTrade) throws Exception; /** * 根据退款单号查询退款信息 diff --git a/service/src/main/java/com/hfkj/openapi/v1/service/impl/OpenApiTradeOrderServiceImpl.java b/service/src/main/java/com/hfkj/openapi/v1/service/impl/OpenApiTradeOrderServiceImpl.java index 8de1572..a5fc588 100644 --- a/service/src/main/java/com/hfkj/openapi/v1/service/impl/OpenApiTradeOrderServiceImpl.java +++ b/service/src/main/java/com/hfkj/openapi/v1/service/impl/OpenApiTradeOrderServiceImpl.java @@ -2,6 +2,9 @@ package com.hfkj.openapi.v1.service.impl; import com.alibaba.fastjson.JSONObject; import com.hfkj.channel.lakala.LaKaLaTradeService; +import com.hfkj.common.exception.ErrorCode; +import com.hfkj.common.exception.ErrorHelp; +import com.hfkj.common.exception.SysCode; import com.hfkj.entity.BsTradeOrder; import com.hfkj.entity.BsTradeOrderExample; import com.hfkj.entity.BsTradeOrderRefund; @@ -13,12 +16,14 @@ import com.hfkj.service.BsMerKeyService; import com.hfkj.service.BsTradeOrderRefundService; import com.hfkj.service.BsTradeOrderService; import com.hfkj.sysenum.TradeOrderRefundStatusEnum; +import com.hfkj.sysenum.TradeOrderStatusEnum; import org.apache.commons.collections4.MapUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.math.BigDecimal; import java.util.Map; /** @@ -65,28 +70,47 @@ public class OpenApiTradeOrderServiceImpl implements OpenApiTradeOrderService { } @Override - public ResponseRefundTradeModel refund(RequestRefundTradeModel refundTrade) { - - -/* BsTradeOrderRefund orderRefund = new BsTradeOrderRefund(); - orderRefund.setTradeOrderId(order.getId()); - orderRefund.setOutTradeNo(order.getOutTradeNo()); - orderRefund.setTradeOrderId(order.getId()); - orderRefund.setAgentId(order.getAgentId()); - orderRefund.setSalesmanId(order.getSalesmanId()); - orderRefund.setMerId(order.getMerId()); - orderRefund.setStoreId(order.getStoreId()); - orderRefund.setPlatformType(order.getPlatformType()); - orderRefund.setRefundNo(refundNo); - orderRefund.setTotalAmount(order.getTradeAmount()); - orderRefund.setRefundAmount(body.getBigDecimal("refundAmount")); - orderRefund.setRefundReason(body.getString("refundReason")); + public ResponseRefundTradeModel refund(RequestRefundTradeModel refundTrade) throws Exception { + // 查询交易订单 + BsTradeOrder tradeOrder = getOrderByOutTradeNo(refundTrade.getOutTradeNo()); + if (tradeOrder == null) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的交易订单"); + } + if (!tradeOrder.getStatus().equals(TradeOrderStatusEnum.status3.getNumber())) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "交易订单状态不处于已支付"); + } + + BsTradeOrderRefund orderRefund = new BsTradeOrderRefund(); + orderRefund.setSalesmanId(tradeOrder.getSalesmanId()); + orderRefund.setAgentId(tradeOrder.getAgentId()); + orderRefund.setMerId(tradeOrder.getMerId()); + orderRefund.setStoreId(tradeOrder.getStoreId()); + + orderRefund.setPlatformType(tradeOrder.getPlatformType()); + orderRefund.setTradeOrderId(tradeOrder.getId()); + orderRefund.setOutTradeNo(tradeOrder.getOutTradeNo()); + orderRefund.setRefundNo(refundTrade.getRefundTradeNo()); + orderRefund.setTotalAmount(tradeOrder.getTradeAmount()); + orderRefund.setRefundAmount(new BigDecimal(refundTrade.getRefundAmount())); + orderRefund.setRefundReason(refundTrade.getRefundReason()); orderRefund.setStatus(TradeOrderRefundStatusEnum.status1.getNumber()); - orderRefund.setOperatorId(userInfoModel.getSecUser().getId()); - orderRefund.setOperatorName(userInfoModel.getSecUser().getUserName()); - - bsTradeOrderRefundService.tradeOrderRefund()*/ - return null; + orderRefund.setOperatorId(0L); + orderRefund.setOperatorName("API接口"); + bsTradeOrderRefundService.editOrderRefund(orderRefund); + + Map refundMap = bsTradeOrderRefundService.tradeOrderRefund(orderRefund); + orderRefund = (BsTradeOrderRefund) refundMap.get("orderRefund"); + + ResponseRefundTradeModel refundTradeModel = new ResponseRefundTradeModel(); + refundTradeModel.setMerchantNo(tradeOrder.getMerNo()); + refundTradeModel.setOutTradeNo(tradeOrder.getOutTradeNo()); + refundTradeModel.setPayMode(tradeOrder.getPayMode()); + refundTradeModel.setRefundTradeNo(orderRefund.getRefundNo()); + refundTradeModel.setRefundAmount(orderRefund.getRefundAmount().toString()); + refundTradeModel.setRefundPayerAmount(orderRefund.getPayerAmount().toString()); + refundTradeModel.setRefundTime(orderRefund.getRefundTime()); + refundTradeModel.setSign(SignatureUtil.createSign(refundTradeModel, merKeyService.getKeyByMerNo(tradeOrder.getMerNo()))); + return refundTradeModel; } @Override diff --git a/service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java b/service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java index ff99017..895144f 100644 --- a/service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java +++ b/service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java @@ -80,8 +80,11 @@ public class SignatureUtil { public static void main(String[] args) throws Exception { String paramStr = "{\n" + - " \"merchantNo\": \"2023030909414450700\",\n" + - " \"outTradeNo\": \"ZF1130202305051459532538978807\"" + + " \"merchantNo\": \"2023030909414450700\",\n" + + " \"outTradeNo\": \"ZF1130202305242035187441186606\",\n" + + " \"refundAmount\": \"0.01\",\n" + + " \"refundReason\": \"测试退款\",\n" + + " \"refundTradeNo\": \"1170202305051137247442194606\"" + "}"; String sign = createSign(JSONObject.parseObject(paramStr), "LRL9uflTQGeyp9yVWDD6orhBp2VhYDvP"); System.out.println(sign);