|
|
@@ -9,21 +9,27 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.kxs.common.core.constant.CommonConstants;
|
|
|
+import com.kxs.common.core.exception.GlobalCustomerException;
|
|
|
import com.kxs.common.core.util.R;
|
|
|
import com.kxs.common.security.util.SecurityUtils;
|
|
|
import com.kxs.user.api.dto.admin.userWithdrawal.SysUserWithdrawalPageDTO;
|
|
|
import com.kxs.user.api.dto.kxsapp.userAccount.WithdrawDepositDTO;
|
|
|
+import com.kxs.user.api.model.KxsPartner;
|
|
|
import com.kxs.user.api.model.KxsUserAmount;
|
|
|
import com.kxs.user.api.model.KxsUserBank;
|
|
|
import com.kxs.user.api.vo.admin.userWithdrawal.SysUserWithdrawalPageVO;
|
|
|
+import com.kxs.user.api.vo.kxsapp.totalDebt.TotalDebtDetailVO;
|
|
|
import com.kxs.user.api.vo.kxsapp.userAccount.WithdrawDetailVO;
|
|
|
import com.kxs.user.api.vo.kxsapp.userAccount.WithdrawListVO;
|
|
|
import com.kxs.user.biz.constant.enums.UserErrorTypeEnum;
|
|
|
import com.kxs.user.biz.constant.enums.WithdrawalStatusEnum;
|
|
|
+import com.kxs.user.biz.constant.enums.WithdrawalTypeEnum;
|
|
|
+import com.kxs.user.biz.mapper.KxsPartnerMapper;
|
|
|
import com.kxs.user.biz.mapper.KxsUserAmountMapper;
|
|
|
import com.kxs.user.biz.mapper.KxsUserBankMapper;
|
|
|
import com.kxs.user.biz.mapper.KxsUserWithdrawalMapper;
|
|
|
import com.kxs.user.api.model.KxsUserWithdrawal;
|
|
|
+import com.kxs.user.biz.service.KxsTotalDebtService;
|
|
|
import com.kxs.user.biz.service.KxsUserService;
|
|
|
import com.kxs.user.biz.service.KxsUserWithdrawalService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
@@ -32,6 +38,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
@@ -50,6 +57,10 @@ public class KxsUserWithdrawalServiceImpl extends ServiceImpl<KxsUserWithdrawalM
|
|
|
|
|
|
private final KxsUserAmountMapper userAmountMapper;
|
|
|
|
|
|
+ private final KxsPartnerMapper kxsPartnerMapper;
|
|
|
+
|
|
|
+ private final KxsTotalDebtService kxsTotalDebtService;
|
|
|
+
|
|
|
/**
|
|
|
* 税费比例
|
|
|
*/
|
|
|
@@ -136,8 +147,71 @@ public class KxsUserWithdrawalServiceImpl extends ServiceImpl<KxsUserWithdrawalM
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public IPage<WithdrawListVO> withdrawListPage(Page<WithdrawListVO> page) {
|
|
|
- IPage<WithdrawListVO> byPage = baseMapper.getByPage(page);
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R leaderCash(WithdrawDepositDTO param) {
|
|
|
+ Long userId = SecurityUtils.getUser().getId();
|
|
|
+
|
|
|
+ if (!kxsUserService.checkPayPwd(param.getPayPwd())) {
|
|
|
+ return R.failed(UserErrorTypeEnum.PWD_ERROR.getDescription());
|
|
|
+ }
|
|
|
+ //查询银行卡
|
|
|
+ KxsUserBank userBank = userBankMapper.selectOne(Wrappers.<KxsUserBank>lambdaQuery().eq(KxsUserBank::getUserId, userId));
|
|
|
+ if(userBank == null){
|
|
|
+ return R.failed(UserErrorTypeEnum.NOT_REAL.getDescription());
|
|
|
+ }
|
|
|
+
|
|
|
+ //TODO 目前没合并表之前查询两个的余额
|
|
|
+ KxsUserAmount userAmount = userAmountMapper.selectOne(Wrappers.<KxsUserAmount>lambdaQuery().eq(KxsUserAmount::getUserId, userId).last("FOR UPDATE"));
|
|
|
+ KxsPartner kxsPartner = kxsPartnerMapper.selectByPartner(userId.intValue(), LocalDateTime.now());
|
|
|
+ BigDecimal leaderAmt = userAmount.getLeaderBalanceAmount();
|
|
|
+ if(kxsPartner != null){
|
|
|
+ leaderAmt = NumberUtil.add(userAmount.getLeaderBalanceAmount(), kxsPartner.getWithdrawalAmount());
|
|
|
+ }
|
|
|
+ //余额减去预扣款金额
|
|
|
+ TotalDebtDetailVO detail = kxsTotalDebtService.detail();
|
|
|
+ if(detail != null){
|
|
|
+ leaderAmt = NumberUtil.sub(leaderAmt, detail.getTotalDebt());
|
|
|
+ }
|
|
|
+ //验证余额
|
|
|
+ if (leaderAmt.compareTo(param.getApplyAmount()) < 0) {
|
|
|
+ return R.failed(UserErrorTypeEnum.NOT_SUFFICIENT_FUNDS.getDescription());
|
|
|
+ }
|
|
|
+
|
|
|
+ //订单号
|
|
|
+ String orderSn = CommonConstants.KXS_LEADER_WITHDRAWAL_PREFIX + IdUtil.getSnowflakeNextIdStr();
|
|
|
+ KxsUserWithdrawal kxsUserWithdrawal = new KxsUserWithdrawal();
|
|
|
+ kxsUserWithdrawal.setUserId(userId.intValue());
|
|
|
+ kxsUserWithdrawal.setApplyNo(orderSn);
|
|
|
+ kxsUserWithdrawal.setWithdrawalType(WithdrawalTypeEnum.LEADER.getType());
|
|
|
+ kxsUserWithdrawal.setBankCode(userBank.getBankCode());
|
|
|
+ kxsUserWithdrawal.setBankName(userBank.getBankName());
|
|
|
+ kxsUserWithdrawal.setApplyAmount(param.getApplyAmount());
|
|
|
+ baseMapper.insert(kxsUserWithdrawal);
|
|
|
+
|
|
|
+ //如果提现金额<=盟主提现金额则直接扣除盟主提现金额
|
|
|
+ if(param.getApplyAmount().compareTo(userAmount.getLeaderBalanceAmount()) <= 0){
|
|
|
+ //可用余额减少
|
|
|
+ userAmount.setLeaderBalanceAmount(NumberUtil.sub(userAmount.getLeaderBalanceAmount(), param.getApplyAmount()));
|
|
|
+ }else if(kxsPartner != null){
|
|
|
+ //否则扣除盟主余额后还需扣除运营中心的金额
|
|
|
+ BigDecimal subPartnerAmt = NumberUtil.sub(param.getApplyAmount(), userAmount.getLeaderBalanceAmount());
|
|
|
+ kxsPartner.setWithdrawalAmount(NumberUtil.sub(kxsPartner.getWithdrawalAmount(), subPartnerAmt));
|
|
|
+
|
|
|
+ userAmount.setLeaderBalanceAmount(BigDecimal.ZERO);
|
|
|
+ kxsPartnerMapper.updateById(kxsPartner);
|
|
|
+ }else{
|
|
|
+ throw new GlobalCustomerException("可提现余额不足");
|
|
|
+ }
|
|
|
+ userAmountMapper.updateById(userAmount);
|
|
|
+
|
|
|
+ return R.ok(Boolean.TRUE);
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public IPage<WithdrawListVO> withdrawListPage(Page<WithdrawListVO> page, KxsUserWithdrawal param) {
|
|
|
+
|
|
|
+ param.setUserId(SecurityUtils.getUser().getId().intValue());
|
|
|
+
|
|
|
+ IPage<WithdrawListVO> byPage = baseMapper.getByPage(page, param);
|
|
|
|
|
|
for (WithdrawListVO record : byPage.getRecords()) {
|
|
|
String statusNo = EnumUtil.getFieldBy(WithdrawalStatusEnum::getDescription, WithdrawalStatusEnum::getType, record.getStatus());
|
|
|
@@ -176,5 +250,6 @@ public class KxsUserWithdrawalServiceImpl extends ServiceImpl<KxsUserWithdrawalM
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
}
|
|
|
|