xiaoyong931011
2023-04-04 869ea72afdca9ad0f83a6f09659e4a4478012606
src/main/java/cc/mrbird/febs/mall/service/impl/MallMemberWithdrawServiceImpl.java
@@ -2,8 +2,10 @@
import cc.mrbird.febs.common.enumerates.DataDictionaryEnum;
import cc.mrbird.febs.common.enumerates.FlowTypeEnum;
import cc.mrbird.febs.common.enumerates.GreenScoreEnum;
import cc.mrbird.febs.common.enumerates.MoneyFlowTypeEnum;
import cc.mrbird.febs.common.exception.FebsException;
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.WithdrawalDto;
@@ -71,18 +73,6 @@
            throw new FebsException("未找到银行卡信息");
        }
//        BigDecimal profit = mallMoneyFlowMapper.selectProfitByDateAndMemberId(memberId);
//        MallMemberWallet wallet = mallMemberWalletMapper.selectWalletByMemberId(memberId);
//        if (profit != null) {
//            // 可提现
//            BigDecimal canMoney = wallet.getCommission().subtract(profit);
//
//            if(withdrawalDto.getAmount().compareTo(canMoney) > 0) {
//                throw new FebsException("提现金额不足");
//            }
//        }
//        BigDecimal profit = mallMoneyFlowMapper.selectProfitByDateAndMemberId(memberId);
        MallMemberWallet wallet = mallMemberWalletMapper.selectWalletByMemberId(memberId);
        // 可提现
        BigDecimal canMoney = wallet.getBalance();
@@ -91,8 +81,47 @@
            throw new FebsException("提现金额不足");
        }
        BigDecimal serviceFee = cashOutSettingVo.getServiceFee().multiply(BigDecimal.valueOf(0.01));
        walletService.reduce(withdrawalDto.getAmount(), memberId, "commission");
        BigDecimal serviceFeePercent = cashOutSettingVo.getServiceFee().multiply(BigDecimal.valueOf(0.01));
        BigDecimal serviceFee = serviceFeePercent.multiply(withdrawalDto.getAmount());
        String remark = AppContants.MEMBER_WITHDRAW_NORMAL;
        DataDictionaryCustom voucherOnOffDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                GreenScoreEnum.VOUCHER_ON_OFF.getType(),
                GreenScoreEnum.VOUCHER_ON_OFF.getCode()
        );
        if(ObjectUtil.isNotEmpty(voucherOnOffDic)){
            String voucherOnOff = voucherOnOffDic.getValue();
            /**
             * 绿色凭证提现开关 1:开启 2:关闭
             *      验证账户凭证数量
             *      不需要手续费
             *      减少用户的凭证数量
             */
            if("1".equals(voucherOnOff)){
                BigDecimal voucherCntDto = withdrawalDto.getVoucherCnt();
                if(voucherCntDto.compareTo(BigDecimal.ZERO) <= 0){
                    throw new FebsException("绿色积分不足");
                }
                //提现需要的凭证数量 = 提现金额 * 余额提现需要绿色凭证比例
                DataDictionaryCustom voucherPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                        GreenScoreEnum.VOUCHER_PERCENT.getType(),
                        GreenScoreEnum.VOUCHER_PERCENT.getCode()
                );
                BigDecimal voucherPercent = new BigDecimal(voucherPercentDic.getValue() == null ? "0" : voucherPercentDic.getValue());
                BigDecimal voucherPercentNeed = withdrawalDto.getAmount().multiply(voucherPercent).setScale(2,BigDecimal.ROUND_DOWN);
                BigDecimal voucherCnt = wallet.getVoucherCnt();
                if(voucherCnt.compareTo(voucherPercentNeed) < 0){
                    throw new FebsException("绿色积分不足");
                }
                walletService.reduce(voucherCntDto, memberId, "voucher_cnt");
                serviceFee = voucherCntDto;
                remark = AppContants.MEMBER_WITHDRAW_VOUCHER;
            }
        }
        walletService.reduce(withdrawalDto.getAmount(), memberId, "balance");
        String orderNo = MallUtils.getOrderNum("W");
        MallMemberWithdraw withdraw = new MallMemberWithdraw();
@@ -100,10 +129,11 @@
        withdraw.setMemberId(memberId);
        withdraw.setAmount(withdrawalDto.getAmount());
        withdraw.setStatus(1);
        withdraw.setAmountFee(serviceFee.multiply(withdrawalDto.getAmount()));
        withdraw.setAmountFee(serviceFee);
        withdraw.setRemark(remark);
        withdraw.setWtihdrawTypeId(mallMemberBank.getId());
        this.baseMapper.insert(withdraw);
        mallMemberService.addMoneyFlow(memberId, withdrawalDto.getAmount().negate(), MoneyFlowTypeEnum.WITHDRAWAL.getValue(), orderNo, null, null, null, 1, FlowTypeEnum.COMMISSION.getValue());
        mallMemberService.addMoneyFlow(memberId, withdrawalDto.getAmount().negate(), MoneyFlowTypeEnum.WITHDRAWAL.getValue(), orderNo, null, null, null, 1, FlowTypeEnum.BALANCE.getValue());
    }
}