From 029d0af8d3e0d32dbfff8dc47fb5e997332bc01d Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期一, 06 十一月 2023 10:10:40 +0800
Subject: [PATCH] 修改bug

---
 ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/domain/pojo/account/OrderPayment.java             |    5 +++++
 ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/account/OrderPaymentService.java          |    2 +-
 ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/miniapp/NotifyController.java          |    5 +++--
 ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/account/OrderPaymentServiceImpl.java |    3 ++-
 ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/controller/miniapp/AppHomeController.java           |    2 ++
 ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/domain/vo/WeixinPaymentNotifyVo.java              |    8 ++++++++
 ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/order/OrderService.java                   |    2 +-
 ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java          |   13 +++++++++----
 ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/util/HuiFuTianXiaUtil.java                        |    2 ++
 9 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/miniapp/NotifyController.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/miniapp/NotifyController.java
index 58c3808..9c4bc5a 100644
--- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/miniapp/NotifyController.java
+++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/miniapp/NotifyController.java
@@ -38,6 +38,7 @@
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.math.BigDecimal;
 import java.nio.charset.StandardCharsets;
 import java.security.GeneralSecurityException;
 import java.util.Collection;
@@ -96,7 +97,7 @@
                 PartnerTransactionsResult result = notifyResult.getResult();
                 // 支付通知回调
                 if ("SUCCESS".equals(result.getTradeState())) {
-                    orderService.payBack(result);
+                    orderService.payBack(result, BigDecimal.ONE);
                 }
                 resultMessage = GSON.toJson(notifyResult);
             } else if (WxPayNotifyEventTypeEnum.REFUND_SUCCESS.getCode().equals(eventType)
@@ -240,7 +241,7 @@
                 PartnerTransactionsResult transaction = new PartnerTransactionsResult();
                 transaction.setOutTradeNo(data.getReqSeqId());
                 //开始处理业务数据
-                orderService.payBack(transaction);
+                orderService.payBack(transaction, data.getFeeFlag() == 1 ? BigDecimal.ZERO : new BigDecimal(data.getFeeAmount()));
 
                 response.setStatus(200);
                 PrintWriter out = null;
diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/domain/pojo/account/OrderPayment.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/domain/pojo/account/OrderPayment.java
index 9af071b..eb61951 100644
--- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/domain/pojo/account/OrderPayment.java
+++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/domain/pojo/account/OrderPayment.java
@@ -78,6 +78,11 @@
     @TableField("pay_money")
     private BigDecimal payMoney;
     /**
+     * 手续费
+     */
+    @TableField("fee_amount")
+    private BigDecimal feeAmount;
+    /**
      * 失效时间
      */
     @TableField("time_expire")
diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/domain/vo/WeixinPaymentNotifyVo.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/domain/vo/WeixinPaymentNotifyVo.java
index ed6cf4e..49f5c75 100644
--- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/domain/vo/WeixinPaymentNotifyVo.java
+++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/domain/vo/WeixinPaymentNotifyVo.java
@@ -32,4 +32,12 @@
      * 交易状态 S:成功、F:失败
      */
     private String transStat;
+    /**
+     * 手续费扣款标志 1: 外扣,2: 内扣
+     */
+    private Integer feeFlag;
+    /**
+     * 手续费金额
+     */
+    private String feeAmount;
 }
diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/account/OrderPaymentService.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/account/OrderPaymentService.java
index d0318a9..6690a60 100644
--- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/account/OrderPaymentService.java
+++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/account/OrderPaymentService.java
@@ -43,5 +43,5 @@
      * @param outTradeNo
      * @param transactionId
      */
-    void updatePaySuccess(String outTradeNo, String transactionId);
+    void updatePaySuccess(String outTradeNo, BigDecimal feeAmount, String transactionId);
 }
diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/account/OrderPaymentServiceImpl.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/account/OrderPaymentServiceImpl.java
index 8625cba..3477bcf 100644
--- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/account/OrderPaymentServiceImpl.java
+++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/account/OrderPaymentServiceImpl.java
@@ -68,11 +68,12 @@
     }
 
     @Override
-    public void updatePaySuccess(String outTradeNo, String transactionId) {
+    public void updatePaySuccess(String outTradeNo, BigDecimal feeAmount, String transactionId) {
         LambdaUpdateWrapper<OrderPayment> updateWrapper = Wrappers.lambdaUpdate();
         updateWrapper.eq(OrderPayment::getOutTradeNo, outTradeNo)
                 .set(OrderPayment::getPayStatus, 2)
                 .set(OrderPayment::getTransactionId, transactionId)
+                .set(OrderPayment::getFeeAmount, feeAmount)
                 .set(OrderPayment::getBackTime, new Date());
         this.update(updateWrapper);
     }
diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java
index 8eaf64d..6bc5a49 100644
--- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java
+++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java
@@ -4,6 +4,7 @@
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -1897,10 +1898,14 @@
         }
         this.saveOrUpdate(order);
         // 订单金额大于0时进行分账
