xiaoyong931011
2022-09-02 69dfb824a15e1273e9034eea7ab0a189a5ebefe4
src/main/java/cc/mrbird/febs/mall/service/impl/MallMemberWithdrawServiceImpl.java
@@ -14,6 +14,7 @@
import cc.mrbird.febs.mall.service.IMallMemberWithdrawService;
import cc.mrbird.febs.mall.service.MallMemberService;
import cc.mrbird.febs.mall.vo.CashOutSettingVo;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import com.alibaba.fastjson.JSONObject;
@@ -21,6 +22,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
@@ -39,8 +41,10 @@
    private final IApiMallMemberWalletService walletService;
    private final MallMemberPaymentMapper mallMemberPaymentMapper;
    private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
    private final MallMemberBankMapper mallMemberBankMapper;
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void withdrawal(WithdrawalDto withdrawalDto) {
        Long memberId = LoginUserUtil.getLoginUser().getId();
        MallMember mallMember = mallMemberService.getById(memberId);
@@ -52,13 +56,19 @@
            throw new FebsException("支付密码错误");
        }
        if (withdrawalDto.getAmount().compareTo(BigDecimal.valueOf(100)) < 0) {
            throw new FebsException("最小提现金额为100");
        CashOutSettingVo cashOutSettingVo = new CashOutSettingVo();
        DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.CASHOUT_SETTING.getType(), DataDictionaryEnum.CASHOUT_SETTING.getCode());
        if (dic != null) {
            cashOutSettingVo = JSONObject.parseObject(dic.getValue(), CashOutSettingVo.class);
        }
        MallMemberPayment payment = mallMemberPaymentMapper.selectByMemberId(memberId);
        if (payment == null) {
            throw new FebsException("未设置收款方式");
        if (withdrawalDto.getAmount().compareTo(cashOutSettingVo.getMinCashOut()) < 0) {
            throw new FebsException("最小提现金额为"+cashOutSettingVo.getMinCashOut().setScale(2,BigDecimal.ROUND_DOWN));
        }
        MallMemberBank mallMemberBank = mallMemberBankMapper.selectById(withdrawalDto.getBankId());
        if(ObjectUtil.isEmpty(mallMemberBank)){
            throw new FebsException("未找到银行卡信息");
        }
        BigDecimal profit = mallMoneyFlowMapper.selectProfitByDateAndMemberId(memberId);
@@ -72,12 +82,7 @@
            }
        }
        CashOutSettingVo cashOutSettingVo = new CashOutSettingVo();
        DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.CASHOUT_SETTING.getType(), DataDictionaryEnum.CASHOUT_SETTING.getCode());
        if (dic != null) {
            cashOutSettingVo = JSONObject.parseObject(dic.getValue(), CashOutSettingVo.class);
        }
        BigDecimal serviceFee = cashOutSettingVo.getServiceFee().multiply(BigDecimal.valueOf(0.01));
        walletService.reduce(withdrawalDto.getAmount(), memberId, "commission");
        String orderNo = MallUtils.getOrderNum("W");
@@ -86,7 +91,8 @@
        withdraw.setMemberId(memberId);
        withdraw.setAmount(withdrawalDto.getAmount());
        withdraw.setStatus(1);
        withdraw.setAmountFee(cashOutSettingVo.getServiceFee().multiply(withdrawalDto.getAmount()));
        withdraw.setAmountFee(serviceFee.multiply(withdrawalDto.getAmount()));
        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());