release- 用户的提现及银行卡记录

release-2024-08-08
pikaqiudeshujia 7 months ago
parent 0ca8b1bab8
commit 1bd8c0b433

@ -42,4 +42,10 @@ public class ErrorConstants {
public final static String REAL_NAME_ERROR = "实名认证错误";
public final static String REASONS_FOR_REFUSAL_MUST_BE_GIVEN = "必须填写拒绝理由";
public final static String THE_BANK_CARD_HAS_BEEN_BOUND = "该银行卡已绑定";
public final static String NO_BANK_CARD = "没有绑定银行卡";
public final static String AMOUNT_MUST_BE_GREATER_THAN_0 = "金额必须大于0";
}

@ -0,0 +1,27 @@
package enums;
import lombok.Getter;
/**
* @Author: yawei.huang
* @Package: enums
* @Project: luoo_parent
* @Date: 2024/5/11 11:19
* @Filename: UserBankStateEnum
* @Describe:
*/
@Getter
public enum UserBankStateEnum {
BIND(1, "绑定"),
UNBIND(2, "解绑");
private Integer code;
private String desc;
UserBankStateEnum(Integer code, String desc) {
this.code = code;
this.desc = desc;
}
}

@ -0,0 +1,38 @@
package enums;
import lombok.Getter;
/**
* @Author: yawei.huang
* @Package: enums
* @Project: luoo_parent
* @Date: 2024/5/11 14:01
* @Filename: WithdrawStateEnum
* @Describe:
*/
@Getter
public enum WithdrawStateEnum {
INITIATED(1, "已发起"),
SUCCESS(2, "已成功"),
FAIL(3, "失败");
private Integer code;
private String desc;
WithdrawStateEnum(Integer code, String desc) {
this.code = code;
this.desc = desc;
}
public static WithdrawStateEnum getByCode(Integer code) {
for (WithdrawStateEnum item : WithdrawStateEnum.values()) {
if (item.getCode().equals(code)) {
return item;
}
}
return null;
}
}

@ -8,6 +8,7 @@ import api.StatusCode;
import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
import com.luoo.user.dao.UserMessageDao;
import com.luoo.user.dto.*;
import com.luoo.user.dto.bank.UserBankAddDto;
import com.luoo.user.dto.request.LoginReq;
import com.luoo.user.dto.request.LogoffReq;
import com.luoo.user.dto.response.UserRespDTO;
@ -42,6 +43,7 @@ import util.ScaleFilter;
import util.StringTools;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -607,5 +609,52 @@ public class MyController extends BaseController {
return userInfoService.getRealNameInfo(userId);
}
@ApiOperation(value = "16.1 用户绑定银行卡号")
@PostMapping("/add/bank")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<Void> addUserBank(@ApiParam(value = "用户token", required = true) @RequestHeader(value = "Authorization", required = true) String authorization,
@ApiParam(value = "添加用户银行卡绑定对象", required = true) @Validated @RequestBody UserBankAddDto userBankAddDto
) {
userInfoService.addUserBank(authorization, userBankAddDto);
return Result.success();
}
@ApiOperation(value = "16.2 用户解绑银行卡")
@PostMapping("/del/bank/{id}")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<Void> delUserBank(@ApiParam(value = "用户token", required = true) @RequestHeader(value = "Authorization", required = true) String authorization,
@ApiParam(value = "用户绑定银行卡id", required = true) @PathVariable String id) {
userInfoService.untieCard(authorization, id);
return Result.success();
}
@ApiOperation(value = "16.3 查看用户已绑定的银行卡号")
@GetMapping("/bank/info")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<UserBank> getUserBankInfo(@ApiParam(value = "用户token", required = true) @RequestHeader(value = "Authorization", required = true) String authorization) {
return Result.success(userInfoService.getUserBank(authorization));
}
@ApiOperation(value = "17.1 发出提现申请")
@PostMapping("/approve/withdraw")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<Void> approveWithdraw(@ApiParam(value = "用户token", required = true) @RequestHeader(value = "Authorization", required = true) String authorization,
@ApiParam(value = "金额", required = true) BigDecimal amount) {
userInfoService.approveWithdraw(authorization, amount);
return Result.success();
}
@ApiOperation(value = "17.2 查询提现记录")
@GetMapping("/withdraw/{pageNum}/{pageSize}")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<PageResult<Withdraw>> pageResultResult(
@RequestHeader(value = "Authorization", required = true) String authorization,
@PathVariable @VerifyParam(required = true) Integer pageNum,
@PathVariable @VerifyParam(required = true) Integer pageSize) {
return Result.success(userInfoService.withdrawPageResult(authorization, pageNum, pageSize));
}
}

