From 52df45c5210c72fd6f89939780041a4482e41618 Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Tue, 22 Jul 2025 19:25:20 +0800
Subject: [PATCH] 1

---
 src/main/java/com/nq/service/impl/SiteAdminServiceImpl.java |  248 ++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 213 insertions(+), 35 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..69b940e 100644
--- a/src/main/java/com/nq/service/impl/SiteAdminServiceImpl.java
+++ b/src/main/java/com/nq/service/impl/SiteAdminServiceImpl.java
@@ -1,19 +1,18 @@
 package com.nq.service.impl;
 
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.nq.dao.SiteAdminMapper;
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.extra.qrcode.QrCodeUtil;
+import cn.hutool.extra.qrcode.QrConfig;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+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,9 +28,11 @@
 
 import com.nq.service.IUserWithdrawService;
 
+import com.nq.utils.ConverterUtil;
 import com.nq.utils.PropertiesUtil;
 
 import com.nq.utils.SymmetricCryptoUtil;
+import com.nq.utils.redis.CookieUtils;
 import com.nq.utils.redis.JsonUtil;
 import com.nq.utils.redis.RedisConst;
 import com.nq.utils.redis.RedisShardedPoolUtils;
@@ -41,9 +42,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,54 +106,49 @@
     @Resource
     UserMapper userMapper;
 
+    @Resource
+    UserWithdrawMapper userWithdrawMapper;
 
-    public ServerResponse login(String adminPhone, String adminPwd, String verifyCode, HttpServletRequest request) {
+    @Autowired
+    AgentUserMapper agentUserMapper;
+
+    public ServerResponse login(String adminPhone, String adminPwd, String verifyCode,Integer googleAuthCode, HttpServletRequest request) {
 
         if (StringUtils.isBlank(verifyCode)) {
-
             return ServerResponse.createByErrorMsg("验证码不能为空");
-
         }
-//
-        String original = (String) request.getSession().getAttribute("KAPTCHA_SESSION_KEY");
 
-        /*if (!verifyCode.equalsIgnoreCase(original)) {
-
-            return ServerResponse.createByErrorMsg("验证码错误");
-
-        }*/
-
-
-        if (StringUtils.isBlank(adminPhone) || StringUtils.isBlank(adminPwd)) {
+        if (StringUtils.isBlank(adminPhone) || StringUtils.isBlank(adminPwd) ) {
 
             return ServerResponse.createByErrorMsg("参数不能为空");
 
         }
-
-        SymmetricCryptoUtil.decryptPassword("8OTlTNZ9EwQ29Pf0R8a37Q==");
         adminPwd = SymmetricCryptoUtil.encryptPassword(adminPwd);
         SiteAdmin siteAdmin = this.siteAdminMapper.login(adminPhone, adminPwd);
-//        SiteAdmin siteAdmin = (SiteAdmin) siteAdminMapper.selectOne(new QueryWrapper<SiteAdmin>().eq("admin_phone", adminPhone).eq("admin_pwd", adminPwd));
-
         if (siteAdmin == null) {
-
             return ServerResponse.createByErrorMsg("账号密码错误");
-
         }
-
-
         if (siteAdmin.getIsLock().intValue() == 1) {
-
             return ServerResponse.createByErrorMsg("账号已被锁定");
-
         }
-
+        if(siteAdmin.getGoogleAuthBind() && ObjectUtil.isEmpty(googleAuthCode)){
+            return ServerResponse.createByErrorMsg("谷歌验证码不能为空");
+        }
+        if(siteAdmin.getGoogleAuthBind()){
+            long t = System.currentTimeMillis();
+            GoogleAuthenticator ga = new GoogleAuthenticator();
+            ga.setWindowSize(5);
+            boolean userFlag = ga.check_code(siteAdmin.getGoogleAuthSecret(), Long.valueOf(googleAuthCode), t);
+            if (!userFlag) {
+                return ServerResponse.createByErrorMsg("谷歌验证码错误!");
+            }
+        }
 
         siteAdmin.setAdminPwd(null);
         HttpSession httpSession = request.getSession();
         String token = RedisConst.getAdminRedisKey(httpSession.getId());
 
-        String str = RedisShardedPoolUtils.setEx(token,
+        RedisShardedPoolUtils.setEx(token,
                 JsonUtil.obj2String(siteAdmin), 999999);
 
 
@@ -352,6 +350,148 @@
 
     }
 
+    @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);
+    }
+
+    @Override
+    public GoogleAuthDto getGoogleAuth(HttpServletRequest request) {
+        String secretKey = GoogleAuthenticator.generateSecretKey();
+        QrConfig config = new QrConfig(345, 345);
+        config.setMargin(3);
+        String cookie_name = PropertiesUtil.getProperty("admin.cookie.name");
+        SiteAdmin siteAdmin = null;
+        if(StringUtils.isNotEmpty(cookie_name)){
+            siteAdmin = getAdmin(cookie_name,request);
+        }
+        String content = String.format("otpauth://totp/%s?secret=%s", siteAdmin.getAdminName(),secretKey);
+        String base64 = QrCodeUtil.generateAsBase64(content, config, "png");
+        GoogleAuthDto dto = new GoogleAuthDto();
+        dto.setGoogleAuthImg(base64);
+        dto.setGoogleAuthSecret(secretKey);
+        return dto;
+    }
+
+    public SiteAdmin getAdmin(String cookie_name,HttpServletRequest request){
+        String logintoken = CookieUtils.readLoginToken(request, cookie_name);
+        String adminJson = RedisShardedPoolUtils.get(logintoken);
+        return (SiteAdmin) JsonUtil.string2Obj(adminJson, SiteAdmin.class);
+    }
+
+    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 +509,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