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 | 78 ++++++++++++++++++++++++++++++++++-----
1 files changed, 68 insertions(+), 10 deletions(-)
diff --git a/src/main/java/com/nq/service/impl/AgentUserServiceImpl.java b/src/main/java/com/nq/service/impl/AgentUserServiceImpl.java
index 1ebdb94..57b8240 100644
--- a/src/main/java/com/nq/service/impl/AgentUserServiceImpl.java
+++ b/src/main/java/com/nq/service/impl/AgentUserServiceImpl.java
@@ -6,11 +6,9 @@
import com.google.gson.Gson;
import com.nq.common.ServerResponse;
import com.nq.dao.*;
+import com.nq.enums.EConfigKey;
import com.nq.pojo.*;
-import com.nq.service.IAgentAgencyFeeService;
-import com.nq.service.IAgentDistributionUserService;
-import com.nq.service.IAgentUserService;
-import com.nq.service.ISiteInfoService;
+import com.nq.service.*;
import com.nq.utils.KeyUtils;
import com.nq.utils.PropertiesUtil;
import com.nq.utils.SymmetricCryptoUtil;
@@ -20,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;
@@ -66,6 +66,9 @@
@Resource
UserMapper userMapper;
+ @Autowired
+ IStockConfigServices iStockConfigServices;
+
public AgentUser getCurrentAgent(HttpServletRequest request) {
// String loginToken = CookieUtils.readLoginToken(request, PropertiesUtil.getProperty("agent.cookie.name"));
@@ -88,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("验证码不能为空");
// }
@@ -110,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;
}
@@ -197,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));
@@ -305,7 +341,10 @@
if (pAgent != null) {
return ServerResponse.createByErrorMsg("手机号已存在");
}
-
+ AgentUser cAgent = this.agentUserMapper.findByCode(agentUser.getAgentCode());
+ if (cAgent != null) {
+ return ServerResponse.createByErrorMsg("代理编码已存在");
+ }
AgentUser nameAgent = this.agentUserMapper.findByName(agentUser.getAgentName());
if (nameAgent != null) {
return ServerResponse.createByErrorMsg("代理名已存在");
@@ -318,7 +357,8 @@
dbAgent.setAgentRealName(agentUser.getAgentRealName());
dbAgent.setAddTime(new Date());
dbAgent.setIsLock(Integer.valueOf(0));
- dbAgent.setAgentCode(KeyUtils.getAgentUniqueKey());
+// dbAgent.setAgentCode(KeyUtils.getAgentUniqueKey());
+ dbAgent.setAgentCode(agentUser.getAgentCode());
dbAgent.setOnLineServices(agentUser.getOnLineServices());
if (agentUser.getParentId() != null) {
@@ -327,6 +367,12 @@
dbAgent.setParentId(parentAgent.getId());
dbAgent.setParentName(parentAgent.getAgentName());
dbAgent.setAgentLevel(parentAgent.getAgentLevel()+1);
+ //判断代理等级
+ StockConfig stockConfig = iStockConfigServices.queryByKey(EConfigKey.AGENT_MAX_GRADE.getCode());
+ if(dbAgent.getAgentLevel() > Integer.parseInt(stockConfig.getCValue())){
+ return ServerResponse.createByErrorMsg("代理最大等级为"+stockConfig.getCValue());
+ }
+
} else {
//总代理默认0级
dbAgent.setAgentLevel(Integer.valueOf(0));
@@ -349,7 +395,13 @@
return ServerResponse.createByErrorMsg("代理名不能变更");
}
+ AgentUser cAgent = this.agentUserMapper.findByCodeAndNeid(agentUser.getAgentCode(),agentUser.getId());
+ if (cAgent != null) {
+ return ServerResponse.createByErrorMsg("代理编码已存在");
+ }
+
dbAgent.setId(agentUser.getId());
+ dbAgent.setAgentCode(agentUser.getAgentCode());
if (StringUtils.isNotBlank(agentUser.getAgentPwd())) {
dbAgent.setAgentPwd(SymmetricCryptoUtil.encryptPassword(agentUser.getAgentPwd()));
}
@@ -399,6 +451,11 @@
}
+ @Override
+ public ServerResponse<List<AgentUser>> getParensAgent() {
+ return ServerResponse.createBySuccess(agentUserMapper.getParensAgent());
+ }
+
public int CountAgentNum() {
return this.agentUserMapper.CountAgentNum();
}
@@ -427,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