@ -1,6 +1,6 @@
package com.luoo.user.dao;
import com.luoo.user.pojo.TbBank;
import com.luoo.user.pojo.Bank;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
@ -12,5 +12,5 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
* @Filename: TbBankDao
* @Describe:
*/
public interface TbBankDao extends JpaRepository<TbBank, String>, JpaSpecificationExecutor<TbBank> {
public interface BankDao extends JpaRepository<Bank, String>, JpaSpecificationExecutor<Bank> {
}

@ -1,16 +0,0 @@
package com.luoo.user.dao;
import com.luoo.user.pojo.TbUserBank;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/**
* @Author: yawei.huang
* @Package: com.luoo.user.dao
* @Project: luoo_parent
* @Date: 2024/5/11 10:59
* @Filename: TbUserBankDao
* @Describe:
*/
public interface TbUserBankDao extends JpaRepository<TbUserBank, String>, JpaSpecificationExecutor<TbUserBank> {
}

@ -1,16 +0,0 @@
package com.luoo.user.dao;
import com.luoo.user.pojo.TbWithdraw;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/**
* @Author: yawei.huang
* @Package: com.luoo.user.dao
* @Project: luoo_parent
* @Date: 2024/5/11 11:00
* @Filename: TbWithdrawDao
* @Describe:
*/
public interface TbWithdrawDao extends JpaRepository<TbWithdraw, String>, JpaSpecificationExecutor<TbWithdraw> {
}

@ -0,0 +1,28 @@
package com.luoo.user.dao;
import com.luoo.user.pojo.UserBank;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
/**
* @Author: yawei.huang
* @Package: com.luoo.user.dao
* @Project: luoo_parent
* @Date: 2024/5/11 10:59
* @Filename: TbUserBankDao
* @Describe:
*/
public interface UserBankDao extends JpaRepository<UserBank, String>, JpaSpecificationExecutor<UserBank> {
public List<UserBank> findAllByBankCardAndStateAndUserId(String bankCard, Integer state, String userId);
@Modifying
@Query(value = "update tb_user_bank set state = 2 where user_id = ?")
public void untieAllCard(String userId);
public UserBank findAllByUserIdAndState(String userId, Integer state);
}

@ -0,0 +1,23 @@
package com.luoo.user.dao;
import com.luoo.user.pojo.Withdraw;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
/**
* @Author: yawei.huang
* @Package: com.luoo.user.dao
* @Project: luoo_parent
* @Date: 2024/5/11 11:00
* @Filename: TbWithdrawDao
* @Describe:
*/
public interface WithdrawDao extends JpaRepository<Withdraw, String>, JpaSpecificationExecutor<Withdraw> {
@Query(value = "select * from tb_withdraw t1 where t1.user_id = ?1", countProjection = "t1.id", nativeQuery = true)
public Page<Withdraw> findListByUserId(String userId, Pageable pageable);
}

@ -0,0 +1,33 @@
package com.luoo.user.dto.bank;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
/**
* @Author: yawei.huang
* @Package: com.luoo.user.dto.bank
* @Project: luoo_parent
* @Date: 2024/5/11 11:06
* @Filename: UserBankAddDto
* @Describe:
*/
@Data
public class UserBankAddDto implements Serializable {
@ApiModelProperty(value = "银行卡号")
@NotBlank
private String bankCard;
@ApiModelProperty(value = "银行id")
private String bankId;
@ApiModelProperty(value = "银行名称")
private String bankName;
@ApiModelProperty(value = "手机号")
@NotBlank
private String phone;
}

@ -16,7 +16,7 @@ import java.io.Serializable;
@ToString
@Entity
@Table(name = "tb_bank")
public class TbBank implements Serializable {
public class Bank implements Serializable {
@Id
private String id;

@ -21,7 +21,7 @@ import java.time.Instant;
@ToString
@Entity
@Table(name = "tb_user_bank")
public class TbUserBank implements Serializable {
public class UserBank implements Serializable {
@Id
private String id;

@ -10,6 +10,7 @@ import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.Instant;
@ -22,7 +23,7 @@ import java.time.Instant;
@ToString
@Entity
@Table(name = "tb_withdraw")
public class TbWithdraw implements Serializable {
public class Withdraw implements Serializable {
@Id
private String id;
@ -49,4 +50,8 @@ public class TbWithdraw implements Serializable {
private String updateUser;
@Transient
@ApiModelProperty(value = "提现状态字符串")
private String stateStr;
}

@ -1,20 +1,28 @@
package com.luoo.user.service;
import api.PageResult;
import client.vo.SimpleUser;
import com.luoo.user.dao.UserBankDao;
import com.luoo.user.dao.UserInfoDao;
import com.luoo.user.dao.UserRealNameDao;
import com.luoo.user.dao.WithdrawDao;
import com.luoo.user.dto.UserQueryReq;
import com.luoo.user.dto.UserRealNameCheckDto;
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.UserRealName;
import com.luoo.user.pojo.Withdraw;
import com.luoo.user.util.NickNameUtil;
import com.luoo.user.util.NickNameUtil2;
import constants.Constants;
import constants.ErrorConstants;
import dto.UserLoginDto;
import enums.UserBankStateEnum;
import enums.UserRealNameStateEnum;
import enums.UserStatusEnum;
import enums.WithdrawStateEnum;
import exception.BizException;
import org.apache.commons.lang.ObjectUtils;
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.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
@ -34,6 +43,7 @@ import util.JwtUtil;
import javax.persistence.criteria.Predicate;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@ -68,6 +78,12 @@ public class UserInfoService {
@Autowired
private UserRealNameDao userRealNameDao;
@Autowired
private UserBankDao userBankDao;
@Autowired
private WithdrawDao withdrawDao;
/**
* token
*/
@ -554,4 +570,130 @@ public class UserInfoService {
List<UserRealName> userRealNames = userRealNameDao.passList(userId);
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);
}
}

Loading…
Cancel
Save