Pu Zhibing
2025-04-22 fd7b8fb7c89832c28a838b0449bbb8a392433ee2
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/WithdrawalRequestsServiceImpl.java
@@ -53,33 +53,36 @@
    @Override
    public void withdrawalApply(WithdrawalRequestsDTO params) {
        BigDecimal withdrawalAmount = params.getWithdrawalAmount();
        if (withdrawalAmount.compareTo(MAX_WITHDRAWAL_AMOUNT) > 0) {
        if (withdrawalAmount.compareTo(MAX_WITHDRAWAL_AMOUNT) > 0 && params.getWithdrawalMethod().equals(1)) {
            throw new ServiceException("提现失败,单次提现金额不能超过200元!");
        }
        LoginUser loginUserApplet = tokenService.getLoginUserApplet();
        AppUser appUser = appUserService.getById(loginUserApplet.getUserid());
        Integer vipId = appUser.getVipId();
        VipSetting vipSetting = vipSettingService.getVipSettingById(vipId);
        BigDecimal withdrawableAmount = appUser.getWithdrawableAmount();
        BigDecimal vipWithdrawalMinAmount = vipSetting.getVipWithdrawalMinAmount();
        if (vipWithdrawalMinAmount.compareTo(withdrawableAmount) > 0) {
            throw new ServiceException("提现失败,提现门槛为:"+vipWithdrawalMinAmount+"元!");
        }
        if (appUser.getWithdrawableAmount().compareTo(withdrawalAmount) < 0) {
            throw new ServiceException("提现失败,可提现金额不足!");
        }
        Integer vipId = appUser.getVipId();
        VipSetting vipSetting = vipSettingService.getVipSettingById(vipId);
        if (vipSetting.getVipWithdrawalRole() == 0) {
            throw new ServiceException("提现失败,当前会员等级不允许提现!");
        }
        BigDecimal vipWithdrawalMinAmount = vipSetting.getVipWithdrawalMinAmount();
        if (withdrawalAmount.compareTo(vipWithdrawalMinAmount) < 0) {
            throw new ServiceException("提现失败,提现金额不能小于" + vipWithdrawalMinAmount + "元!");
        }
        // 提现手续费
        BigDecimal vipWithdrawalFee = vipSetting.getVipWithdrawalFee()
                .divide(VIP_WITHDRAWAL_FEE_DENOMINATOR, 2, RoundingMode.HALF_UP);
        // 减去手续费
        BigDecimal multiply = params.getWithdrawalAmount().multiply(vipWithdrawalFee);
        params.setWithdrawalAmount(params.getWithdrawalAmount()
                .subtract(multiply));
        params.setWithdrawalAmount(params.getWithdrawalAmount().subtract(multiply));
        WithdrawalRequests withdrawalRequests = new WithdrawalRequests();
        BeanUtils.copyBeanProp(withdrawalRequests, params);
@@ -92,14 +95,13 @@
            withdrawalRequests.setBankCardNumber(appUserBank.getBankNumber());
        }
        withdrawalRequests.setWithdrawalAmount(withdrawalAmount);
        withdrawalRequests.setArrivalAmount(withdrawalRequests.getWithdrawalAmount());
        withdrawalRequests.setArrivalAmount(params.getWithdrawalAmount());
        withdrawalRequests.setServiceCharge(multiply);
        withdrawalRequests.setDelFlag(0);
        withdrawalRequests.setAppUserId(SecurityUtils.getUserId());
        withdrawalRequests.setAuditStatus(1);
        save(withdrawalRequests);
        //修改用户的可提现金额
        BigDecimal withdrawableAmount = appUser.getWithdrawableAmount();
        BigDecimal withdrawnAmount = appUser.getWithdrawnAmount();
        BigDecimal balance = appUser.getBalance();
        appUser.setWithdrawableAmount(withdrawableAmount.subtract(withdrawalAmount).setScale(2, RoundingMode.HALF_EVEN));
@@ -112,11 +114,10 @@
        balanceChangeRecord.setVipId(appUser.getVipId());
        balanceChangeRecord.setOrderId(withdrawalRequests.getId());
        balanceChangeRecord.setChangeType(2);
        balanceChangeRecord.setBeforeAmount(balance);
        balanceChangeRecord.setChangeAmount(withdrawalAmount);
        balanceChangeRecord.setAfterAmount(appUser.getBalance());
        balanceChangeRecord.setDelFlag(0);
        balanceChangeRecord.setCreateTime(LocalDateTime.now());
        balanceChangeRecord.setChangeDirection(-1);
        balanceChangeRecordService.save(balanceChangeRecord);
    }