From 8e7d88adae4ec8bc4e6f19dcdb0173d55eb440fb Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Wed, 14 May 2025 18:36:07 +0800
Subject: [PATCH] 1

---
 src/main/java/com/nq/service/impl/SiteAdminServiceImpl.java |  179 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 170 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/nq/service/impl/SiteAdminServiceImpl.java b/src/main/java/com/nq/service/impl/SiteAdminServiceImpl.java
index 4b8abe0..863377c 100644
--- a/src/main/java/com/nq/service/impl/SiteAdminServiceImpl.java
+++ b/src/main/java/com/nq/service/impl/SiteAdminServiceImpl.java
@@ -1,19 +1,16 @@
 package com.nq.service.impl;
 
+import cn.hutool.core.collection.CollectionUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.nq.dao.SiteAdminMapper;
+import com.nq.dao.*;
 import com.github.pagehelper.PageHelper;
 
 import com.github.pagehelper.PageInfo;
 
 import com.nq.common.ServerResponse;
 
-import com.nq.dao.UserMapper;
-import com.nq.dao.UserRechargeMapper;
-import com.nq.dao.UserWithdrawMapper;
-import com.nq.pojo.SiteAdmin;
-
-import com.nq.pojo.UserRecharge;
+import com.nq.pojo.*;
 
 import com.nq.service.IAgentUserService;
 
@@ -29,6 +26,7 @@
 
 import com.nq.service.IUserWithdrawService;
 
+import com.nq.utils.ConverterUtil;
 import com.nq.utils.PropertiesUtil;
 
 import com.nq.utils.SymmetricCryptoUtil;
@@ -41,9 +39,11 @@
 
 import java.math.BigDecimal;
 
-import java.util.Date;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
 
-import java.util.List;
+import java.util.stream.Collectors;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
@@ -103,6 +103,11 @@
     @Resource
     UserMapper userMapper;
 
+    @Resource
+    UserWithdrawMapper userWithdrawMapper;
+
+    @Autowired
+    AgentUserMapper agentUserMapper;
 
     public ServerResponse login(String adminPhone, String adminPwd, String verifyCode, HttpServletRequest request) {
 
@@ -352,6 +357,124 @@
 
     }
 
