huliguo
2025-06-05 0a492b64ca1a4e40cc9ea56eddd1afe2c09a12b3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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);
    }
}