package com.ruoyi.system.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.common.exception.ServiceException;
|
import com.ruoyi.system.domain.AccountDetail;
|
import com.ruoyi.system.domain.User;
|
import com.ruoyi.system.domain.Withdrawal;
|
import com.ruoyi.system.mapper.AccountDetailMapper;
|
import com.ruoyi.system.mapper.AppUserMapper;
|
import com.ruoyi.system.mapper.WithdrawMapper;
|
import com.ruoyi.system.pojo.dto.FinanceFlowsDTO;
|
import com.ruoyi.system.pojo.dto.WithDrawAgreeDTO;
|
import com.ruoyi.system.pojo.dto.WithDrawRefuseDTO;
|
import com.ruoyi.system.pojo.dto.WithdrawPageDTO;
|
import com.ruoyi.system.pojo.vo.WithdrawPageVO;
|
import com.ruoyi.system.service.WithdrawService;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
@Service
|
public class WithdrawServiceImpl extends ServiceImpl<WithdrawMapper, Withdrawal> implements WithdrawService {
|
|
|
private final AccountDetailMapper accountDetailMapper;
|
private final AppUserMapper appUserMapper;
|
|
public WithdrawServiceImpl(AccountDetailMapper accountDetailMapper, AppUserMapper appUserMapper) {
|
this.accountDetailMapper = accountDetailMapper;
|
this.appUserMapper = appUserMapper;
|
}
|
|
@Override
|
public IPage<WithdrawPageVO> withdrawPage(WithdrawPageDTO dto) {
|
IPage<WithdrawPageVO> page = new Page<>(dto.getPageNum(), dto.getPageSize());
|
return this.baseMapper.withdrawPage(page,dto);
|
}
|
|
@Transactional
|
@Override
|
public void agree(WithDrawAgreeDTO dto) {
|
Withdrawal withdrawal = this.baseMapper.selectById(dto.getId());
|
if (null == withdrawal ) {
|
throw new ServiceException("该申请记录不存在");
|
}
|
if (withdrawal.getStatus() != 0) {
|
throw new ServiceException("状态错误,不在审核状态中");
|
}
|
//审核通过 线下打款
|
//1.审核状态修改
|
withdrawal.setStatus(1);//通过
|
withdrawal.setImg(dto.getImg());
|
withdrawal.setRemark(dto.getRemark());
|
this.baseMapper.updateById(withdrawal);
|
//2.修改账户明细表
|
AccountDetail accountDetail = accountDetailMapper.selectOne(new LambdaQueryWrapper<AccountDetail>().eq(AccountDetail::getSourceId, withdrawal.getId()));
|
accountDetail.setStatus(2);//通过
|
accountDetail.setRemark(dto.getRemark());
|
accountDetailMapper.updateById(accountDetail);
|
}
|
|
@Transactional
|
@Override
|
public void refuse(WithDrawRefuseDTO dto) {
|
Withdrawal withdrawal = this.baseMapper.selectById(dto.getId());
|
if (null == withdrawal ) {
|
throw new ServiceException("该申请记录不存在");
|
}
|
if (withdrawal.getStatus() != 0) {
|
throw new ServiceException("状态错误,不在审核状态中");
|
}
|
//1.审核拒绝
|
withdrawal.setStatus(2);//拒绝
|
withdrawal.setRemark(dto.getRemark());//备注
|
this.baseMapper.updateById(withdrawal);
|
|
//2. 返回账户余额
|
User user = appUserMapper.selectById(withdrawal.getUserId());
|
user.setBalance(user.getBalance().add(withdrawal.getMoney()));
|
appUserMapper.updateById(user);
|
|
//3.修改账户明细表
|
AccountDetail accountDetail = accountDetailMapper.selectOne(new LambdaQueryWrapper<AccountDetail>().eq(AccountDetail::getSourceId, withdrawal.getId()));
|
accountDetail.setStatus(3);//通过
|
accountDetail.setRemark(dto.getRemark());
|
accountDetailMapper.updateById(accountDetail);
|
}
|
}
|