Kaynağa Gözat

财务统计金额优化成根据筛选项来统计金额,默认状态下为全部订单金额

luolinsong 1 ay önce
ebeveyn
işleme
369aad8d36

+ 7 - 26
fs-admin/src/main/java/com/fs/hisStore/controller/FsStorePaymentScrmController.java

@@ -86,40 +86,21 @@ public class FsStorePaymentScrmController extends BaseController
             fsStorePayment.setCreateTimeList(fsStorePayment.getCreateTimeRange().split("--"));
         }
         List<FsStorePaymentVO> list = fsStorePaymentService.selectFsStorePaymentListQuery(fsStorePayment);
-        
+        Map<String, BigDecimal> totalAmountMap = fsStorePaymentService.calculateTotalAmount(fsStorePayment);
         // 计算总支付金额和总退款金额
-        BigDecimal totalPaymentAmount = BigDecimal.ZERO;
-        BigDecimal totalRefundAmount = BigDecimal.ZERO;
-        
+        BigDecimal totalPaymentAmount = totalAmountMap.get("totalPaymentAmount");
+        BigDecimal totalRefundAmount = totalAmountMap.get("totalRefundAmount");
+
         for (FsStorePaymentVO vo : list){
             vo.setUserPhone(ParseUtils.parsePhone(vo.getUserPhone()));
-            
-            // 状态为1(已支付)或-1(已退款)时,累加到总支付金额
-            if (vo.getStatus() != null && (vo.getStatus() == 1 || vo.getStatus() == -1)) {
-                if (vo.getPayMoney() != null) {
-                    totalPaymentAmount = totalPaymentAmount.add(vo.getPayMoney());
-                }
-            }
-            
-            // 状态为-1(已退款)时,累加到总退款金额
-            // 根据规范,只统计退款审核状态为2(审核完成)的退款金额
-            if (vo.getStatus() != null && vo.getStatus() == -1) {
-                if (vo.getRefundAuditStatus() != null && vo.getRefundAuditStatus() == 2) {
-                    if (vo.getRefundMoney() != null) {
-                        totalRefundAmount = totalRefundAmount.add(vo.getRefundMoney());
-                    }
-                }
-            }
         }
-        
         // 记录查询条件和统计结果
         logger.info("支付明细列表查询,查询条件:{},查询结果数量:{},总支付金额:{},总退款金额:{}",
             fsStorePayment, list.size(), totalPaymentAmount, totalRefundAmount);
-        
         TableDataInfo dataTable = getDataTable(list);
         dataTable.put("totalPaymentAmount", totalPaymentAmount);
         dataTable.put("totalRefundAmount", totalRefundAmount);
-        
+
         return dataTable;
     }
 
@@ -215,12 +196,12 @@ public class FsStorePaymentScrmController extends BaseController
         if(payment.getStatus()!=1){
             return R.error("非法操作");
         }
-        
+
         // 检查退款审核状态
         if(payment.getRefundAuditStatus() == null || payment.getRefundAuditStatus() != 1){
             return R.error("退款申请尚未审核或审核未通过,不能执行退款");
         }
-        
+
         if(fsStorePayment.getRefundMoney().compareTo(new BigDecimal(0))<1){
             return R.error("退款金额必须大于0");
         }

+ 57 - 4
fs-service/src/main/java/com/fs/hisStore/mapper/FsStorePaymentScrmMapper.java

@@ -5,14 +5,12 @@ import com.fs.hisStore.domain.FsStorePaymentScrm;
 import com.fs.hisStore.param.FsStorePaymentParam;
 import com.fs.hisStore.param.FsStoreScanPaymentStatParam;
 import com.fs.hisStore.param.FsStoreStatisticsParam;
-import com.fs.hisStore.vo.FsStorePaymentStatisticsVO;
-import com.fs.hisStore.vo.FsStorePaymentVO;
-import com.fs.hisStore.vo.FsStoreScanPaymentStatDetailsVo;
-import com.fs.hisStore.vo.FsStoreScanPaymentStatVo;
+import com.fs.hisStore.vo.*;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 import org.apache.ibatis.annotations.Update;
 
+import java.math.BigDecimal;
 import java.util.List;
 import java.util.Map;
 
@@ -142,6 +140,61 @@ public interface FsStorePaymentScrmMapper
             "</script>"})
     List<FsStorePaymentVO> selectFsStorePaymentListQuery(@Param("maps") FsStorePaymentParam fsStorePayment);
 
