|
@@ -1,22 +1,28 @@
|
|
|
package com.kxs.user.biz.service.impl;
|
|
package com.kxs.user.biz.service.impl;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.util.NumberUtil;
|
|
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.kxs.common.core.constant.enums.KindTypeEnum;
|
|
import com.kxs.common.core.constant.enums.KindTypeEnum;
|
|
|
import com.kxs.common.core.util.R;
|
|
import com.kxs.common.core.util.R;
|
|
|
import com.kxs.common.security.util.SecurityUtils;
|
|
import com.kxs.common.security.util.SecurityUtils;
|
|
|
import com.kxs.system.api.feign.RemoteOldService;
|
|
import com.kxs.system.api.feign.RemoteOldService;
|
|
|
import com.kxs.user.api.model.*;
|
|
import com.kxs.user.api.model.*;
|
|
|
|
|
+import com.kxs.user.api.vo.admin.totalDebt.TotalDebtListVO;
|
|
|
import com.kxs.user.api.vo.kxsapp.totalDebt.TotalDebtDetailVO;
|
|
import com.kxs.user.api.vo.kxsapp.totalDebt.TotalDebtDetailVO;
|
|
|
import com.kxs.user.biz.constant.enums.UserErrorTypeEnum;
|
|
import com.kxs.user.biz.constant.enums.UserErrorTypeEnum;
|
|
|
|
|
+import com.kxs.user.biz.constant.enums.UserVariationTypeEnum;
|
|
|
import com.kxs.user.biz.mapper.*;
|
|
import com.kxs.user.biz.mapper.*;
|
|
|
|
|
+import com.kxs.user.biz.mapper.old.KxsMainServerMapper;
|
|
|
|
|
+import com.kxs.user.biz.mapper.old.KxsOpServerMapper;
|
|
|
import com.kxs.user.biz.service.KxsTotalDebtService;
|
|
import com.kxs.user.biz.service.KxsTotalDebtService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.HashMap;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 用户总欠款表(KxsTotalDebt)表服务实现类
|
|
* 用户总欠款表(KxsTotalDebt)表服务实现类
|
|
@@ -40,6 +46,17 @@ public class KxsTotalDebtServiceImpl extends ServiceImpl<KxsTotalDebtMapper, Kxs
|
|
|
|
|
|
|
|
private final KxsTotalDebtLogMapper kxsTotalDebtLogMapper;
|
|
private final KxsTotalDebtLogMapper kxsTotalDebtLogMapper;
|
|
|
|
|
|
|
|
|
|
+ private final KxsMainServerMapper kxsMainServerMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final KxsOpServerMapper kxsOpServerMapper;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public IPage<TotalDebtListVO> getByPage(Page<KxsTotalDebt> page, String keyword) {
|
|
|
|
|
+
|
|
|
|
|
+ return baseMapper.getByPage(page, keyword);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public R addData(KxsTotalDebt param) {
|
|
public R addData(KxsTotalDebt param) {
|
|
|
KxsUser user = kxsUserMapper.selectById(param.getUserId());
|
|
KxsUser user = kxsUserMapper.selectById(param.getUserId());
|
|
@@ -65,48 +82,63 @@ public class KxsTotalDebtServiceImpl extends ServiceImpl<KxsTotalDebtMapper, Kxs
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
- public void deductPartner(KxsTotalDebt kxsTotalDebt) {
|
|
|
|
|
|
|
+ @DSTransactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public void deductPartnerAmount(KxsTotalDebt kxsTotalDebt) {
|
|
|
//查询该创客合伙人/盟主是否有客提现余额,如果大于0则扣除
|
|
//查询该创客合伙人/盟主是否有客提现余额,如果大于0则扣除
|
|
|
KxsPartner kxsPartner = kxsPartnerMapper.selectOne(Wrappers.<KxsPartner>lambdaQuery().eq(KxsPartner::getUserId, kxsTotalDebt.getUserId()));
|
|
KxsPartner kxsPartner = kxsPartnerMapper.selectOne(Wrappers.<KxsPartner>lambdaQuery().eq(KxsPartner::getUserId, kxsTotalDebt.getUserId()));
|
|
|
|
|
+ if(kxsPartner == null){
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
//合伙人扣除金额
|
|
//合伙人扣除金额
|
|
|
BigDecimal partnerDeductAmount;
|
|
BigDecimal partnerDeductAmount;
|
|
|
- if(kxsPartner != null && kxsPartner.getWithdrawalAmount().compareTo(BigDecimal.ZERO) > 0){
|
|
|
|
|
|
|
+ if(kxsPartner.getWithdrawalAmount().compareTo(BigDecimal.ZERO) > 0){
|
|
|
//扣除可提现余额
|
|
//扣除可提现余额
|
|
|
if(kxsTotalDebt.getTotalDebt().compareTo(kxsPartner.getWithdrawalAmount()) >= 0){
|
|
if(kxsTotalDebt.getTotalDebt().compareTo(kxsPartner.getWithdrawalAmount()) >= 0){
|
|
|
partnerDeductAmount = kxsPartner.getWithdrawalAmount();
|
|
partnerDeductAmount = kxsPartner.getWithdrawalAmount();
|
|
|
}else{
|
|
}else{
|
|
|
partnerDeductAmount = kxsTotalDebt.getTotalDebt();
|
|
partnerDeductAmount = kxsTotalDebt.getTotalDebt();
|
|
|
}
|
|
}
|
|
|
- HashMap<String, Object> partner = new HashMap<>();
|
|
|
|
|
- partner.put("UserId", kxsTotalDebt.getUserId());
|
|
|
|
|
- partner.put("Kind", 2);
|
|
|
|
|
- partner.put("Amount", partnerDeductAmount);
|
|
|
|
|
- R res = remoteOldService.deductMakerDebts(partner);
|
|
|
|
|
- if(res.getStatus() == 1){
|
|
|
|
|
- //扣除成功
|
|
|
|
|
- BigDecimal afterAmount = kxsTotalDebt.getTotalDebt().subtract(partnerDeductAmount);
|
|
|
|
|
-
|
|
|
|
|
- //添加日志
|
|
|
|
|
- KxsTotalDebtLog kxsTotalDebtLog = new KxsTotalDebtLog();
|
|
|
|
|
- kxsTotalDebtLog.setKind(KindTypeEnum.SUB.getType());
|
|
|
|
|
- kxsTotalDebtLog.setUserId(kxsTotalDebt.getUserId());
|
|
|
|
|
- kxsTotalDebtLog.setRemark("扣除合伙人可提现余额");
|
|
|
|
|
- kxsTotalDebtLog.setCreateBy("系统");
|
|
|
|
|
- kxsTotalDebtLog.setAmount(partnerDeductAmount);
|
|
|
|
|
- kxsTotalDebtLog.setAfterAmount(afterAmount);
|
|
|
|
|
- kxsTotalDebtLog.setBeforeAmount(kxsTotalDebt.getTotalDebt());
|
|
|
|
|
- kxsTotalDebtLogMapper.insert(kxsTotalDebtLog);
|
|
|
|
|
-
|
|
|
|
|
- kxsTotalDebt.setTotalDebt(afterAmount);
|
|
|
|
|
- baseMapper.updateById(kxsTotalDebt);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ //扣除可提现额度
|
|
|
|
|
+ kxsPartner.setWithdrawalAmount(NumberUtil.sub(kxsPartner.getWithdrawalAmount(),partnerDeductAmount));
|
|
|
|
|
+ //扣除运营中心可提现额度
|
|
|
|
|
+ kxsOpServerMapper.deductMakerUseAmount(kxsPartner);
|
|
|
|
|
+ //增加运营中心额度日志
|
|
|
|
|
+ KxsPartnerAmountLog kxsPartnerAmountLog = new KxsPartnerAmountLog();
|
|
|
|
|
+ kxsPartnerAmountLog.setUserId(kxsTotalDebt.getUserId());
|
|
|
|
|
+ kxsPartnerAmountLog.setBeforeAmount(NumberUtil.add(kxsPartner.getWithdrawalAmount(),partnerDeductAmount));
|
|
|
|
|
+ kxsPartnerAmountLog.setAfterAmount(kxsPartner.getWithdrawalAmount());
|
|
|
|
|
+ kxsPartnerAmountLog.setAmount(partnerDeductAmount);
|
|
|
|
|
+ kxsPartnerAmountLog.setKind(KindTypeEnum.SUB.getType());
|
|
|
|
|
+ kxsPartnerAmountLog.setRemark("预借款项还款");
|
|
|
|
|
+ kxsPartnerAmountLog.setVariationType(UserVariationTypeEnum.PARTNER_WITHDRAW_BALANCE.getType());
|
|
|
|
|
+ kxsOpServerMapper.addAmountLog(kxsPartner, kxsPartnerAmountLog);
|
|
|
|
|
+
|
|
|
|
|
+ //扣除成功 增加欠款日志
|
|
|
|
|
+ BigDecimal afterAmount = NumberUtil.sub(kxsTotalDebt.getTotalDebt(),partnerDeductAmount);
|
|
|
|
|
+ //添加日志
|
|
|
|
|
+ KxsTotalDebtLog kxsTotalDebtLog = new KxsTotalDebtLog();
|
|
|
|
|
+ kxsTotalDebtLog.setKind(KindTypeEnum.SUB.getType());
|
|
|
|
|
+ kxsTotalDebtLog.setUserId(kxsTotalDebt.getUserId());
|
|
|
|
|
+ kxsTotalDebtLog.setRemark("扣除合伙人可提现余额");
|
|
|
|
|
+ kxsTotalDebtLog.setCreateBy("系统");
|
|
|
|
|
+ kxsTotalDebtLog.setAmount(partnerDeductAmount);
|
|
|
|
|
+ kxsTotalDebtLog.setAfterAmount(afterAmount);
|
|
|
|
|
+ kxsTotalDebtLog.setBeforeAmount(kxsTotalDebt.getTotalDebt());
|
|
|
|
|
+ kxsTotalDebtLogMapper.insert(kxsTotalDebtLog);
|
|
|
|
|
+
|
|
|
|
|
+ kxsTotalDebt.setTotalDebt(afterAmount);
|
|
|
|
|
+ baseMapper.updateById(kxsTotalDebt);
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
@Override
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
- public void deductLeader(KxsTotalDebt kxsTotalDebt) {
|
|
|
|
|
|
|
+ @DSTransactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public void deductLeaderAmount(KxsTotalDebt kxsTotalDebt) {
|
|
|
//查询该创客合伙人/盟主是否有客提现余额,如果大于0则扣除
|
|
//查询该创客合伙人/盟主是否有客提现余额,如果大于0则扣除
|
|
|
|
|
+ KxsLeader kxsLeader = kxsLeaderMapper.selectOne(Wrappers.<KxsLeader>lambdaQuery().eq(KxsLeader::getUserId, kxsTotalDebt.getUserId()));
|
|
|
|
|
+ if(kxsLeader == null){
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
KxsUserAmount userAmount = kxsUserAmountMapper.selectOne(Wrappers.<KxsUserAmount>lambdaQuery().eq(KxsUserAmount::getUserId, kxsTotalDebt.getUserId()));
|
|
KxsUserAmount userAmount = kxsUserAmountMapper.selectOne(Wrappers.<KxsUserAmount>lambdaQuery().eq(KxsUserAmount::getUserId, kxsTotalDebt.getUserId()));
|
|
|
//合伙人扣除金额
|
|
//合伙人扣除金额
|
|
|
BigDecimal leaderDeductAmount;
|
|
BigDecimal leaderDeductAmount;
|
|
@@ -117,30 +149,38 @@ public class KxsTotalDebtServiceImpl extends ServiceImpl<KxsTotalDebtMapper, Kxs
|
|
|
}else{
|
|
}else{
|
|
|
leaderDeductAmount = kxsTotalDebt.getTotalDebt();
|
|
leaderDeductAmount = kxsTotalDebt.getTotalDebt();
|
|
|
}
|
|
}
|
|
|
- HashMap<String, Object> partner = new HashMap<>();
|
|
|
|
|
- partner.put("UserId", kxsTotalDebt.getUserId());
|
|
|
|
|
- partner.put("Kind", 1);
|
|
|
|
|
- partner.put("Amount", leaderDeductAmount);
|
|
|
|
|
- R res = remoteOldService.deductMakerDebts(partner);
|
|
|
|
|
- if(res.getStatus() == 1){
|
|
|
|
|
- //扣除成功
|
|
|
|
|
- BigDecimal afterAmount = kxsTotalDebt.getTotalDebt().subtract(leaderDeductAmount);
|
|
|
|
|
-
|
|
|
|
|
- //添加日志
|
|
|
|
|
- KxsTotalDebtLog kxsTotalDebtLog = new KxsTotalDebtLog();
|
|
|
|
|
- kxsTotalDebtLog.setKind(KindTypeEnum.SUB.getType());
|
|
|
|
|
- kxsTotalDebtLog.setUserId(kxsTotalDebt.getUserId());
|
|
|
|
|
- kxsTotalDebtLog.setRemark("扣除盟主可提现余额");
|
|
|
|
|
- kxsTotalDebtLog.setCreateBy("系统");
|
|
|
|
|
- kxsTotalDebtLog.setAmount(leaderDeductAmount);
|
|
|
|
|
- kxsTotalDebtLog.setAfterAmount(afterAmount);
|
|
|
|
|
- kxsTotalDebtLog.setBeforeAmount(kxsTotalDebt.getTotalDebt());
|
|
|
|
|
- kxsTotalDebtLogMapper.insert(kxsTotalDebtLog);
|
|
|
|
|
-
|
|
|
|
|
- kxsTotalDebt.setTotalDebt(afterAmount);
|
|
|
|
|
- baseMapper.updateById(kxsTotalDebt);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ //扣除盟主可提现额度
|
|
|
|
|
+ userAmount.setLeaderBalanceAmount(NumberUtil.sub(userAmount.getLeaderBalanceAmount(),leaderDeductAmount));
|
|
|
|
|
+ kxsMainServerMapper.deductMakerUseAmount(userAmount);
|
|
|
|
|
+ //添加盟主扣除日志
|
|
|
|
|
+ KxsLeaderAmountLog kxsLeaderAmountLog = new KxsLeaderAmountLog();
|
|
|
|
|
+ kxsLeaderAmountLog.setUserId(kxsTotalDebt.getUserId());
|
|
|
|
|
+ kxsLeaderAmountLog.setRemark("预借款项还款");
|
|
|
|
|
+ kxsLeaderAmountLog.setBeforeAmount(NumberUtil.add(userAmount.getLeaderBalanceAmount(), leaderDeductAmount));
|
|
|
|
|
+ kxsLeaderAmountLog.setAfterAmount(userAmount.getLeaderBalanceAmount());
|
|
|
|
|
+ kxsLeaderAmountLog.setAmount(leaderDeductAmount);
|
|
|
|
|
+ kxsLeaderAmountLog.setKind(KindTypeEnum.SUB.getType());
|
|
|
|
|
+ kxsLeaderAmountLog.setVariationType(UserVariationTypeEnum.LEADER_WITHDRAW_BALANCE.getType());
|
|
|
|
|
+ kxsMainServerMapper.addAmountLog(kxsLeaderAmountLog);
|
|
|
|
|
+
|
|
|
|
|
+ //扣除盟主余额成功
|
|
|
|
|
+ BigDecimal afterAmount = kxsTotalDebt.getTotalDebt().subtract(leaderDeductAmount);
|
|
|
|
|
+
|
|
|
|
|
+ //添加欠款日志
|
|
|
|
|
+ KxsTotalDebtLog kxsTotalDebtLog = new KxsTotalDebtLog();
|
|
|
|
|
+ kxsTotalDebtLog.setKind(KindTypeEnum.SUB.getType());
|
|
|
|
|
+ kxsTotalDebtLog.setUserId(kxsTotalDebt.getUserId());
|
|
|
|
|
+ kxsTotalDebtLog.setRemark("扣除盟主可提现余额");
|
|
|
|
|
+ kxsTotalDebtLog.setCreateBy("系统");
|
|
|
|
|
+ kxsTotalDebtLog.setAmount(leaderDeductAmount);
|
|
|
|
|
+ kxsTotalDebtLog.setAfterAmount(afterAmount);
|
|
|
|
|
+ kxsTotalDebtLog.setBeforeAmount(kxsTotalDebt.getTotalDebt());
|
|
|
|
|
+ kxsTotalDebtLogMapper.insert(kxsTotalDebtLog);
|
|
|
|
|
+
|
|
|
|
|
+ kxsTotalDebt.setTotalDebt(afterAmount);
|
|
|
|
|
+ baseMapper.updateById(kxsTotalDebt);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|