From d98c7875c62e6551ad8aee081242aad8d5f13efe Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Mon, 27 Apr 2026 17:14:18 +0800
Subject: [PATCH] 1

---
 src/main/java/com/nq/service/impl/AgentUserServiceImpl.java |   49 +++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/src/main/java/com/nq/service/impl/AgentUserServiceImpl.java b/src/main/java/com/nq/service/impl/AgentUserServiceImpl.java
index 0c1eab6..57b8240 100644
--- a/src/main/java/com/nq/service/impl/AgentUserServiceImpl.java
+++ b/src/main/java/com/nq/service/impl/AgentUserServiceImpl.java
@@ -18,6 +18,8 @@
 import com.nq.vo.admin.AdminCountVO;
 import com.nq.vo.agent.AgentInfoVO;
 import com.nq.vo.agent.AgentSecondInfoVO;
+import cn.hutool.extra.qrcode.QrCodeUtil;
+import cn.hutool.extra.qrcode.QrConfig;
 
 import java.math.BigDecimal;
 import java.util.Date;
@@ -89,7 +91,7 @@
     }
 
 
-    public ServerResponse login(String agentPhone, String agentPwd, String verifyCode, HttpServletRequest request) {
+    public ServerResponse login(String agentPhone, String agentPwd, String verifyCode, Integer googleAuthCode, HttpServletRequest request) {
 //        if (StringUtils.isBlank(verifyCode)) {
 //            return ServerResponse.createByErrorMsg("验证码不能为空");
 //        }
@@ -111,8 +113,37 @@
         if (agentUser.getIsLock().intValue() == 1) {
             return ServerResponse.createByErrorMsg("登陆失败,您的账号已被锁定!");
         }
+        if (Boolean.TRUE.equals(agentUser.getGoogleAuthBind()) && googleAuthCode == null) {
+            return ServerResponse.createByErrorMsg("谷歌验证码不能为空");
+        }
+        if (Boolean.TRUE.equals(agentUser.getGoogleAuthBind())) {
+            long t = System.currentTimeMillis();
+            GoogleAuthenticator ga = new GoogleAuthenticator();
+            ga.setWindowSize(5);
+            boolean userFlag = ga.check_code(agentUser.getGoogleAuthSecret(), Long.valueOf(googleAuthCode), t);
+            if (!userFlag) {
+                return ServerResponse.createByErrorMsg("谷歌验证码错误!");
+            }
+        }
 
         return ServerResponse.createBySuccess(agentUser);
+    }
+
+    @Override
+    public GoogleAuthDto getGoogleAuth(HttpServletRequest request) {
+        AgentUser agentUser = getCurrentAgent(request);
+        if (agentUser == null) {
+            return null;
+        }
+        String secretKey = GoogleAuthenticator.generateSecretKey();
+        QrConfig config = new QrConfig(345, 345);
+        config.setMargin(3);
+        String content = String.format("otpauth://totp/%s?secret=%s", agentUser.getAgentName(), secretKey);
+        String base64 = QrCodeUtil.generateAsBase64(content, config, "png");
+        GoogleAuthDto dto = new GoogleAuthDto();
+        dto.setGoogleAuthImg(base64);
+        dto.setGoogleAuthSecret(secretKey);
+        return dto;
     }
 
 
@@ -198,12 +229,16 @@
         AgentUser parentAgent = this.agentUserMapper.selectByPrimaryKey(parentId);
         if (parentId != null && parentId>0) {
             if (parentAgent != null) {
-                if(parentAgent.getAgentLevel()>=6){
-                    return ServerResponse.createByErrorMsg("六级代理不能添加下级");
-                }
                 agentUser.setParentId(parentAgent.getId());
                 agentUser.setParentName(parentAgent.getAgentName());
                 agentUser.setAgentLevel(parentAgent.getAgentLevel()+1);
+                //判断代理等级
+                StockConfig stockConfig = iStockConfigServices.queryByKey(EConfigKey.AGENT_MAX_GRADE.getCode());
+                Integer configLevel = Integer.parseInt(stockConfig.getCValue());
+                if(agentUser.getAgentLevel() > configLevel){
+                    return ServerResponse.createByErrorMsg("代理最大等级为"+stockConfig.getCValue());
+                }
+
             } else {
                 //总代理默认0级
                 agentUser.setAgentLevel(Integer.valueOf(0));
@@ -331,12 +366,13 @@
             if (parentAgent != null) {
                 dbAgent.setParentId(parentAgent.getId());
                 dbAgent.setParentName(parentAgent.getAgentName());
+                dbAgent.setAgentLevel(parentAgent.getAgentLevel()+1);
                 //判断代理等级
                 StockConfig stockConfig = iStockConfigServices.queryByKey(EConfigKey.AGENT_MAX_GRADE.getCode());
-                if(parentAgent.getAgentLevel()+1 > Integer.parseInt(stockConfig.getCValue())){
+                if(dbAgent.getAgentLevel() > Integer.parseInt(stockConfig.getCValue())){
                     return ServerResponse.createByErrorMsg("代理最大等级为"+stockConfig.getCValue());
                 }
-                dbAgent.setAgentLevel(parentAgent.getAgentLevel()+1);
+
             } else {
                 //总代理默认0级
                 dbAgent.setAgentLevel(Integer.valueOf(0));
@@ -448,6 +484,7 @@
         agentInfoVO.setParentName(agentUser.getParentName());
         agentInfoVO.setTotalMoney(agentUser.getTotalMoney());
         agentInfoVO.setOnLineServices(agentUser.getOnLineServices());
+        agentInfoVO.setGoogleAuthBind(Boolean.TRUE.equals(agentUser.getGoogleAuthBind()));
 
         String pcUrl = host + PropertiesUtil.getProperty("site.pc.reg.url") + agentUser.getAgentCode();
         agentInfoVO.setPcUrl(pcUrl);

--
Gitblit v1.9.3