+    @Select({"<script> " +
+            "select  SUM(CASE WHEN p.status IN (1, -1) AND p.pay_money IS NOT NULL  THEN p.pay_money ELSE 0 END) AS  totalPaymentAmount, SUM(CASE WHEN p.status = '-1' AND p.refund_audit_status = '2' AND refund_money IS NOT NULL THEN p.refund_money ELSE 0 END) AS totalRefundAmount  from fs_store_payment_scrm p left join company_user cu on p.company_user_id=cu.user_id left join fs_user u on u.user_id=p.user_id left join company_dept d on d.dept_id=p.dept_id left join company c on c.company_id=p.company_id left join fs_store_order_scrm o on o.id=p.order_id   " +
+            "where 1=1 " +
+            "<if test = 'maps.payCode != null and  maps.payCode !=\"\"    '> " +
+            "and p.pay_code like CONCAT('%',#{maps.payCode},'%') " +
+            "</if>" +
+            "<if test = 'maps.orderCode != null and  maps.orderCode !=\"\"    '> " +
+            "and o.order_code like CONCAT('%',#{maps.orderCode},'%') " +
+            "</if>" +
+            "<if test = 'maps.tradeNo != null and  maps.tradeNo !=\"\"    '> " +
+            "and p.trade_no like CONCAT('%',#{maps.tradeNo},'%') " +
+            "</if>" +
+            "<if test = 'maps.bankSerialNo != null and  maps.bankSerialNo !=\"\"    '> " +
+            "and p.bank_serial_no like CONCAT('%',#{maps.bankSerialNo},'%') " +
+            "</if>" +
+            "<if test = 'maps.mobile != null and  maps.mobile !=\"\"     '> " +
+            "and u.phone like CONCAT('%',#{maps.mobile},'%') " +
+            "</if>" +
+            "<if test = 'maps.status != null    '> " +
+            "and p.status =#{maps.status} " +
+            "</if>" +
+            "<if test = 'maps.businessType != null    '> " +
+            "and p.business_type =#{maps.businessType} " +
+            "</if>" +
+            "<if test = 'maps.companyId != null    '> " +
+            "and p.company_id =#{maps.companyId} " +
+            "</if>" +
+            "<if test = 'maps.params != null and maps.params != \"\"   '> " +
+            "<if test = 'maps.params.beginTime != null and maps.params.beginTime != \"\"   '> " +
+            " AND date_format(p.pay_time,'%y%m%d') &gt;= date_format(#{maps.params.beginTime},'%y%m%d') " +
+            "</if>" +
+            "<if test = 'maps.params.endTime != null and maps.params.endTime != \"\"   '> " +
+            " AND date_format(p.pay_time,'%y%m%d') &lt;= date_format(#{maps.params.endTime},'%y%m%d') " +
+            "</if>" +
+            "</if>" +
+            "<if test = 'maps.refundBeginTime != null  and maps.refundBeginTime != \"\"    '> " +
+            "and DATE_FORMAT(p.refund_time,'%y%m%d') &gt;= date_format(#{maps.refundBeginTime},'%y%m%d')  " +
+            "</if>" +
+            "<if test = 'maps.refundEndTime != null and maps.refundEndTime != \"\"   '> " +
+            " AND date_format(p.refund_time,'%y%m%d') &lt;= date_format(#{maps.refundEndTime},'%y%m%d') " +
+            "</if>" +
+            "<if test = 'maps.bankTransactionId != null and  maps.bankTransactionId !=\"\"     '> " +
+            "and p.bank_transaction_id like CONCAT('%',#{maps.bankTransactionId},'%') " +
+            "</if>" +
+            "<if test = 'maps.companyUserNickName != null and  maps.companyUserNickName !=\"\"     '> " +
+            "and cu.nick_name like CONCAT('%',#{maps.companyUserNickName},'%') " +
+            "</if>" +
+            "<if test = 'maps.createTimeList != null    '> " +
+            " AND date_format(p.create_time,'%y%m%d') &gt;= date_format(#{maps.createTimeList[0]},'%y%m%d') " +
+            " AND date_format(p.create_time,'%y%m%d') &lt;= date_format(#{maps.createTimeList[1]},'%y%m%d') " +
+            "</if>" +
+            " order by p.payment_id desc "+
+            "</script>"})
+    FsStorePaymentAmountVO calculateTotalAmount(@Param("maps") FsStorePaymentParam fsStorePayment);
+
 
     @Select({"<script> " +
             "select p.*,o.order_code,fsp.title, c.company_name,u.phone as user_phone,cu.nick_name as company_user_nick_name,cu.user_name as company_user_name " +

+ 3 - 1
fs-service/src/main/java/com/fs/hisStore/service/IFsStorePaymentScrmService.java

@@ -11,6 +11,7 @@ import com.fs.hisStore.vo.FsStoreScanPaymentStatDetailsVo;
 import com.fs.hisStore.vo.FsStoreScanPaymentStatVo;
 
 import javax.servlet.http.HttpServletRequest;
+import java.math.BigDecimal;
 import java.util.List;
 import java.util.Map;
 
@@ -75,6 +76,7 @@ public interface IFsStorePaymentScrmService
     FsStorePaymentScrm selectFsStorePaymentByCode(String payCode);
 
     List<FsStorePaymentVO> selectFsStorePaymentListQuery(FsStorePaymentParam fsStorePayment);
+    Map<String, BigDecimal>  calculateTotalAmount(FsStorePaymentParam fsStorePayment);
 
     List<FsStorePaymentVO> exportFsStorePaymentList(FsStorePaymentParam fsStorePayment);
 
@@ -152,4 +154,4 @@ public interface IFsStorePaymentScrmService
     R auditRefund(Long paymentId, Integer auditStatus, String auditRemark, String auditor);
 
 
-}
+}

