|
|
@@ -13,6 +13,7 @@ import com.kxs.common.security.util.SecurityUtils;
|
|
|
import com.kxs.store.api.dto.kxsapp.storeLimit.ForAmountWithdrawDTO;
|
|
|
import com.kxs.store.api.model.KxsWarehouseLimit;
|
|
|
import com.kxs.store.biz.constant.enums.StoreErrorTypeEnum;
|
|
|
+import com.kxs.store.biz.constant.enums.WarehouseLimitTypeEnum;
|
|
|
import com.kxs.store.biz.mapper.KxsForAmountWithdrawMapper;
|
|
|
import com.kxs.store.api.model.KxsForAmountWithdraw;
|
|
|
import com.kxs.store.biz.mapper.KxsWarehouseLimitMapper;
|
|
|
@@ -26,6 +27,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* 客小爽仓库临额提现申请表(KxsForAmountWithdraw)表服务实现类
|
|
|
@@ -43,7 +45,7 @@ public class KxsForAmountWithdrawServiceImpl extends ServiceImpl<KxsForAmountWit
|
|
|
|
|
|
@Override
|
|
|
@GlobalTransactional
|
|
|
- public R forAmountWithdraw(ForAmountWithdrawDTO param, Integer withdrawType) {
|
|
|
+ public R forAmountWithdraw(ForAmountWithdrawDTO param) {
|
|
|
|
|
|
Long userId = SecurityUtils.getUser().getId();
|
|
|
|
|
|
@@ -61,32 +63,30 @@ public class KxsForAmountWithdrawServiceImpl extends ServiceImpl<KxsForAmountWit
|
|
|
kxsForAmountWithdraw.setUserCode(realUserInfoVO.getUserCode());
|
|
|
kxsForAmountWithdraw.setBankName(realUserInfoVO.getBankName());
|
|
|
kxsForAmountWithdraw.setBankPhone(realUserInfoVO.getPhone());
|
|
|
- kxsForAmountWithdraw.setWithdrawType(withdrawType);
|
|
|
+ kxsForAmountWithdraw.setAmountType(param.getAmountType());
|
|
|
+ kxsForAmountWithdraw.setWithdrawType(param.getWhsType());
|
|
|
|
|
|
KxsWarehouseLimit userLimit = kxsWarehouseLimitMapper.selectOne(Wrappers.<KxsWarehouseLimit>lambdaQuery()
|
|
|
- .eq(KxsWarehouseLimit::getWarehouseType, param.getWithdrawType())
|
|
|
+ .eq(KxsWarehouseLimit::getWarehouseType, param.getWhsType())
|
|
|
.eq(KxsWarehouseLimit::getUserId, userId));
|
|
|
|
|
|
- BigDecimal forAmount;
|
|
|
- //小分仓提现
|
|
|
- if(withdrawType == 1){
|
|
|
- //可提现临时额度 可用额度-固定额度 = 可提现临时额度
|
|
|
- forAmount = NumberUtil.sub(userLimit.getValidAmount(), userLimit.getFixedAmount());
|
|
|
- }else{
|
|
|
- //仓库提现 可提现临时额度 = 临时额度 - (已用额度 - 担保额度 < 0 ? 0: )
|
|
|
- BigDecimal sub = NumberUtil.sub(userLimit.getUsedAmount(), userLimit.getCreditAmount());
|
|
|
- forAmount = NumberUtil.sub(userLimit.getForAmount(), sub.compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO : sub);
|
|
|
+ //临时额度总和
|
|
|
+ BigDecimal totalForAmt = NumberUtil.add(userLimit.getYueForAmount(), userLimit.getForAmount());
|
|
|
+
|
|
|
+ if(param.getAmount().compareTo(userLimit.getValidAmount()) > 0){
|
|
|
+ return R.failed("可用额度不足");
|
|
|
}
|
|
|
|
|
|
- if(forAmount.compareTo(NumberUtil.add(param.getBankAmount(),param.getYueAmount())) < 0){
|
|
|
+ if(param.getAmount().compareTo(totalForAmt) > 0){
|
|
|
return R.failed("临额不足");
|
|
|
}
|
|
|
//余额提现
|
|
|
- if(param.getYueAmount() != null && param.getYueAmount() > 0){
|
|
|
+ if(param.getAmountType() == 0){
|
|
|
+
|
|
|
yueWithdrawAmount(kxsForAmountWithdraw, param, userLimit);
|
|
|
}
|
|
|
//银行卡提现
|
|
|
- if(param.getBankAmount() != null && param.getBankAmount() > 0){
|
|
|
+ if(param.getAmountType() == 1){
|
|
|
bankWithdrawAmount(kxsForAmountWithdraw, param, userLimit);
|
|
|
}
|
|
|
|
|
|
@@ -106,15 +106,15 @@ public class KxsForAmountWithdrawServiceImpl extends ServiceImpl<KxsForAmountWit
|
|
|
//银行卡最大提现金额
|
|
|
BigDecimal bankCashAmount = userLimit.getForAmount();
|
|
|
//银行卡提现
|
|
|
- if(param.getBankAmount() > bankCashAmount.intValue()){
|
|
|
+ if(param.getAmount().compareTo(bankCashAmount) > 0){
|
|
|
throw new GlobalCustomerException("提现到银行卡超出限额");
|
|
|
}
|
|
|
- kxsForAmountWithdraw.setAmount(BigDecimal.valueOf(param.getBankAmount()));
|
|
|
+ kxsForAmountWithdraw.setAmount(param.getAmount());
|
|
|
baseMapper.insert(kxsForAmountWithdraw);
|
|
|
|
|
|
//扣减可用余额,扣减临额
|
|
|
- userLimit.setForAmount(NumberUtil.sub(userLimit.getForAmount(),param.getBankAmount()));
|
|
|
- userLimit.setValidAmount(NumberUtil.sub(userLimit.getValidAmount(),param.getBankAmount()));
|
|
|
+ userLimit.setForAmount(NumberUtil.sub(userLimit.getForAmount(),param.getAmount()));
|
|
|
+ userLimit.setValidAmount(NumberUtil.sub(userLimit.getValidAmount(),param.getAmount()));
|
|
|
kxsWarehouseLimitMapper.updateById(userLimit);
|
|
|
|
|
|
}
|
|
|
@@ -131,30 +131,30 @@ public class KxsForAmountWithdrawServiceImpl extends ServiceImpl<KxsForAmountWit
|
|
|
//余额最大提现金额
|
|
|
BigDecimal yueCashAmount = userLimit.getYueForAmount();
|
|
|
//余额提现
|
|
|
- if(param.getYueAmount() > yueCashAmount.intValue()){
|
|
|
+ if(param.getAmount().compareTo(yueCashAmount) > 0){
|
|
|
throw new GlobalCustomerException("提现到余额超出限额");
|
|
|
}
|
|
|
- kxsForAmountWithdraw.setAmount(BigDecimal.valueOf(param.getYueAmount()));
|
|
|
+ kxsForAmountWithdraw.setAmount(param.getAmount());
|
|
|
kxsForAmountWithdraw.setStatus(1);
|
|
|
baseMapper.insert(kxsForAmountWithdraw);
|
|
|
|
|
|
//扣减可用余额,扣减临额
|
|
|
- userLimit.setYueForAmount(NumberUtil.sub(userLimit.getForAmount(),param.getYueAmount()));
|
|
|
- userLimit.setValidAmount(NumberUtil.sub(userLimit.getValidAmount(),param.getYueAmount()));
|
|
|
+ userLimit.setYueForAmount(NumberUtil.sub(userLimit.getYueForAmount(), param.getAmount()));
|
|
|
+ userLimit.setValidAmount(NumberUtil.sub(userLimit.getValidAmount(), param.getAmount()));
|
|
|
kxsWarehouseLimitMapper.updateById(userLimit);
|
|
|
|
|
|
KxsUserAmountLog userAmountLog = new KxsUserAmountLog();
|
|
|
userAmountLog.setUserId(kxsForAmountWithdraw.getUserId());
|
|
|
userAmountLog.setKind(KindTypeEnum.ADD.getType());
|
|
|
//分仓临时额度提现
|
|
|
- if(kxsForAmountWithdraw.getWithdrawType() == 0){
|
|
|
+ if(Objects.equals(param.getWhsType(), WarehouseLimitTypeEnum.FC.getType())){
|
|
|
userAmountLog.setVariationType(AmountLogChangeTypesEnum.FOR_WILL_BE_REFUNDED.getType());
|
|
|
- userAmountLog.setVariationCause(AmountLogChangeTypesEnum.FOR_WILL_BE_REFUNDED.getDescription());
|
|
|
+ userAmountLog.setRemark(AmountLogChangeTypesEnum.FOR_WILL_BE_REFUNDED.getDescription());
|
|
|
}else{
|
|
|
userAmountLog.setVariationType(AmountLogChangeTypesEnum.ADVANCE_ISSUANCE_TEMPORARY_QUOTA_REFUND.getType());
|
|
|
- userAmountLog.setVariationCause(AmountLogChangeTypesEnum.ADVANCE_ISSUANCE_TEMPORARY_QUOTA_REFUND.getDescription());
|
|
|
+ userAmountLog.setRemark(AmountLogChangeTypesEnum.ADVANCE_ISSUANCE_TEMPORARY_QUOTA_REFUND.getDescription());
|
|
|
}
|
|
|
- userAmountLog.setAmount(BigDecimal.valueOf(param.getYueAmount()));
|
|
|
+ userAmountLog.setAmount(param.getAmount());
|
|
|
|
|
|
R<Boolean> booleanR = remoteKxsUserService.userAmountChange(userAmountLog, SecurityConstants.FROM_IN);
|
|
|
if(booleanR.getStatus() == 1 && !booleanR.getData()){
|