xiaoyong931011
2023-01-09 615b4cba39cc01756d7c0299204cc6ecaf172be5
src/main/java/cc/mrbird/febs/mall/service/impl/MallMemberWithdrawServiceImpl.java
@@ -2,6 +2,7 @@
import cc.mrbird.febs.common.enumerates.DataDictionaryEnum;
import cc.mrbird.febs.common.enumerates.FlowTypeEnum;
import cc.mrbird.febs.common.enumerates.MallMoneyFlowTypeEnum;
import cc.mrbird.febs.common.enumerates.MoneyFlowTypeEnum;
import cc.mrbird.febs.common.exception.FebsException;
import cc.mrbird.febs.common.utils.LoginUserUtil;
@@ -9,10 +10,7 @@
import cc.mrbird.febs.mall.dto.WithdrawalDto;
import cc.mrbird.febs.mall.entity.*;
import cc.mrbird.febs.mall.mapper.*;
import cc.mrbird.febs.mall.service.IApiMallMemberService;
import cc.mrbird.febs.mall.service.IApiMallMemberWalletService;
import cc.mrbird.febs.mall.service.IMallMemberWithdrawService;
import cc.mrbird.febs.mall.service.MallMemberService;
import cc.mrbird.febs.mall.service.*;
import cc.mrbird.febs.mall.vo.CashOutSettingVo;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
@@ -38,10 +36,11 @@
    private final IApiMallMemberService mallMemberService;
    private final MallMoneyFlowMapper mallMoneyFlowMapper;
    private final MallMemberWalletMapper mallMemberWalletMapper;
    private final IApiMallMemberWalletService walletService;
    private final IApiMallMemberWalletService memberWalletService;
    private final MallMemberPaymentMapper mallMemberPaymentMapper;
    private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
    private final MallMemberBankMapper mallMemberBankMapper;
    private final IMallMoneyFlowService mallMoneyFlowService;
    @Override
    @Transactional(rollbackFor = Exception.class)
@@ -62,39 +61,38 @@
            cashOutSettingVo = JSONObject.parseObject(dic.getValue(), CashOutSettingVo.class);
        }
        if (withdrawalDto.getAmount().compareTo(cashOutSettingVo.getMinCashOut()) < 0) {
            throw new FebsException("最小提现金额为"+cashOutSettingVo.getMinCashOut().setScale(2,BigDecimal.ROUND_DOWN));
        if (withdrawalDto.getAmount().compareTo(BigDecimal.ZERO) <= 0) {
            throw new FebsException("请输入正确的提现金额");
        }
        if(ObjectUtil.isEmpty(withdrawalDto.getBankNo())){
            throw new FebsException("请输入地址");
        }
        MallMemberBank mallMemberBank = mallMemberBankMapper.selectById(withdrawalDto.getBankId());
        if(ObjectUtil.isEmpty(mallMemberBank)){
            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 serviceFee = cashOutSettingVo.getServiceFee().multiply(BigDecimal.valueOf(0.01));
        walletService.reduce(withdrawalDto.getAmount(), memberId, "commission");
        BigDecimal serviceFee = cashOutSettingVo.getServiceFee();
        String orderNo = MallUtils.getOrderNum("W");
        //减少用户余额
        memberWalletService.reduce(withdrawalDto.getAmount(), memberId, "balance");
        //生成提现记录
        MallMemberWithdraw withdraw = new MallMemberWithdraw();
        withdraw.setWithdrawNo(orderNo);
        withdraw.setMemberId(memberId);
        withdraw.setAmount(withdrawalDto.getAmount());
        withdraw.setStatus(1);
        withdraw.setAmountFee(serviceFee.multiply(withdrawalDto.getAmount()));
        withdraw.setWtihdrawTypeId(mallMemberBank.getId());
        withdraw.setAmountFee(serviceFee);
        withdraw.setRemark(withdrawalDto.getBankNo());
//        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());
        //生成提现流水记录
        Long subsidyAmountFlowId = mallMoneyFlowService.addMoneyFlow(
                memberId,
                orderNo,
                withdrawalDto.getAmount().negate(),
                MallMoneyFlowTypeEnum.WITHDRAW.getCode(),
                MallMoneyFlow.STATUS_ING,
                MallMoneyFlow.IS_RETURN_Y,
                mallMember.getId(),
                FlowTypeEnum.BALANCE.getValue(),
                MallMoneyFlowTypeEnum.WITHDRAW.getName()
        );
    }
}