1
zj
4 days ago d98c7875c62e6551ad8aee081242aad8d5f13efe
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));
@@ -331,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));
@@ -409,6 +451,11 @@
    }
    @Override
    public ServerResponse<List<AgentUser>> getParensAgent() {
        return ServerResponse.createBySuccess(agentUserMapper.getParensAgent());
    }
    public int CountAgentNum() {
        return this.agentUserMapper.CountAgentNum();
    }
@@ -437,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);