From 1bec2b1a127211b580ab5aa2f82d06dca4d7053f Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Fri, 24 May 2024 15:46:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/BsOrderAfterSalesApplyServiceImpl.java | 17 +++++++++++++++++ .../order/impl/BsOrderRefundServiceImpl.java | 4 ++-- .../com/hfkj/service/pay/HuiPayService.java | 10 +++++----- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/service/src/main/java/com/hfkj/service/order/impl/BsOrderAfterSalesApplyServiceImpl.java b/service/src/main/java/com/hfkj/service/order/impl/BsOrderAfterSalesApplyServiceImpl.java index 6f52e1e..bbed271 100644 --- a/service/src/main/java/com/hfkj/service/order/impl/BsOrderAfterSalesApplyServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/order/impl/BsOrderAfterSalesApplyServiceImpl.java @@ -22,7 +22,9 @@ import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.math.BigDecimal; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -79,6 +81,7 @@ public class BsOrderAfterSalesApplyServiceImpl implements BsOrderAfterSalesApply && (!record.getStatus().equals(OrderAfterSalesApplyStatusEnum.type5.getCode()) && !record.getStatus().equals(OrderAfterSalesApplyStatusEnum.type2.getCode()))) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "此订单已提交售后,请勿重复提交"); } + BsOrderAfterSalesApply apply = new BsOrderAfterSalesApply(); apply.setType(applyType.getCode()); apply.setUserId(order.getUserId()); @@ -98,6 +101,20 @@ public class BsOrderAfterSalesApplyServiceImpl implements BsOrderAfterSalesApply apply.setPhoto(photo); apply.setRemarks(remarks); apply.setStatus(OrderAfterSalesApplyStatusEnum.type1.getCode()); + + if (orderChild.getSurplusRefundCount().equals(productCount)) { + // 全部退款 + apply.setRefundPrice(orderChild.getSurplusRefundPrice()); + apply.setRefundIntegral(orderChild.getSurplusRefundIntegral()); + } else { + // 部分退款 + // 计算单价 + BigDecimal unitPrice = orderChild.getSurplusRefundPrice().divide(new BigDecimal(orderChild.getProductCount().toString()), 2, BigDecimal.ROUND_DOWN).setScale(2); + BigDecimal unitPriceIntegral = new BigDecimal(orderChild.getSurplusRefundIntegral().toString()).divide(new BigDecimal("100")) + .divide(new BigDecimal(orderChild.getProductCount().toString()), 2, BigDecimal.ROUND_DOWN).setScale(2); + apply.setRefundPrice(unitPrice.multiply(new BigDecimal(productCount.toString()))); + apply.setRefundIntegral(unitPriceIntegral.multiply(new BigDecimal("100")).longValue()); + } editData(apply); // 操作记录 diff --git a/service/src/main/java/com/hfkj/service/order/impl/BsOrderRefundServiceImpl.java b/service/src/main/java/com/hfkj/service/order/impl/BsOrderRefundServiceImpl.java index 2dc66cf..f248169 100644 --- a/service/src/main/java/com/hfkj/service/order/impl/BsOrderRefundServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/order/impl/BsOrderRefundServiceImpl.java @@ -63,8 +63,8 @@ public class BsOrderRefundServiceImpl implements BsOrderRefundService { try { if (OrderPayChannelEnum.type1.getCode() == orderRefund.getRefundPayChannel()) { // 渠道退款 - JSONObject refund = HuiPayService.refund(orderRefund.getAccountMerchantNo(), orderRefund.getOrderNo(), orderRefund.getRefundOrderNo(), orderRefund.getRefundPrice()); - if (refund.getString("").equals("000000")) { + JSONObject refund = HuiPayService.refund(HuiPayService.DEFAULT_MER_NO, orderRefund.getOrderNo(), orderRefund.getRefundOrderNo(), orderRefund.getRefundPrice()); + if (refund.getString("return_code").equals("000000")) { JSONObject data = refund.getJSONObject("return_data"); orderRefund.setRefundPayChannelOrderNo(data.getString("refundTradeNo")); orderRefund.setRefundSerialNo(data.getString("accTradeNo")); diff --git a/service/src/main/java/com/hfkj/service/pay/HuiPayService.java b/service/src/main/java/com/hfkj/service/pay/HuiPayService.java index c47f2fd..5b251b2 100644 --- a/service/src/main/java/com/hfkj/service/pay/HuiPayService.java +++ b/service/src/main/java/com/hfkj/service/pay/HuiPayService.java @@ -28,7 +28,7 @@ public class HuiPayService { static Logger log = LoggerFactory.getLogger(HuiPayService.class); // 请求地址 private final static String REQUEST_URL = "https://pay.dctpay.com/openApi/v1/"; - private final static String DEFAULT_MER_NO = "2023041916292112804"; + public final static String DEFAULT_MER_NO = "2023041916292112804"; private final static String DEFAULT_MER_KEY = "2jLO2WjXcSRSzTCaca0Kmv0OFrfYBbrA"; public static Map preorder(String openId,OrderModel order) throws Exception { @@ -82,10 +82,10 @@ public class HuiPayService { public static JSONObject refund(String merchantNo,String outTradeNo,String refundTradeNo, BigDecimal refundAmount) throws Exception { Map param = new HashMap<>(); - param.put("merchantNo", ""); - param.put("outTradeNo", ""); - param.put("refundTradeNo", ""); - param.put("refundAmount", ""); + param.put("merchantNo", merchantNo); + param.put("outTradeNo", outTradeNo); + param.put("refundTradeNo", refundTradeNo); + param.put("refundAmount", refundAmount); param.put("sign" , SignatureUtil.createSign(param, DEFAULT_MER_KEY)); return HttpsUtils.doPost(REQUEST_URL + "trade/refund", param, new HashMap<>());