From 57bd5c68e1f71aa9cbd0bf2d561a736db3b0cbbf Mon Sep 17 00:00:00 2001 From: KKSU <15274802129@163.com> Date: Wed, 28 Aug 2024 16:09:45 +0800 Subject: [PATCH] 新增功能操作按钮,和更新了数据库数据 --- src/main/java/cc/mrbird/febs/mall/service/impl/MallMemberWithdrawServiceImpl.java | 67 +++++++++++++++++++++++++++++++++ 1 files changed, 66 insertions(+), 1 deletions(-) diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/MallMemberWithdrawServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/MallMemberWithdrawServiceImpl.java index 7cf9f63..cbdac3d 100644 --- a/src/main/java/cc/mrbird/febs/mall/service/impl/MallMemberWithdrawServiceImpl.java +++ b/src/main/java/cc/mrbird/febs/mall/service/impl/MallMemberWithdrawServiceImpl.java @@ -8,6 +8,7 @@ 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.*; @@ -47,12 +48,19 @@ 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("未设置支付密码"); } @@ -69,9 +77,14 @@ //每日提现额度上限 BigDecimal allCashOut = cashOutSettingVo.getAllCashOut(); + if(withdrawalDto.getAmount().compareTo(allCashOut) > 0){ + throw new FebsException("每日限额为"+cashOutSettingVo.getAllCashOut().setScale(2,BigDecimal.ROUND_DOWN)); + } List<MallMemberWithdraw> mallMemberWithdrawListDone = this.baseMapper.selectListByMemberIdAndDate(memberId,new Date()); if(CollUtil.isNotEmpty(mallMemberWithdrawListDone)){ - if (withdrawalDto.getAmount().compareTo(allCashOut) >= 0) { + BigDecimal amountTCAll = mallMemberWithdrawListDone.stream().map(MallMemberWithdraw::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); + amountTCAll = amountTCAll.add(withdrawalDto.getAmount()); + if (amountTCAll.compareTo(allCashOut) > 0) { throw new FebsException("每日限额为"+cashOutSettingVo.getAllCashOut().setScale(2,BigDecimal.ROUND_DOWN)); } } @@ -165,4 +178,56 @@ 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 (StrUtil.isBlank(mallMember.getTradePassword())) { + throw new FebsException("未设置支付密码"); + } + if (!mallMember.getTradePassword().equals(SecureUtil.md5(withdrawalBalanceDto.getTradePwd()))) { + throw new FebsException("支付密码错误"); + } + DataDictionaryCustom coinWithdrawDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( + DataDictionaryEnum.COIN_WITHDRAW.getType(), + DataDictionaryEnum.COIN_WITHDRAW.getCode() + ); + if(!"1".equals(coinWithdrawDic.getValue())){ + 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); + } + +// boolean b = Integer.parseInt(amount.toString()) % Integer.parseInt(withdrawAmount.toString()) == 0; + boolean b = amount.remainder(withdrawAmount).compareTo(BigDecimal.ZERO) == 0; + if(!b){ + throw new FebsException("金额必须为"+withdrawAmount+"的整数倍"); + } + + + MallMemberAmount mallMemberAmount = mallMemberAmountMapper.selectByMemberId(memberId); + mallMemberAmount.setFcmCntAva(mallMemberAmount.getFcmCntAva().subtract(amount)); + mallMemberAmountMapper.updateFcmCntAvaById(mallMemberAmount); + + String orderNo = MallUtils.getOrderNum("W"); + MallMemberWithdraw withdraw = new MallMemberWithdraw(); + withdraw.setWithdrawNo(orderNo); + withdraw.setMemberId(memberId); + withdraw.setAmount(amount.negate()); + withdraw.setStatus(1); + withdraw.setAmountFee(BigDecimal.ZERO); + withdraw.setRemark(withdrawalBalanceDto.getAddress()); + this.baseMapper.insert(withdraw); + + } } -- Gitblit v1.9.1