| | |
| | | import com.nq.utils.KeyUtils; |
| | | import com.nq.utils.PropertiesUtil; |
| | | import com.nq.utils.SymmetricCryptoUtil; |
| | | import com.nq.utils.UserFundUtil; |
| | | import com.nq.utils.ip.IpUtils; |
| | | import com.nq.utils.ip.JuheIpApi; |
| | | import com.nq.utils.redis.CookieUtils; |
| | |
| | | IUserService iUserService; |
| | | @Autowired |
| | | UserPositionMapper userPositionMapper; |
| | | @Autowired |
| | | UserWithdrawMapper userWithdrawMapper; |
| | | |
| | | @Autowired |
| | | IUserRechargeService userRechargeService; |
| | |
| | | return ServerResponse.createByErrorMsg("注册失败, 参数不能为空"); |
| | | } |
| | | |
| | | if (!com.nq.utils.PhoneUtil.isValidChinaMobile(phone)) { |
| | | return ServerResponse.createByErrorMsg("注册失败, 手机号格式不正确"); |
| | | } |
| | | phone = com.nq.utils.PhoneUtil.normalizeChinaMobile(phone); |
| | | |
| | | // String keys = "AliyunSmsCode:" + phone; |
| | | // String redis_yzm = RedisShardedPoolUtils.get(keys); |
| | | // |
| | | // log.info("redis_yzm = {},yzmCode = {}", redis_yzm, yzmCode); |
| | | // if (!yzmCode.equals(redis_yzm) && !"6666".equals(yzmCode)) { |
| | | // return ServerResponse.createByErrorMsg("注册失败, 验证码错误"); |
| | | // } |
| | | if (com.nq.utils.sms.SmsConstants.isVerifyEnabled()) { |
| | | if (StringUtils.isBlank(yzmCode)) { |
| | | return ServerResponse.createByErrorMsg("注册失败, 请输入短信验证码"); |
| | | } |
| | | |
| | | String keys = com.nq.utils.sms.SmsConstants.SMS_CODE_PREFIX + phone; |
| | | String redis_yzm = RedisShardedPoolUtils.get(keys); |
| | | |
| | | log.info("redis_yzm = {},yzmCode = {}", redis_yzm, yzmCode); |
| | | if (StringUtils.isBlank(redis_yzm) || !yzmCode.equals(redis_yzm)) { |
| | | return ServerResponse.createByErrorMsg("注册失败, 验证码错误或已过期"); |
| | | } |
| | | RedisShardedPoolUtils.del(keys); |
| | | } |
| | | |
| | | AgentUser agentUser = this.iAgentUserService.findByCode(agentCode); |
| | | if (agentUser == null) { |
| | |
| | | user.setIsActive(Integer.valueOf(0)); |
| | | |
| | | user.setRegTime(new Date()); |
| | | // String uip = IpUtils.getIp(request); |
| | | // user.setRegIp(uip); |
| | | // // IP地址查询改为异步处理,避免阻塞注册接口 |
| | | // final String finalUip = uip; |
| | | // final String finalPhone = phone; |
| | | // new Thread(() -> { |
| | | // try { |
| | | // String uadd = JuheIpApi.ip2Add(finalUip); |
| | | // log.info("用户注册IP地址查询完成 手机 {} , ip = {} 地址 = {}", finalPhone, finalUip, uadd); |
| | | // } catch (Exception e) { |
| | | // log.error("IP地址查询异常", e); |
| | | // } |
| | | // }).start(); |
| | | String uip = IpUtils.getIp(request); |
| | | user.setRegIp(StringUtils.isBlank(uip) ? "--" : uip); |
| | | String uadd = JuheIpApi.ip2Add(uip); |
| | | user.setRegAddress(StringUtils.isBlank(uadd) ? "未知" : uadd); |
| | | |
| | | user.setIsLogin(Integer.valueOf(0)); |
| | | |
| | |
| | | String newAgentCode = generateUniqueAgentCode(); |
| | | agentUser.setAgentCode(newAgentCode); |
| | | iAgentUserService.updateAgentCode(agentUser); |
| | | log.info("用户注册成功 手机 {} , ip = {}", phone, "123123"); |
| | | log.info("用户注册成功 手机 {} , ip = {}", phone, uip); |
| | | return ServerResponse.createBySuccessMsg("注册成功.请登录"); |
| | | } |
| | | return ServerResponse.createBySuccessMsg("注册出错, 请重试"); |
| | |
| | | if (StringUtils.isBlank(phone) || StringUtils.isBlank(userPwd)) { |
| | | return ServerResponse.createByErrorMsg("手机号和密码不能为空"); |
| | | } |
| | | if (!com.nq.utils.PhoneUtil.isValidChinaMobile(phone)) { |
| | | return ServerResponse.createByErrorMsg("手机号格式不正确"); |
| | | } |
| | | phone = com.nq.utils.PhoneUtil.normalizeChinaMobile(phone); |
| | | userPwd = SymmetricCryptoUtil.encryptPassword(userPwd); |
| | | User user = this.userMapper.login(phone, userPwd); |
| | | if (user != null) { |
| | |
| | | User user = (User)JsonUtil.string2Obj(userJson, User.class); |
| | | User dbuser = this.userMapper.selectByPrimaryKey(user.getId()); |
| | | RedisShardedPoolUtils.setEx(loginToken, JsonUtil.obj2String(dbuser), 9999); |
| | | UserInfoVO userInfoVO = assembleUserInfoVO(dbuser); |
| | | UserInfoVO userInfoVO = assembleUserInfoVO(dbuser, true); |
| | | |
| | | return ServerResponse.createBySuccess(userInfoVO); |
| | | } |
| | |
| | | |
| | | |
| | | public ServerResponse checkPhone(String phone) { |
| | | if (!com.nq.utils.PhoneUtil.isValidChinaMobile(phone)) { |
| | | return ServerResponse.createByErrorMsg("手机号格式不正确"); |
| | | } |
| | | phone = com.nq.utils.PhoneUtil.normalizeChinaMobile(phone); |
| | | User user = this.userMapper.findByPhone(phone); |
| | | if (user != null) { |
| | | return ServerResponse.createBySuccessMsg("用户已存在"); |
| | |
| | | |
| | | |
| | | public ServerResponse updatePwd(String phone, String code, String newPwd) { |
| | | if (StringUtils.isBlank(phone) || |
| | | StringUtils.isBlank(code) || |
| | | StringUtils.isBlank(newPwd)) { |
| | | if (StringUtils.isBlank(phone) || StringUtils.isBlank(newPwd)) { |
| | | return ServerResponse.createByErrorMsg("参数不能为空"); |
| | | } |
| | | if (com.nq.utils.sms.SmsConstants.isVerifyEnabled() && StringUtils.isBlank(code)) { |
| | | return ServerResponse.createByErrorMsg("参数不能为空"); |
| | | } |
| | | if (!com.nq.utils.PhoneUtil.isValidChinaMobile(phone)) { |
| | | return ServerResponse.createByErrorMsg("手机号格式不正确"); |
| | | } |
| | | phone = com.nq.utils.PhoneUtil.normalizeChinaMobile(phone); |
| | | |
| | | if (com.nq.utils.sms.SmsConstants.isVerifyEnabled()) { |
| | | String keys = "AliyunSmsCode:" + phone; |
| | | String redis_yzm = RedisShardedPoolUtils.get(keys); |
| | | |
| | | String keys = "AliyunSmsCode:" + phone; |
| | | String redis_yzm = RedisShardedPoolUtils.get(keys); |
| | | |
| | | log.info("redis_yzm = {} , code = {}", redis_yzm, code); |
| | | if (!code.equals(redis_yzm)) { |
| | | return ServerResponse.createByErrorMsg("修改密码失败,验证码错误"); |
| | | log.info("redis_yzm = {} , code = {}", redis_yzm, code); |
| | | if (!code.equals(redis_yzm)) { |
| | | return ServerResponse.createByErrorMsg("修改密码失败,验证码错误"); |
| | | } |
| | | } |
| | | |
| | | User user = this.userMapper.findByPhone(phone); |
| | |
| | | BigDecimal enableIndexAmt = user.getEnableIndexAmt().add(new BigDecimal(amt.intValue())); |
| | | |
| | | user.setUserAmt(userAmt); |
| | | user.setEnableAmt(enableAmt); |
| | | UserFundUtil.debitEnableAndWithdraw(user, new BigDecimal(amt.intValue())); |
| | | user.setUserIndexAmt(userIndexAmt); |
| | | user.setEnableIndexAmt(enableIndexAmt); |
| | | int updateCount = this.userMapper.updateByPrimaryKeySelective(user); |
| | |
| | | } |
| | | |
| | | BigDecimal userAmt = user.getUserAmt().add(new BigDecimal(amt.intValue())); |
| | | BigDecimal enableAmt = user.getEnableAmt().add(new BigDecimal(amt.intValue())); |
| | | BigDecimal userIndexAmt = user.getUserIndexAmt().subtract(new BigDecimal(amt.intValue())); |
| | | BigDecimal enableIndexAmt = user.getEnableIndexAmt().subtract(new BigDecimal(amt.intValue())); |
| | | |
| | | user.setUserAmt(userAmt); |
| | | user.setEnableAmt(enableAmt); |
| | | UserFundUtil.creditEnableAndWithdraw(user, new BigDecimal(amt.intValue())); |
| | | user.setUserIndexAmt(userIndexAmt); |
| | | user.setEnableIndexAmt(enableIndexAmt); |
| | | int updateCount = this.userMapper.updateByPrimaryKeySelective(user); |
| | |
| | | } |
| | | |
| | | BigDecimal userAmt = user.getUserAmt().subtract(new BigDecimal(amt.intValue())); |
| | | BigDecimal enableAmt = user.getEnableAmt().subtract(new BigDecimal(amt.intValue())); |
| | | BigDecimal userFutAmt = user.getUserFutAmt().add(new BigDecimal(amt.intValue())); |
| | | BigDecimal enableFutAmt = user.getEnableFutAmt().add(new BigDecimal(amt.intValue())); |
| | | |
| | | user.setUserAmt(userAmt); |
| | | user.setEnableAmt(enableAmt); |
| | | UserFundUtil.debitEnableAndWithdraw(user, new BigDecimal(amt.intValue())); |
| | | user.setUserFutAmt(userFutAmt); |
| | | user.setEnableFutAmt(enableFutAmt); |
| | | int updateCount = this.userMapper.updateByPrimaryKeySelective(user); |
| | |
| | | } |
| | | |
| | | BigDecimal userAmt = user.getUserAmt().add(new BigDecimal(amt.intValue())); |
| | | BigDecimal enableAmt = user.getEnableAmt().add(new BigDecimal(amt.intValue())); |
| | | BigDecimal userFutAmt = user.getUserFutAmt().subtract(new BigDecimal(amt.intValue())); |
| | | BigDecimal enableFutAmt = user.getEnableFutAmt().subtract(new BigDecimal(amt.intValue())); |
| | | |
| | | user.setUserAmt(userAmt); |
| | | user.setEnableAmt(enableAmt); |
| | | UserFundUtil.creditEnableAndWithdraw(user, new BigDecimal(amt.intValue())); |
| | | user.setUserFutAmt(userFutAmt); |
| | | user.setEnableFutAmt(enableFutAmt); |
| | | |
| | |
| | | |
| | | List<User> users = this.userMapper.listByAdmin(realName, phone, agentId, accountType); |
| | | |
| | | for(User user:users){ |
| | | List<UserInfoVO> voList = Lists.newArrayListWithCapacity(users.size()); |
| | | for (User user : users) { |
| | | user.setUserPwd(""); |
| | | voList.add(assembleUserInfoVO(user, false)); |
| | | } |
| | | |
| | | PageInfo pageInfo = new PageInfo(users); |
| | | pageInfo.setList(voList); |
| | | |
| | | return ServerResponse.createBySuccess(pageInfo); |
| | | } |
| | | |
| | | |
| | | |
| | | public ServerResponse findByUserId(Integer userId) { return ServerResponse.createBySuccess(this.userMapper.selectByPrimaryKey(userId)); } |
| | | public ServerResponse findByUserId(Integer userId) { |
| | | if (userId == null) { |
| | | return ServerResponse.createByErrorMsg("用户ID不能为空"); |
| | | } |
| | | User user = this.userMapper.selectByPrimaryKey(userId); |
| | | if (user == null) { |
| | | return ServerResponse.createByErrorMsg("用户不存在"); |
| | | } |
| | | return ServerResponse.createBySuccess(assembleUserInfoVO(user, false)); |
| | | } |
| | | |
| | | @Override |
| | | public User getUserEntityById(Integer userId) { |
| | | if (userId == null) { |
| | | return null; |
| | | } |
| | | return this.userMapper.selectByPrimaryKey(userId); |
| | | } |
| | | |
| | | |
| | | |
| | |
| | | } else { |
| | | return ServerResponse.createByErrorMsg("不存在此操作"); |
| | | } |
| | | user.setEnableAmt(sh_amt_back); |
| | | BigDecimal amtDecimal = new BigDecimal(amt); |
| | | if (direction.intValue() == 0) { |
| | | UserFundUtil.creditUserBalance(user, amtDecimal); |
| | | } else if (direction.intValue() == 1) { |
| | | user.setEnableAmt(sh_amt_back); |
| | | BigDecimal withdrawAmt = user.getEnaleWithdrawAmt() == null ? BigDecimal.ZERO : user.getEnaleWithdrawAmt(); |
| | | BigDecimal newWithdraw = withdrawAmt.subtract(amtDecimal); |
| | | user.setEnaleWithdrawAmt(newWithdraw.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : newWithdraw); |
| | | } else { |
| | | user.setEnableAmt(sh_amt_back); |
| | | } |
| | | |
| | | // BigDecimal hk_amt = user.getHkAmt(); |
| | | // |
| | |
| | | agentUserListVO.setUserAmt(user.getUserAmt()); |
| | | agentUserListVO.setEnableAmt(user.getEnableAmt()); |
| | | |
| | | BigDecimal pendingWithdrawAmt = userWithdrawMapper.sumPendingAmtByUserId(user.getId()); |
| | | BigDecimal resolvedWithdrawAmt = UserFundUtil.resolveWithdrawAmt( |
| | | user.getEnableAmt(), user.getEnaleWithdrawAmt(), pendingWithdrawAmt); |
| | | agentUserListVO.setEnaleWithdrawAmt(resolvedWithdrawAmt); |
| | | |
| | | agentUserListVO.setUserIndexAmt(user.getUserIndexAmt()); |
| | | agentUserListVO.setEnableIndexAmt(user.getEnableIndexAmt()); |
| | | |
| | |
| | | BigDecimal allFreezAmt = positionVO.getAllFreezAmt(); |
| | | agentUserListVO.setAllProfitAndLose(allProfitAndLose); |
| | | agentUserListVO.setAllFreezAmt(allFreezAmt); |
| | | |
| | | BigDecimal openBuyFees = BigDecimal.ZERO; |
| | | List<UserPosition> openPositions = this.iUserPositionService.findPositionByUserIdAndSellIdIsNull(user.getId()); |
| | | if (openPositions != null) { |
| | | for (UserPosition position : openPositions) { |
| | | if (position.getOrderFee() != null) { |
| | | openBuyFees = openBuyFees.add(position.getOrderFee()); |
| | | } |
| | | } |
| | | } |
| | | BigDecimal enableAmt = user.getEnableAmt() == null ? BigDecimal.ZERO : user.getEnableAmt(); |
| | | BigDecimal freezAmt = allFreezAmt == null ? BigDecimal.ZERO : allFreezAmt; |
| | | BigDecimal profitAndLose = allProfitAndLose == null ? BigDecimal.ZERO : allProfitAndLose; |
| | | BigDecimal userAllAmt = enableAmt.add(freezAmt).add(profitAndLose).add(openBuyFees); |
| | | agentUserListVO.setUserAmt(userAllAmt.setScale(2, RoundingMode.HALF_UP)); |
| | | |
| | | BigDecimal forceLine = forcePercent.multiply(allFreezAmt); |
| | | forceLine = forceLine.add(user.getEnableAmt()); |
| | |
| | | } |
| | | |
| | | private UserInfoVO assembleUserInfoVO(User user) { |
| | | return assembleUserInfoVO(user, true); |
| | | } |
| | | |
| | | /** 与用户端 getUserInfo 一致的账户资产展示 */ |
| | | private UserInfoVO assembleUserInfoVO(User user, boolean persistWithdrawHeal) { |
| | | UserInfoVO userInfoVO = new UserInfoVO(); |
| | | |
| | | userInfoVO.setId(user.getId()); |
| | |
| | | userInfoVO.setAccountType(user.getAccountType()); |
| | | userInfoVO.setRecomPhone(user.getRecomPhone()); |
| | | userInfoVO.setIsLock(user.getIsLock()); |
| | | userInfoVO.setIsLogin(user.getIsLogin()); |
| | | userInfoVO.setRegTime(user.getRegTime()); |
| | | userInfoVO.setRegIp(user.getRegIp()); |
| | | userInfoVO.setRegAddress(user.getRegAddress()); |
| | |
| | | userInfoVO.setEnableAmt(user.getEnableAmt()); |
| | | userInfoVO.setTradingAmount(user.getTradingAmount()); |
| | | |
| | | BigDecimal pendingWithdrawAmt = userWithdrawMapper.sumPendingAmtByUserId(user.getId()); |
| | | BigDecimal resolvedWithdrawAmt = UserFundUtil.resolveWithdrawAmt( |
| | | user.getEnableAmt(), user.getEnaleWithdrawAmt(), pendingWithdrawAmt); |
| | | if (persistWithdrawHeal |
| | | && (user.getEnaleWithdrawAmt() == null || resolvedWithdrawAmt.compareTo(user.getEnaleWithdrawAmt()) != 0)) { |
| | | user.setEnaleWithdrawAmt(resolvedWithdrawAmt); |
| | | this.userMapper.updateByPrimaryKeySelective(user); |
| | | } |
| | | userInfoVO.setEnaleWithdrawAmt(resolvedWithdrawAmt); |
| | | |
| | | PositionVO positionVO = this.iUserPositionService.findUserPositionAllProfitAndLose(user.getId()); |
| | | userInfoVO.setAllFreezAmt(positionVO.getAllFreezAmt()); |
| | |
| | | BigDecimal userAllAmt = enableAmt.add(allFreezAmt).add(allProfitAndLose).add(openBuyFees); |
| | | |
| | | userInfoVO.setEnableIndexAmt(user.getEnableIndexAmt()); |
| | | userInfoVO.setEnaleWithdrawAmt(user.getEnaleWithdrawAmt()); |
| | | userInfoVO.setIsSignedContract(user.getIsSignedContract()); |
| | | userInfoVO.setIsSignedAgreement(user.getIsSignedAgreement()); |
| | | userInfoVO.setHkAmt(user.getHkAmt()); |
| | |
| | | |
| | | @Override |
| | | public void updateUserAmt(Double amt, Integer user_id) { |
| | | userMapper.updateUserAmt(amt, user_id); |
| | | if (amt == null || user_id == null || amt <= 0) { |
| | | return; |
| | | } |
| | | User user = this.userMapper.selectByPrimaryKey(user_id); |
| | | if (user == null) { |
| | | log.error("updateUserAmt 用户不存在 userId={}", user_id); |
| | | return; |
| | | } |
| | | UserFundUtil.creditUserBalance(user, BigDecimal.valueOf(amt)); |
| | | this.userMapper.updateByPrimaryKeySelective(user); |
| | | log.info("updateUserAmt 充值入账 userId={} amt={} enable={} withdraw={}", |
| | | user_id, amt, user.getEnableAmt(), user.getEnaleWithdrawAmt()); |
| | | } |
| | | |
| | | |