|
|
@ -1,20 +1,28 @@
|
|
|
|
package com.luoo.user.service;
|
|
|
|
package com.luoo.user.service;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import api.PageResult;
|
|
|
|
import client.vo.SimpleUser;
|
|
|
|
import client.vo.SimpleUser;
|
|
|
|
|
|
|
|
import com.luoo.user.dao.UserBankDao;
|
|
|
|
import com.luoo.user.dao.UserInfoDao;
|
|
|
|
import com.luoo.user.dao.UserInfoDao;
|
|
|
|
import com.luoo.user.dao.UserRealNameDao;
|
|
|
|
import com.luoo.user.dao.UserRealNameDao;
|
|
|
|
|
|
|
|
import com.luoo.user.dao.WithdrawDao;
|
|
|
|
import com.luoo.user.dto.UserQueryReq;
|
|
|
|
import com.luoo.user.dto.UserQueryReq;
|
|
|
|
import com.luoo.user.dto.UserRealNameCheckDto;
|
|
|
|
import com.luoo.user.dto.UserRealNameCheckDto;
|
|
|
|
import com.luoo.user.dto.UserRealNameFormDto;
|
|
|
|
import com.luoo.user.dto.UserRealNameFormDto;
|
|
|
|
|
|
|
|
import com.luoo.user.dto.bank.UserBankAddDto;
|
|
|
|
|
|
|
|
import com.luoo.user.pojo.UserBank;
|
|
|
|
import com.luoo.user.pojo.UserInfo;
|
|
|
|
import com.luoo.user.pojo.UserInfo;
|
|
|
|
import com.luoo.user.pojo.UserRealName;
|
|
|
|
import com.luoo.user.pojo.UserRealName;
|
|
|
|
|
|
|
|
import com.luoo.user.pojo.Withdraw;
|
|
|
|
import com.luoo.user.util.NickNameUtil;
|
|
|
|
import com.luoo.user.util.NickNameUtil;
|
|
|
|
import com.luoo.user.util.NickNameUtil2;
|
|
|
|
import com.luoo.user.util.NickNameUtil2;
|
|
|
|
import constants.Constants;
|
|
|
|
import constants.Constants;
|
|
|
|
import constants.ErrorConstants;
|
|
|
|
import constants.ErrorConstants;
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
|
|
|
|
import enums.UserBankStateEnum;
|
|
|
|
import enums.UserRealNameStateEnum;
|
|
|
|
import enums.UserRealNameStateEnum;
|
|
|
|
import enums.UserStatusEnum;
|
|
|
|
import enums.UserStatusEnum;
|
|
|
|
|
|
|
|
import enums.WithdrawStateEnum;
|
|
|
|
import exception.BizException;
|
|
|
|
import exception.BizException;
|
|
|
|
import org.apache.commons.lang.ObjectUtils;
|
|
|
|
import org.apache.commons.lang.ObjectUtils;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
@ -24,6 +32,7 @@ import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
|
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
@ -34,6 +43,7 @@ import util.JwtUtil;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
@ -68,6 +78,12 @@ public class UserInfoService {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private UserRealNameDao userRealNameDao;
|
|
|
|
private UserRealNameDao userRealNameDao;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private UserBankDao userBankDao;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private WithdrawDao withdrawDao;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* token解析示例
|
|
|
|
* token解析示例
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -554,4 +570,130 @@ public class UserInfoService {
|
|
|
|
List<UserRealName> userRealNames = userRealNameDao.passList(userId);
|
|
|
|
List<UserRealName> userRealNames = userRealNameDao.passList(userId);
|
|
|
|
return !userRealNames.isEmpty();
|
|
|
|
return !userRealNames.isEmpty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 新增用户绑定银行卡
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param token token
|
|
|
|
|
|
|
|
* @param userBankAddDto 用户绑定银行卡对象
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
|
|
|
public void addUserBank(String token, UserBankAddDto userBankAddDto) {
|
|
|
|
|
|
|
|
UserBank userBank = new UserBank();
|
|
|
|
|
|
|
|
BeanUtils.copyProperties(userBankAddDto, userBank);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
|
|
|
if (user != null) {
|
|
|
|
|
|
|
|
userBank.setUserId(user.getUserId());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 用户校验失败,请重新登录
|
|
|
|
|
|
|
|
throw new BizException(ErrorConstants.USER_VERIFICATION_FAILURE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
userBank.setCreateUser(user.getUserId());
|
|
|
|
|
|
|
|
userBank.setState(UserBankStateEnum.BIND.getCode());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<UserBank> checkList = userBankDao.findAllByBankCardAndStateAndUserId(userBank.getBankCard(), userBank.getState(), userBank.getUserId());
|
|
|
|
|
|
|
|
if (checkList.isEmpty()) {
|
|
|
|
|
|
|
|
// 先解绑所有已绑定的银行卡
|
|
|
|
|
|
|
|
userBankDao.untieAllCard(user.getUserId());
|
|
|
|
|
|
|
|
// 保存本次的银行卡信息
|
|
|
|
|
|
|
|
userBankDao.save(userBank);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 该银行卡已绑定
|
|
|
|
|
|
|
|
throw new BizException(ErrorConstants.THE_BANK_CARD_HAS_BEEN_BOUND);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 用户解绑银行卡
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param token token
|
|
|
|
|
|
|
|
* @param id 用户绑定银行卡的id
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
|
|
|
public void untieCard(String token, String id) {
|
|
|
|
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
|
|
|
if (user == null) {
|
|
|
|
|
|
|
|
// 用户校验失败,请重新登录
|
|
|
|
|
|
|
|
throw new BizException(ErrorConstants.USER_VERIFICATION_FAILURE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UserBank userBank = userBankDao.findById(id).get();
|
|
|
|
|
|
|
|
userBank.setState(UserBankStateEnum.UNBIND.getCode());
|
|
|
|
|
|
|
|
userBank.setUpdateUser(user.getUserId());
|
|
|
|
|
|
|
|
userBankDao.save(userBank);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 查询用户绑定的银行卡
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param token 查询人的token
|
|
|
|
|
|
|
|
* @return 绑定的银行卡对象
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public UserBank getUserBank(String token) {
|
|
|
|
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
|
|
|
if (user == null) {
|
|
|
|
|
|
|
|
// 用户校验失败,请重新登录
|
|
|
|
|
|
|
|
throw new BizException(ErrorConstants.USER_VERIFICATION_FAILURE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return userBankDao.findAllByUserIdAndState(user.getUserId(), UserBankStateEnum.BIND.getCode());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 发起提现申请
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param token 发起人的token
|
|
|
|
|
|
|
|
* @param amount 金额
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
|
|
|
public void approveWithdraw(String token, BigDecimal amount) {
|
|
|
|
|
|
|
|
UserBank userBank = getUserBank(token);
|
|
|
|
|
|
|
|
if (userBank == null) {
|
|
|
|
|
|
|
|
// 没有绑定银行卡
|
|
|
|
|
|
|
|
throw new BizException(ErrorConstants.NO_BANK_CARD);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (amount.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
|
|
|
|
|
// 金额必须大于0
|
|
|
|
|
|
|
|
throw new BizException(ErrorConstants.AMOUNT_MUST_BE_GREATER_THAN_0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
|
|
|
Withdraw withdraw = Withdraw.builder()
|
|
|
|
|
|
|
|
.userId(user.getUserId())
|
|
|
|
|
|
|
|
.createUser(user.getUserId())
|
|
|
|
|
|
|
|
.amount(amount)
|
|
|
|
|
|
|
|
.state(WithdrawStateEnum.INITIATED.getCode())
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
withdrawDao.save(withdraw);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 分页查询用户的提现记录
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param token 登录token
|
|
|
|
|
|
|
|
* @param page 页码
|
|
|
|
|
|
|
|
* @param size 每页数量
|
|
|
|
|
|
|
|
* @return 列表
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public PageResult<Withdraw> withdrawPageResult(String token, Integer page, Integer size) {
|
|
|
|
|
|
|
|
Pageable pageable = PageRequest.of(page - 1, size);
|
|
|
|
|
|
|
|
UserBank userBank = getUserBank(token);
|
|
|
|
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
|
|
|
if (user == null) {
|
|
|
|
|
|
|
|
// 用户校验失败,请重新登录
|
|
|
|
|
|
|
|
throw new BizException(ErrorConstants.USER_VERIFICATION_FAILURE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Page<Withdraw> withdrawPage = withdrawDao.findListByUserId(user.getUserId(), pageable);
|
|
|
|
|
|
|
|
long totalElements = withdrawPage.getTotalElements();
|
|
|
|
|
|
|
|
List<Withdraw> content = withdrawPage.getContent();
|
|
|
|
|
|
|
|
for (Withdraw withdraw : content) {
|
|
|
|
|
|
|
|
if(withdraw.getState() != null) {
|
|
|
|
|
|
|
|
withdraw.setStateStr(Objects.requireNonNull(WithdrawStateEnum.getByCode(withdraw.getState())).getDesc());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return new PageResult<>(totalElements, content);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|