KKSU
2024-06-21 5519fb3a19df1bb839d29d23abc3f320c5c77baa
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
91
92
package cc.mrbird.febs.dapp.service.impl;
 
import cc.mrbird.febs.common.entity.FebsResponse;
import cc.mrbird.febs.common.entity.QueryRequest;
import cc.mrbird.febs.common.exception.FebsException;
import cc.mrbird.febs.dapp.entity.*;
import cc.mrbird.febs.dapp.mapper.*;
import cc.mrbird.febs.dapp.service.AdminOperationService;
import cc.mrbird.febs.dapp.service.DappWalletService;
import cc.mrbird.febs.dapp.vo.AdminMemberCoinWithdrawVo;
import cc.mrbird.febs.rabbit.producer.ChainProducer;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.math.BigDecimal;
 
@Service
@RequiredArgsConstructor
public class AdminOperationServiceImpl extends ServiceImpl<DappMemberDao, DappMemberEntity> implements AdminOperationService {
 
    private final MemberCoinWithdrawDao memberCoinWithdrawDao;
    private final DappWalletCoinDao dappWalletCoinDao;
    private final DappMemberDao dappMemberDao;
    private final DappAccountMoneyChangeDao dappAccountMoneyChangeDao;
    private final DappWalletService dappWalletService;
    private final DappFundFlowDao dappFundFlowDao;
    private final ChainProducer chainProducer;
 
    @Override
    public IPage<AdminMemberCoinWithdrawVo> findMemberWithdrawCoinAllOneInPage(MemberCoinWithdrawEntity memberCoinWithdrawEntity, QueryRequest request) {
        Page<MemberCoinWithdrawEntity> page = new Page<>(request.getPageNum(), request.getPageSize());
        IPage<AdminMemberCoinWithdrawVo> adminMemberCoinWithdrawVoIPage = memberCoinWithdrawDao.findMemberWithdrawCoinInPage(page, memberCoinWithdrawEntity);
        return adminMemberCoinWithdrawVoIPage;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public FebsResponse agreeWithdraw(Long id) {
        MemberCoinWithdrawEntity memberCoinWithdrawEntity = memberCoinWithdrawDao.selectById(id);
        if(ObjectUtil.isEmpty(memberCoinWithdrawEntity)){
            throw new FebsException("刷新页面重试");
        }
 
        if (MemberCoinWithdrawEntity.STATUS_DOING != memberCoinWithdrawEntity.getStatus()) {
            throw new FebsException("非可审核状态");
        }
        memberCoinWithdrawEntity.setStatus(MemberCoinWithdrawEntity.STATUS_YES);
        memberCoinWithdrawDao.updateById(memberCoinWithdrawEntity);
 
        DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectById(memberCoinWithdrawEntity.getFlowId());
        dappFundFlowEntity.setStatus(DappFundFlowEntity.WITHDRAW_STATUS_AGREE);
        dappFundFlowDao.updateById(dappFundFlowEntity);
 
        chainProducer.sendFeeDistributeMsg(dappFundFlowEntity.getId());
        return new FebsResponse().success();
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public FebsResponse disagreeWithdraw(Long id) {
        MemberCoinWithdrawEntity memberCoinWithdrawEntity = memberCoinWithdrawDao.selectById(id);
        if(ObjectUtil.isEmpty(memberCoinWithdrawEntity)){
            throw new FebsException("刷新页面重试");
        }
 
        if (MemberCoinWithdrawEntity.STATUS_DOING != memberCoinWithdrawEntity.getStatus()) {
            throw new FebsException("非可审核状态");
        }
 
        DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectById(memberCoinWithdrawEntity.getFlowId());
        if (dappFundFlowEntity == null) {
            throw new FebsException("审核失败,联系管理员");
        }
        memberCoinWithdrawEntity.setStatus(MemberCoinWithdrawEntity.STATUS_NO);
        memberCoinWithdrawDao.updateById(memberCoinWithdrawEntity);
 
        dappFundFlowEntity.setStatus(DappFundFlowEntity.WITHDRAW_STATUS_DISAGREE);
        dappFundFlowDao.updateById(dappFundFlowEntity);
 
        dappWalletService.updateWalletCoinWithLock(memberCoinWithdrawEntity.getAmount(), memberCoinWithdrawEntity.getMemberId(), 1);
        dappWalletService.updateWalletMineWithLock(memberCoinWithdrawEntity.getFeeAmount(), memberCoinWithdrawEntity.getMemberId(), 1);
 
        DappFundFlowEntity feeFlow = new DappFundFlowEntity(memberCoinWithdrawEntity.getMemberId(), memberCoinWithdrawEntity.getFeeAmount(), 7, 2, null, null);
        dappFundFlowDao.insert(feeFlow);
        return new FebsResponse().success();
    }
}