+ 16 - 9
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStorePaymentScrmServiceImpl.java

@@ -40,11 +40,7 @@ import com.fs.hisStore.mapper.FsStorePaymentScrmMapper;
 import com.fs.hisStore.param.*;
 import com.fs.hisStore.service.IFsStorePaymentScrmService;
 import com.fs.hisStore.service.IFsUserScrmService;
-import com.fs.hisStore.vo.FsStorePaymentStatisticsVO;
-import com.fs.hisStore.vo.FsStorePaymentVO;
-import com.fs.hisStore.vo.FsStoreScanPaymentDetailVo;
-import com.fs.hisStore.vo.FsStoreScanPaymentStatDetailsVo;
-import com.fs.hisStore.vo.FsStoreScanPaymentStatVo;
+import com.fs.hisStore.vo.*;
 import com.fs.huifuPay.domain.HuiFuCreateOrder;
 import com.fs.huifuPay.domain.HuifuCreateOrderResult;
 import com.fs.huifuPay.sdk.opps.core.utils.HuiFuUtils;
@@ -78,10 +74,7 @@ import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
 import java.time.LocalDate;
 import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * 支付明细Service业务层处理
@@ -304,6 +297,20 @@ public class FsStorePaymentScrmServiceImpl implements IFsStorePaymentScrmService
         return fsStorePaymentMapper.selectFsStorePaymentListQuery(fsStorePayment);
     }
 
+    @Override
+    public Map<String, BigDecimal> calculateTotalAmount(FsStorePaymentParam fsStorePayment) {
+        FsStorePaymentAmountVO  fsStorePaymentAmountVO =fsStorePaymentMapper.calculateTotalAmount(fsStorePayment);
+        BigDecimal totalPaymentAmount = fsStorePaymentAmountVO.getTotalPaymentAmount() == null
+                ? BigDecimal.ZERO : fsStorePaymentAmountVO.getTotalPaymentAmount();
+        BigDecimal totalRefundAmount = fsStorePaymentAmountVO.getTotalRefundAmount() == null
+                ? BigDecimal.ZERO : fsStorePaymentAmountVO.getTotalRefundAmount();
+
+        Map<String, BigDecimal> resultMap = new HashMap<>();
+        resultMap.put("totalPaymentAmount", totalPaymentAmount);
+        resultMap.put("totalRefundAmount", totalRefundAmount);
+        return resultMap;
+    }
+
     @Override
     public List<FsStorePaymentVO> exportFsStorePaymentList(FsStorePaymentParam fsStorePayment) {
         return fsStorePaymentMapper.exportFsStorePaymentList(fsStorePayment);

+ 13 - 0
fs-service/src/main/java/com/fs/hisStore/vo/FsStorePaymentAmountVO.java

@@ -0,0 +1,13 @@
+package com.fs.hisStore.vo;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class FsStorePaymentAmountVO {
+    // 总支付金额(状态为1已支付 或 -1已退款 的 payMoney 总和)
+    private BigDecimal totalPaymentAmount;
+    // 总退款金额(状态为-1已退款 且 退款审核状态为2审核完成 的 refundMoney 总和)
+    private BigDecimal totalRefundAmount;
+}