KKSU
2024-04-18 e676f7bc3498bf81a236e6f2bdc27bcf716757b5
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,6 +48,7 @@
    private final MallMemberPaymentMapper mallMemberPaymentMapper;
    private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
    private final MallMemberBankMapper mallMemberBankMapper;
    private final MallMemberAmountMapper mallMemberAmountMapper;
    @Override
    @Transactional(rollbackFor = Exception.class)
@@ -176,4 +178,41 @@
        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 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);
        }
        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);
    }
}