From 70f25657a7f1c5b1bfb1189759b9fa6f33b6922e Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期一, 09 十月 2023 13:35:48 +0800
Subject: [PATCH] 集成mqtt

---
 server/services/src/main/java/com/doumee/core/wx/WxMiniUtilService.java |   60 +++++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 47 insertions(+), 13 deletions(-)

diff --git a/server/services/src/main/java/com/doumee/core/wx/WxMiniUtilService.java b/server/services/src/main/java/com/doumee/core/wx/WxMiniUtilService.java
index d0da6cd..295eb7e 100644
--- a/server/services/src/main/java/com/doumee/core/wx/WxMiniUtilService.java
+++ b/server/services/src/main/java/com/doumee/core/wx/WxMiniUtilService.java
@@ -1,19 +1,28 @@
 package com.doumee.core.wx;
 
 import com.doumee.biz.system.SystemDictDataBiz;
+import com.doumee.core.constants.Constants;
 import com.doumee.core.constants.ResponseStatus;
 import com.doumee.core.exception.BusinessException;
 import com.doumee.core.utils.ID;
+import com.doumee.dao.business.RefundMapper;
+import com.doumee.dao.business.TransactionsMapper;
+import com.doumee.dao.business.model.Refund;
+import com.doumee.dao.business.model.Transactions;
+import com.doumee.dao.business.web.request.RefundDTO;
+import com.doumee.service.business.RefundService;
 import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest;
 import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest;
 import com.github.binarywang.wxpay.bean.result.WxPayRefundResult;
 import com.github.binarywang.wxpay.exception.WxPayException;
 import lombok.extern.slf4j.Slf4j;
+import org.checkerframework.checker.units.qual.A;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
+import java.util.Date;
 
 /**
  * 寰俊灏忕▼搴�-鍏叡鏂规硶
@@ -22,29 +31,55 @@
 @Slf4j
 public class WxMiniUtilService {
 
+    @Autowired
+    private RefundMapper refundMapper;
 
     @Autowired
-    private SystemDictDataBiz systemDictDataBiz;
+    private TransactionsMapper transactionsMapper;
 
-    /**
-     * 璁㈠崟寰俊閫�娆�
-     * orderNo:鍟嗘埛璁㈠崟鍙�
-     * totalPrice锛氳鍗曟�婚噾棰�
-     * refundPrice锛涢��娆鹃噾棰�
-     */
+
     @Transactional(rollbackFor = Exception.class)
-    public static String wxRefund(String orderNo, BigDecimal totalPrice, BigDecimal refundPrice) {
+    public Refund wxRefund(RefundDTO refundDTO) {
         try {
             // 鍙戦�侀��娆捐姹�
             String refNum = ID.nextGUID();
             WxPayRefundRequest request = new WxPayRefundRequest();
-            request.setOutTradeNo(orderNo);
+            request.setOutTradeNo(refundDTO.getOrderId());
             request.setOutRefundNo(refNum);
-            request.setTotalFee(BaseWxPayRequest.yuanToFen(totalPrice.toString()));
-            request.setRefundFee(BaseWxPayRequest.yuanToFen(refundPrice.toString()));
+            request.setTotalFee(BaseWxPayRequest.yuanToFen(refundDTO.getTotalAmount().toString()));
+            request.setRefundFee(BaseWxPayRequest.yuanToFen(refundDTO.getRefundAmount().toString()));
             WxPayRefundResult response = WxMiniConfig.wxPayService.refund(request);
             if ("SUCCESS".equals(response.getReturnCode()) && "SUCCESS".equals(response.getResultCode())) {
-                return refNum;
+                //瀛樺偍閫�娆捐褰� 涓� 娴佹按璁板綍
+                Refund refund = new Refund();
+                refund.setCreateDate(new Date());
+                refund.setMemberId(refundDTO.getMemberId());
+                refund.setMoney(refundDTO.getRefundAmount());
+                refund.setOnlineOrderid(refNum);
+                refund.setPayWay(Constants.ZERO);
+                refund.setDoneDate(new Date());
+                refund.setType(refundDTO.getType());
+                refund.setObjId(refundDTO.getOrderId());
+                refund.setReason(refundDTO.getReason());
+                refundMapper.insert(refund);
+                //瀛樺偍浜ゆ槗娴佹按琛�
+                Transactions transactions = new Transactions();
+                transactions.setMemberId(refundDTO.getMemberId());
+                transactions.setCreateDate(new Date());
+                transactions.setIsdeleted(Constants.ZERO);
+                transactions.setOrderId(refundDTO.getOrderId());
+                transactions.setMoney(refundDTO.getRefundAmount());
+                transactions.setType(refundDTO.getType()==Constants.transactionsType.refund?Constants.transactionsType.platformRefund:Constants.transactionsType.refund);
+                transactions.setPreOrderid(refundDTO.getOrderId());
+                transactions.setOnlineOrderid(refNum);
+                transactions.setDoneDate(new Date());
+                transactions.setTitle("閫�娆�");
+                transactions.setContent(refundDTO.getType()==Constants.transactionsType.refund?"骞冲彴閫�娆�":"缁撶畻閫�娆�");
+                transactions.setBalance(BigDecimal.ZERO);
+                transactions.setObjId(refund.getId());
+                transactions.setObjType(Constants.ONE);
+                transactionsMapper.insert(transactions);
+                return refund;
             } else{
                 throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),response.getErrCode() + response.getErrCodeDes());
             }
@@ -53,6 +88,5 @@
         }
         throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"閫�娆惧彂鐢熷紓甯歌鑱旂郴绠$悊鍛�");
     }
-
 
 }

--
Gitblit v1.9.3