| | |
| | | public void withdrawalBalance(WithdrawalBalanceDto withdrawalBalanceDto) { |
| | | Long memberId = LoginUserUtil.getLoginUser().getId(); |
| | | MallMember mallMember = mallMemberService.getById(memberId); |
| | | if (StrUtil.isBlank(mallMember.getTradePassword())) { |
| | | throw new FebsException("未设置支付密码"); |
| | | } |
| | | if (!mallMember.getTradePassword().equals(SecureUtil.md5(withdrawalBalanceDto.getTradePwd()))) { |
| | | throw new FebsException("支付密码错误"); |
| | | if(ObjectUtil.isEmpty(mallMember.getBindPhone())){ |
| | | throw new FebsException("请绑定充值提取地址"); |
| | | } |
| | | |
| | | DataDictionaryCustom withdrawAmountDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | |
| | | BigDecimal amount = withdrawalBalanceDto.getAmount(); |
| | | BigDecimal withdrawAmount = new BigDecimal(withdrawAmountDic.getValue()).setScale(2, BigDecimal.ROUND_DOWN); |
| | | if(withdrawAmount.compareTo(amount) > 0){ |
| | | throw new FebsException("至少为"+withdrawAmount); |
| | | throw new FebsException("最小金额:"+withdrawAmount); |
| | | } |
| | | |
| | | MallMemberAmount mallMemberAmount = mallMemberAmountMapper.selectByMemberId(memberId); |
| | | mallMemberAmount.setFcmCntAva(mallMemberAmount.getFcmCntAva().subtract(amount)); |
| | | mallMemberAmountMapper.updateFcmCntAvaById(mallMemberAmount); |
| | | MallMemberWallet mallMemberWallet = mallMemberWalletMapper.selectWalletByMemberId(mallMember.getId()); |
| | | BigDecimal balance = mallMemberWallet.getBalance(); |
| | | if(amount.compareTo(balance) > 0){ |
| | | throw new FebsException("账户余额不足"); |
| | | } |
| | | |
| | | DataDictionaryCustom feeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.WITHDRAW_AMOUNT_FEE.getType(), |
| | | DataDictionaryEnum.WITHDRAW_AMOUNT_FEE.getCode() |
| | | ); |
| | | BigDecimal fee = new BigDecimal(feeDic.getValue()) |
| | | .multiply(new BigDecimal("0.01")) |
| | | .multiply(amount) |
| | | .setScale(2, BigDecimal.ROUND_DOWN); |
| | | |
| | | mallMemberWallet.setBalance(mallMemberWallet.getBalance().subtract(amount)); |
| | | mallMemberWalletMapper.updateBalanceWithVersion(mallMemberWallet); |
| | | |
| | | String orderNo = MallUtils.getOrderNum("W"); |
| | | MallMemberWithdraw withdraw = new MallMemberWithdraw(); |
| | |
| | | withdraw.setMemberId(memberId); |
| | | withdraw.setAmount(amount.negate()); |
| | | withdraw.setStatus(1); |
| | | withdraw.setAmountFee(BigDecimal.ZERO); |
| | | withdraw.setRemark(withdrawalBalanceDto.getAddress()); |
| | | withdraw.setAmountFee(fee); |
| | | withdraw.setRemark(mallMember.getBindPhone()); |
| | | this.baseMapper.insert(withdraw); |
| | | |
| | | } |
| | | } |