Browse Source

feat(payment): 增加微信支付分账及退款明细记录功能

- 引入 JSONObject 用于接收分账接口返回数据
- 在 ProfitSharingJonService 中调用分账结果查询接口并接收返回值
- 新增 ReceiptPaymentDetailsInfoVo 类及相关服务注入
- 实现退款成功后的分账金额计算与明细记录保存逻辑
- 添加 getChangeMoney 和 getBigDecimal 工具方法处理金额转换
- 记录平台、商户和门店三方的退款金额变动信息
SheepHy 1 month ago
parent
commit
1a7d8438b2

+ 56 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/service/WeChatPayService.java

@@ -17,8 +17,10 @@ import org.apache.commons.lang3.StringUtils;
 import org.jeecg.common.constant.CommonConstant;
 import org.jeecg.modules.pay.config.*;
 import org.jeecg.modules.pay.serverPay.WXPayUtility;
+import org.jeecg.modules.system.app.dto.receiptPaymentDetails.ReceiptPaymentDetailsInfoVo;
 import org.jeecg.modules.system.app.entity.*;
 import org.jeecg.modules.system.app.mapper.*;
+import org.jeecg.modules.system.app.service.IReceiptPaymentDetailsInfoService;
 import org.jeecg.modules.system.entity.SysDepart;
 import org.jeecg.modules.system.mapper.SysDepartMapper;
 import org.jetbrains.annotations.NotNull;
@@ -75,6 +77,9 @@ public class WeChatPayService {
     @Resource
     private WeChatProfitSharingService weChatProfitSharingService;
 
+    @Resource
+    private IReceiptPaymentDetailsInfoService iReceiptPaymentDetailsInfoService;
+
 
     /**
      * 小程序支付拉起
@@ -520,6 +525,37 @@ public class WeChatPayService {
 
             parm.put("code", "SUCCESS");
             parm.put("message", "成功");
+            SysDepart sysDepart = sysDepartMapper.findByOrgCodeAndParentId(order.getOrgCode());
+            SeparateAccounts separateAccounts = separateAccountsMapper.findByDeptIdAndStatus(sysDepart.getId());
+            BigDecimal shBigDecimal = BigDecimal.ZERO;
+            try {
+                shBigDecimal = getBigDecimal(order.getPrice(), separateAccounts.getShSeparateAccounts());
+            } catch (Exception e) {
+                log.error("百分比计算错误", e);
+            }
+            BigDecimal ptBigDecimal = BigDecimal.ZERO;
+            try {
+                ptBigDecimal = getBigDecimal(order.getPrice(), separateAccounts.getPtSeparateAccounts());
+            } catch (Exception e) {
+                log.error("百分比计算错误", e);
+            }
+            SysDepart byOrgCode = sysDepartMapper.findByOrgCode("A01");
+            BigDecimal mdBigDecimal = order.getPrice().subtract(shBigDecimal).subtract(ptBigDecimal).setScale(2, RoundingMode.HALF_UP);
+            log.info("退款成功消息通知,金额:" + mdBigDecimal + ";" + shBigDecimal + ";" + ptBigDecimal);
+            ReceiptPaymentDetailsInfoVo receiptPaymentDetailsInfoVo = new ReceiptPaymentDetailsInfoVo();
+            receiptPaymentDetailsInfoVo.setMoney(order.getPrice());
+            receiptPaymentDetailsInfoVo.setChangeMoney(appOrderRefundsInfo.getAmount());
+            receiptPaymentDetailsInfoVo.setPayType(1);
+            receiptPaymentDetailsInfoVo.setPurseChangeReason(1);
+            receiptPaymentDetailsInfoVo.setCreateTime(new Date());
+            receiptPaymentDetailsInfoVo.setUpdateTime(new Date());
+            receiptPaymentDetailsInfoVo.setOrderId(appOrderRefundsInfo.getOrderId());
+            ReceiptPaymentDetailsInfoVo receiptPaymentDetailsInfoVoMd = getChangeMoney(receiptPaymentDetailsInfoVo, order.getOrgCode(), order.getTenantId(), 2, mdBigDecimal);
+            ReceiptPaymentDetailsInfoVo receiptPaymentDetailsInfoVoSh = getChangeMoney(receiptPaymentDetailsInfoVo, order.getOrgCode(), sysDepart.getId(), 1, shBigDecimal);
+            ReceiptPaymentDetailsInfoVo receiptPaymentDetailsInfoVoPt = getChangeMoney(receiptPaymentDetailsInfoVo, order.getOrgCode(), byOrgCode.getId(), 0, ptBigDecimal);
+            iReceiptPaymentDetailsInfoService.add(receiptPaymentDetailsInfoVoPt);
+            iReceiptPaymentDetailsInfoService.add(receiptPaymentDetailsInfoVoSh);
+            iReceiptPaymentDetailsInfoService.add(receiptPaymentDetailsInfoVoMd);
         } else {
             parm.put("code", "FAIL");
             parm.put("message", "失败");
@@ -528,6 +564,26 @@ public class WeChatPayService {
         return parm;  //返回给前端的参数
     }
 
+    private ReceiptPaymentDetailsInfoVo getChangeMoney(ReceiptPaymentDetailsInfoVo receiptPaymentDetailsInfoVo, String orgCode, String deptId, Integer deptType, BigDecimal changeMoney) {
+        receiptPaymentDetailsInfoVo.setDeptId(deptId);
+        receiptPaymentDetailsInfoVo.setDeptType(deptType);
+        receiptPaymentDetailsInfoVo.setOrgCode(orgCode);
+        receiptPaymentDetailsInfoVo.setChangeMoney(changeMoney);
+        return receiptPaymentDetailsInfoVo;
+    }
+
+    private BigDecimal getBigDecimal(BigDecimal bigDecimal1 ,BigDecimal bigDecimal2 ){
+        if (bigDecimal2.compareTo(BigDecimal.ZERO) <= 0) {
+            throw new IllegalArgumentException("扣款金额必须大于0");
+        }
+
+        if (bigDecimal1.compareTo(bigDecimal2) < 0) {
+            throw new IllegalArgumentException("余额不足");
+        }
+
+        return bigDecimal1.subtract(bigDecimal2);
+    }
+
     //退款回调  解密数据
     public String decryptToString(byte[] associatedData, byte[] nonce, String ciphertext) throws GeneralSecurityException, IOException {
         try {

+ 4 - 2
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/quartz/job/ProfitSharingJonService.java

@@ -1,5 +1,6 @@
 package org.jeecg.modules.quartz.job;
 
+import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -57,7 +58,8 @@ public class ProfitSharingJonService {
                 boolean validRange = isValidRange(localDate, 5);
                 if (validRange) {
                     //分账
-                    weChatProfitSharingService.profitSharing(appOrder.getOrderCode());
+                    JSONObject jsonObject = weChatProfitSharingService.profitSharing(appOrder.getOrderCode());
+
                 }
             }
         } catch (Exception e) {
@@ -78,7 +80,7 @@ public class ProfitSharingJonService {
             for (AppOrder appOrder : appOrders) {
                 sleep(1000);
                 //查询分账结果
-                weChatProfitSharingService.getProfitSharingResult(appOrder.getOrderCode());
+                JSONObject profitSharingResult = weChatProfitSharingService.getProfitSharingResult(appOrder.getOrderCode());
             }
         } catch (Exception e) {
             log.error("分账结果查询定时任务异常", e);