| | |
| | | package com.ruoyi.account.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.account.api.feignClient.AppUserClient; |
| | | import com.ruoyi.account.api.model.*; |
| | | import com.ruoyi.account.dto.WithQuery; |
| | | import com.ruoyi.account.dto.WithdrawalRequestsDTO; |
| | | import com.ruoyi.account.mapper.WithdrawalRequestsMapper; |
| | | import com.ruoyi.account.api.model.WithdrawalRequests; |
| | | import com.ruoyi.account.service.WithdrawalRequestsService; |
| | | import com.ruoyi.account.service.*; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.common.core.utils.bean.BeanUtils; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.other.api.domain.VipSetting; |
| | | import com.ruoyi.system.api.model.LoginUser; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.LocalDateTime; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | */ |
| | | @Service |
| | | public class WithdrawalRequestsServiceImpl extends ServiceImpl<WithdrawalRequestsMapper, WithdrawalRequests> implements WithdrawalRequestsService { |
| | | @Resource |
| | | private TokenService tokenService; |
| | | @Resource |
| | | private AppUserService appUserService; |
| | | @Resource |
| | | private VipSettingService vipSettingService; |
| | | |
| | | @Resource |
| | | private BalanceChangeRecordService balanceChangeRecordService; |
| | | |
| | | public static final BigDecimal MAX_WITHDRAWAL_AMOUNT = new BigDecimal("200"); |
| | | public static final BigDecimal VIP_WITHDRAWAL_FEE_DENOMINATOR = new BigDecimal("100"); |
| | | |
| | | @Resource |
| | | private AppUserBankService appUserBankService; |
| | | |
| | | @Override |
| | | public void withdrawalApply(WithdrawalRequestsDTO params) { |
| | | BigDecimal withdrawalAmount = params.getWithdrawalAmount(); |
| | | 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("提现失败,可提现金额不足!"); |
| | | } |
| | | |
| | | |
| | | if (vipSetting.getVipWithdrawalRole() == 0) { |
| | | throw new ServiceException("提现失败,当前会员等级不允许提现!"); |
| | | } |
| | | |
| | | // 提现手续费 |
| | | 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)); |
| | | |
| | | WithdrawalRequests withdrawalRequests = new WithdrawalRequests(); |
| | | BeanUtils.copyBeanProp(withdrawalRequests, params); |
| | | if(2 == params.getWithdrawalMethod()){ |
| | | AppUserBank appUserBank = appUserBankService.getOne(new LambdaQueryWrapper<AppUserBank>().eq(AppUserBank::getAppUserId, loginUserApplet.getUserid())); |
| | | if(null == appUserBank){ |
| | | throw new ServiceException("请先添加提款账户!"); |
| | | } |
| | | withdrawalRequests.setAccountHolder(appUserBank.getBankName()); |
| | | withdrawalRequests.setBankCardNumber(appUserBank.getBankNumber()); |
| | | } |
| | | withdrawalRequests.setWithdrawalAmount(withdrawalAmount); |
| | | withdrawalRequests.setArrivalAmount(params.getWithdrawalAmount()); |
| | | withdrawalRequests.setServiceCharge(multiply); |
| | | withdrawalRequests.setDelFlag(0); |
| | | withdrawalRequests.setAppUserId(SecurityUtils.getUserId()); |
| | | withdrawalRequests.setAuditStatus(1); |
| | | save(withdrawalRequests); |
| | | //修改用户的可提现金额 |
| | | BigDecimal withdrawnAmount = appUser.getWithdrawnAmount(); |
| | | BigDecimal balance = appUser.getBalance(); |
| | | appUser.setWithdrawableAmount(withdrawableAmount.subtract(withdrawalAmount).setScale(2, RoundingMode.HALF_EVEN)); |
| | | appUser.setWithdrawnAmount(withdrawnAmount.add(withdrawalAmount).setScale(2, RoundingMode.HALF_EVEN)); |
| | | appUser.setBalance(appUser.getBalance().subtract(withdrawalAmount).setScale(2, RoundingMode.HALF_EVEN)); |
| | | appUserService.updateById(appUser); |
| | | //添加变动明细 |
| | | BalanceChangeRecord balanceChangeRecord = new BalanceChangeRecord(); |
| | | balanceChangeRecord.setAppUserId(appUser.getId()); |
| | | balanceChangeRecord.setVipId(appUser.getVipId()); |
| | | balanceChangeRecord.setOrderId(withdrawalRequests.getId()); |
| | | balanceChangeRecord.setChangeType(2); |
| | | balanceChangeRecord.setChangeAmount(withdrawalAmount); |
| | | balanceChangeRecord.setDelFlag(0); |
| | | balanceChangeRecord.setCreateTime(LocalDateTime.now()); |
| | | balanceChangeRecord.setChangeDirection(-1); |
| | | balanceChangeRecordService.save(balanceChangeRecord); |
| | | } |
| | | |
| | | @Override |
| | | public IPage<WithdrawalRequests> pageList(WithQuery withQuery) { |
| | | Page<UserClickLog> page = new Page<>(); |
| | | page.setCurrent(withQuery.getPageNum()); |
| | | page.setSize(withQuery.getPageSize()); |
| | | IPage<WithdrawalRequests> shopIPage = this.baseMapper.pageList(page, withQuery); |
| | | return shopIPage; |
| | | } |
| | | |
| | | } |