-        if (order.getOnlinePayMoney().compareTo(BigDecimal.ZERO)>0) {
+        OrderPayment orderPayment = orderPaymentService.getOne(new QueryWrapper<OrderPayment>()
+                .eq("order_id", order.getOrderId()).eq("pay_status", 2)
+                .eq("del_flag", 0));
+        BigDecimal bigDecimal = orderPayment.getPayMoney().subtract(orderPayment.getFeeAmount()).setScale(2, BigDecimal.ROUND_HALF_EVEN);
+        if (bigDecimal.compareTo(BigDecimal.ZERO)>0) {
             // TODO: 2023/10/17  更换分账渠道(汇付天下)
 //            submitProfitSharing(orderId, order.getOrderNo(), order.getShopId(), order.getOnlinePayMoney(),order.getOrderFrom());
-            submitProfitSharing1(orderId, order.getOrderNo(), order.getShopId(), order.getOnlinePayMoney(),order.getOrderFrom());
+            submitProfitSharing1(orderId, order.getOrderNo(), order.getShopId(), bigDecimal, order.getOrderFrom());
         }
         //创建支付记录
         if(merVerifyOrderDto.getRelPayMoney().compareTo(BigDecimal.ZERO)>0){
@@ -5122,7 +5127,7 @@
     @Override
     @Transactional
     @GlobalTransactional(rollbackFor = Exception.class)
-    public void payBack(PartnerTransactionsResult transaction) {
+    public void payBack(PartnerTransactionsResult transaction, BigDecimal feeAmount) {
         log.info("订单支付回调---"+transaction.toString());
         // Order order = this.getById(orderId);
         // 更新订单状态 outTradeNo
@@ -5256,7 +5261,7 @@
             profitsSharingService.applyProfitSharing(request);*/
         }
         //修改支付记录生成支付记录
-        orderPaymentService.updatePaySuccess(transaction.getOutTradeNo(), transaction.getTransactionId());
+        orderPaymentService.updatePaySuccess(transaction.getOutTradeNo(), feeAmount, transaction.getTransactionId());
         PayRecord payRecord = new PayRecord();
         payRecord.setDelFlag(0);
         payRecord.setOrderId(orderId);
diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/order/OrderService.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/order/OrderService.java
index be5d986..3bca1e3 100644
--- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/order/OrderService.java
+++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/order/OrderService.java
@@ -433,7 +433,7 @@
      * @param  transaction
      * @return  void
      */
-    void payBack(PartnerTransactionsResult transaction);
+    void payBack(PartnerTransactionsResult transaction, BigDecimal feeAmount);
 
     /**
      * 取消订单
diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/util/HuiFuTianXiaUtil.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/util/HuiFuTianXiaUtil.java
index 83f0254..0cba250 100644
--- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/util/HuiFuTianXiaUtil.java
+++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/util/HuiFuTianXiaUtil.java
@@ -139,6 +139,8 @@
             vo.setPayAmt(resp_data.getString("pay_amt"));
             vo.setEndTime(resp_data.getString("end_time"));
             vo.setTransStat(resp_data.getString("trans_stat"));
+            vo.setFeeFlag(resp_data.getInteger("fee_flag"));
+            vo.setFeeAmount(resp_data.getString("fee_amount"));
             return R.ok(vo);
         }
         return R.fail(resp_desc);
diff --git a/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/controller/miniapp/AppHomeController.java b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/controller/miniapp/AppHomeController.java
index 2635e11..bf20bb0 100644
--- a/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/controller/miniapp/AppHomeController.java
+++ b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/controller/miniapp/AppHomeController.java
@@ -1,5 +1,6 @@
 package com.ruoyi.shop.controller.miniapp;
 
+import com.alibaba.fastjson.JSON;
 import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.security.utils.SecurityUtils;
 import com.ruoyi.shop.domain.dto.AppNearbyShopDto;
@@ -48,6 +49,7 @@
         if(userId!=null){
             member = memberService.getMember(userId).getData();
         }
+        log.info("获取最近商户:userId=" + userId + "&appNearbyShopDto=" + JSON.toJSONString(appNearbyShopDto));
         appNearbyShopDto.setUserId(userId);
         AppNearbyShopVo appNearbyShopVo = shopService.getNearbyShop(appNearbyShopDto,member);
         return R.ok(appNearbyShopVo);

--
Gitblit v1.7.1