| | |
| | | import cc.mrbird.febs.common.utils.AppContants; |
| | | import cc.mrbird.febs.common.utils.LoginUserUtil; |
| | | import cc.mrbird.febs.common.utils.MallUtils; |
| | | import cc.mrbird.febs.mall.dto.WithdrawalBalanceDto; |
| | | import cc.mrbird.febs.mall.dto.WithdrawalDto; |
| | | import cc.mrbird.febs.mall.entity.*; |
| | | import cc.mrbird.febs.mall.mapper.*; |
| | |
| | | private final MallMemberPaymentMapper mallMemberPaymentMapper; |
| | | private final DataDictionaryCustomMapper dataDictionaryCustomMapper; |
| | | private final MallMemberBankMapper mallMemberBankMapper; |
| | | private final MallMemberAmountMapper mallMemberAmountMapper; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void withdrawal(WithdrawalDto withdrawalDto) { |
| | | Long memberId = LoginUserUtil.getLoginUser().getId(); |
| | | MallMember mallMember = mallMemberService.getById(memberId); |
| | | |
| | | Integer outsideWith = mallMember.getOutsideWith() == null ? 2 :mallMember.getOutsideWith(); |
| | | if (1 != outsideWith) { |
| | | throw new FebsException("功能升级中"); |
| | | } |
| | | |
| | | if (StrUtil.isBlank(mallMember.getTradePassword())) { |
| | | throw new FebsException("未设置支付密码"); |
| | | } |
| | |
| | | |
| | | mallMemberService.addMoneyFlow(memberId, withdrawalDto.getAmount().negate(), MoneyFlowTypeEnum.WITHDRAWAL.getValue(), orderNo, null, null, null, 1, FlowTypeEnum.BALANCE.getValue()); |
| | | } |
| | | |
| | | @Override |
| | | public void withdrawalBalance(WithdrawalBalanceDto withdrawalBalanceDto) { |
| | | Long memberId = LoginUserUtil.getLoginUser().getId(); |
| | | MallMember mallMember = mallMemberService.getById(memberId); |
| | | if(ObjectUtil.isEmpty(mallMember.getBindPhone())){ |
| | | throw new FebsException("请绑定充值提取地址"); |
| | | } |
| | | |
| | | DataDictionaryCustom withdrawAmountDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.WITHDRAW_AMOUNT.getType(), |
| | | DataDictionaryEnum.WITHDRAW_AMOUNT.getCode() |
| | | ); |
| | | BigDecimal amount = withdrawalBalanceDto.getAmount(); |
| | | BigDecimal withdrawAmount = new BigDecimal(withdrawAmountDic.getValue()).setScale(2, BigDecimal.ROUND_DOWN); |
| | | if(withdrawAmount.compareTo(amount) > 0){ |
| | | throw new FebsException("最小金额:"+withdrawAmount); |
| | | } |
| | | |
| | | 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.setWithdrawNo(orderNo); |
| | | withdraw.setMemberId(memberId); |
| | | withdraw.setAmount(amount.negate()); |
| | | withdraw.setStatus(1); |
| | | withdraw.setAmountFee(fee); |
| | | withdraw.setRemark(mallMember.getBindPhone()); |
| | | this.baseMapper.insert(withdraw); |
| | | } |
| | | } |