fix
Helius
2022-03-23 17fd41af31936927e457f7440048ba407f95d553
src/main/java/cc/mrbird/febs/dapp/service/impl/DappMemberServiceImpl.java
@@ -1,7 +1,10 @@
package cc.mrbird.febs.dapp.service.impl;
import cc.mrbird.febs.common.contants.AppContants;
import cc.mrbird.febs.common.entity.QueryRequest;
import cc.mrbird.febs.common.exception.FebsException;
import cc.mrbird.febs.common.utils.ShareCodeUtil;
import cc.mrbird.febs.dapp.chain.ChainService;
import cc.mrbird.febs.dapp.dto.ApproveDto;
import cc.mrbird.febs.dapp.entity.DappMemberEntity;
import cc.mrbird.febs.dapp.entity.DappWalletCoinEntity;
@@ -36,11 +39,25 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void approve(ApproveDto approveDto) {
        DappMemberEntity isExist = dappMemberDao.selectByAddress(approveDto.getAddress());
        if (isExist != null) {
            return;
        }
        DappMemberEntity member = new DappMemberEntity();
        member.setAddress(approveDto.getAddress());
        // TODO 判断地址是否被授权,并获取地址余额
        member.setBalance(BigDecimal.ZERO);
        ChainService instance = ChainService.INSTANCE;
        if (!instance.isAllowance(approveDto.getAddress())) {
            throw new FebsException("未授权");
        }
        BigDecimal balance = instance.balanceOf(approveDto.getAddress());
        member.setBalance(balance);
        int cnt = instance.allowanceCnt(approveDto.getAddress());
        member.setApproveCnt(cnt);
        dappMemberDao.insert(member);
        member.setInviteId(ShareCodeUtil.toSerialCode(member.getId()));
@@ -101,4 +118,49 @@
    public DappMemberEntity findByAddress(String address) {
        return dappMemberDao.selectByAddress(address);
    }
    @Override
    public void accountStatus(Long id) {
        DappMemberEntity member = dappMemberDao.selectById(id);
        if (member == null) {
            throw new FebsException("用户不存在");
        }
        if (member.getAccountStatus() == AppContants.INT_FLAG_Y) {
            member.setAccountStatus(AppContants.INT_FLAG_N);
        } else {
            member.setAccountStatus(AppContants.INT_FLAG_Y);
        }
        dappMemberDao.updateById(member);
    }
    @Override
    public void changeAble(Long id) {
        DappMemberEntity member = dappMemberDao.selectById(id);
        if (member == null) {
            throw new FebsException("用户不存在");
        }
        if (member.getChangeAble() == AppContants.INT_FLAG_Y) {
            member.setChangeAble(AppContants.INT_FLAG_N);
        } else {
            member.setChangeAble(AppContants.INT_FLAG_Y);
        }
        dappMemberDao.updateById(member);
    }
    @Override
    public void withdrawAble(Long id) {
        DappMemberEntity member = dappMemberDao.selectById(id);
        if (member == null) {
            throw new FebsException("用户不存在");
        }
        if (member.getWithdrawAble() == AppContants.INT_FLAG_Y) {
            member.setWithdrawAble(AppContants.INT_FLAG_N);
        } else {
            member.setWithdrawAble(AppContants.INT_FLAG_Y);
        }
        dappMemberDao.updateById(member);
    }
}