+    @Override
+    public ServerResponse moneyCount(String agentId,String startTime, String entTime) {
+        BigDecimal todayRechargeAmount = BigDecimal.ZERO;//今日充值金额
+        BigDecimal todayWithdrawAmount = BigDecimal.ZERO;//今日提现金额
+        Long todayRegister = 0L;//今日注册
+        Long todayWithdraw = 0L;//今日充值总人数
+        BigDecimal rechargeTotalAmount = BigDecimal.ZERO;//总充值金额
+        BigDecimal withdrawalTotalAmount = BigDecimal.ZERO;//总提现金额
+
+        Map<String, Object> map = new HashMap<>();
+        map.put("todayRechargeAmount", todayRechargeAmount);
+        map.put("todayWithdrawAmount", todayWithdrawAmount);
+        map.put("todayRegister", todayRegister);
+        map.put("todayWithdraw", todayWithdraw);
+        map.put("rechargeTotalAmount", rechargeTotalAmount);
+        map.put("withdrawalTotalAmount", withdrawalTotalAmount);
+
+        //今日开始结束时间
+        LocalDate currentDate  = LocalDate.now();
+        LocalDate  nextDay = currentDate.plusDays(1);
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        String start = currentDate.format(formatter);
+        String end = nextDay.format(formatter);
+        List<Integer> userIds  = null;
+        if(StringUtils.isNotEmpty(agentId)){
+            //当前代理
+            AgentUser agentUser = agentUserMapper.selectById(agentId);
+            if(null == agentUser){
+                return ServerResponse.createBySuccess(map);
+            }
+            List<AgentUser> lowerAgentUsers = agentUserMapper.selectList(new LambdaQueryWrapper<AgentUser>());
+            AgentUserNodeVO userNodeVO = ConverterUtil.convert(agentUser, AgentUserNodeVO.class);
+            List<AgentUserNodeVO> agentUserNodeVOS = ConverterUtil.convertToList(lowerAgentUsers, AgentUserNodeVO.class);
+            List<AgentUserNodeVO> nodeJson = getNodeJson(userNodeVO, agentUserNodeVOS);
+            userNodeVO.setChildList(nodeJson);
+            //当前节点和子节点的id
+            List<Integer>  ids  =  getAllChildrenIds(userNodeVO);
+            //查询代理id下面所有的用户
+            List<User> users = userMapper.selectList(new LambdaQueryWrapper<User>().in(User::getAgentId, ids));
+            userIds = users.stream().map(User::getId).collect(Collectors.toList());
+        }
+        if((StringUtils.isNotEmpty(agentId) && CollectionUtil.isNotEmpty(userIds)) || StringUtils.isEmpty(agentId)){
+            //今日充值
+            List<UserRecharge> todayRecharges = userRechargeMapper.selectList(new LambdaQueryWrapper<UserRecharge>().eq(UserRecharge::getOrderStatus, 1)
+                    .ge(UserRecharge::getPayTime, start)
+                    .le(UserRecharge::getPayTime, end)
+                    .in(CollectionUtil.isNotEmpty(userIds),UserRecharge::getUserId,userIds));
+
+            //今日提现
+            List<UserWithdraw> todayWithdraws = userWithdrawMapper.selectList(new LambdaQueryWrapper<UserWithdraw>().eq(UserWithdraw::getWithStatus, 1)
+                    .ge(UserWithdraw::getTransTime, start)
+                    .le(UserWithdraw::getTransTime, end)
+                    .in(CollectionUtil.isNotEmpty(userIds),UserWithdraw::getUserId,userIds));
+
+            //总充值
+            List<UserRecharge> userRecharges = userRechargeMapper.selectList(new LambdaQueryWrapper<UserRecharge>().eq(UserRecharge::getOrderStatus, 1)
+                    .ge(StringUtils.isNotBlank(startTime), UserRecharge::getPayTime, startTime)
+                    .le(StringUtils.isNotBlank(entTime), UserRecharge::getPayTime, entTime)
+                    .in(CollectionUtil.isNotEmpty(userIds),UserRecharge::getUserId,userIds));
+
+            //总提现
+            List<UserWithdraw> userWithdraws = userWithdrawMapper.selectList(new LambdaQueryWrapper<UserWithdraw>().eq(UserWithdraw::getWithStatus, 1)
+                    .ge(StringUtils.isNotBlank(startTime), UserWithdraw::getTransTime, startTime)
+                    .le(StringUtils.isNotBlank(entTime), UserWithdraw::getTransTime, entTime)
+                    .in(CollectionUtil.isNotEmpty(userIds),UserWithdraw::getUserId,userIds));
+
+            //今日注册数量
+            todayRegister = userMapper.selectCount(new LambdaQueryWrapper<User>()
+                    .ge(User::getRegTime, start)
+                    .le(User::getRegTime, end)
+                    .in(CollectionUtil.isNotEmpty(userIds),User::getId,userIds));
+
+            for (UserRecharge userRecharge : todayRecharges) {
+                todayRechargeAmount = todayRechargeAmount.add(userRecharge.getPayAmt());
+            }
+
+            for (UserWithdraw userWithdraw : todayWithdraws) {
+                todayWithdrawAmount = todayWithdrawAmount.add(userWithdraw.getWithAmt());
+            }
+
+            for (UserRecharge userRecharge : userRecharges) {
+                rechargeTotalAmount = rechargeTotalAmount.add(userRecharge.getPayAmt());
+            }
+
+            for (UserWithdraw userWithdraw : userWithdraws) {
+                withdrawalTotalAmount = withdrawalTotalAmount.add(userWithdraw.getWithAmt());
+            }
+
+            List<UserRecharge> distinctCustomers = todayRecharges.stream()
+                    .collect(Collectors.toMap(UserRecharge::getUserId, c -> c, (c1, c2) -> c1))
+                    .values().stream()
+                    .collect(Collectors.toList());
+            todayWithdraw = Long.valueOf(distinctCustomers.size());
+        }
+
+        map.put("todayRechargeAmount", todayRechargeAmount);
+        map.put("todayWithdrawAmount", todayWithdrawAmount);
+        map.put("todayRegister", todayRegister);
+        map.put("todayWithdraw", todayWithdraw);
+        map.put("rechargeTotalAmount", rechargeTotalAmount);
+        map.put("withdrawalTotalAmount", withdrawalTotalAmount);
+        return ServerResponse.createBySuccess(map);
+    }
+
+    public  static  List<Integer>  getAllChildrenIds(AgentUserNodeVO  parent)  {
+        List<Integer>  allChildrenIds  =  new ArrayList<>();
+        getAllChildrenIdsHelper(parent,  allChildrenIds);
+        return  allChildrenIds;
+    }
+    private  static  void  getAllChildrenIdsHelper(AgentUserNodeVO  node,  List<Integer>  allChildrenIds)  {
+        allChildrenIds.add(node.getId());
+        if(CollectionUtil.isNotEmpty(node.getChildList())){
+            for  (AgentUserNodeVO  child  :  node.getChildList())  {
+                getAllChildrenIdsHelper(child,  allChildrenIds);
+            }
+        }
+    }
+
     public ServerResponse deleteAdmin(Integer adminId) {
 
         if (adminId == null) {
@@ -369,6 +492,44 @@
 
     }
 
+    public List<AgentUserNodeVO> getNodeJson(AgentUserNodeVO agentUser, List<AgentUserNodeVO> nodes){
+
+        //当前层级当前点下的所有子节点
+        List<AgentUserNodeVO> childList = getChildNodes(agentUser.getId(),nodes);
+        List<AgentUserNodeVO> list = new ArrayList<>();
+        childList.forEach(f->{
+            List<AgentUserNodeVO> childs = getNodeJson(f,nodes);  //递归调用该方法
+            if(!childs.isEmpty()) {
+                f.setChildList(childs);
+            }
+            list.add(f);
+        });
+        return list;
+    }
+
+    /**
+     * 获取当前节点的所有子节点
+     * @param nodeId
+     * @param nodes
+     * @return
+     */
+    public List<AgentUserNodeVO> getChildNodes(Integer nodeId, List<AgentUserNodeVO> nodes){
+        List<AgentUserNodeVO> list = new ArrayList<>();
+        nodes.forEach(f->{
+            if(f.getParentId().equals(nodeId)){
+                list.add(f);
+            }
+        });
+        return list;
+    }
+
+
+    public String getDate(){
+        LocalDate currentDate  =  LocalDate.now();
+        DateTimeFormatter  formatter  =  DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        return currentDate.format(formatter);
+    }
+
 
     public SiteAdmin findAdminByName(String name) {
         return this.siteAdminMapper.findAdminByName(name);

--
Gitblit v1.9.3