KKSU
2024-04-26 1da6dad3fd2ac6d51125aa1f2d459ae1f146f8ff
src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java
@@ -17,6 +17,7 @@
import cc.mrbird.febs.rabbit.producer.ChainProducer;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
@@ -166,6 +167,9 @@
        if (recordInPageDto.getType() != null && recordInPageDto.getType() != 0) {
            dappFundFlowEntity.setStatus(recordInPageDto.getType());
        }
        if (recordInPageDto.getState() != null && recordInPageDto.getState() != 0) {
            dappFundFlowEntity.setType(recordInPageDto.getState());
        }
        dappFundFlowEntity.setMemberId(member.getId());
        IPage<DappFundFlowEntity> records = dappFundFlowDao.selectInPages(page, dappFundFlowEntity);
        return records.getRecords();
@@ -235,6 +239,30 @@
    @Transactional(rollbackFor = Exception.class)
    public Long transfer(TransferDto transferDto) {
        DappMemberEntity member = LoginUserUtil.getAppUser();
//        QueryWrapper<DappFundFlowEntity> objectQueryWrapper = new QueryWrapper<>();
//        objectQueryWrapper.eq("type" ,FlowTypeEnum.ZHI_YA.getValue());
//        objectQueryWrapper.eq("status" ,DappFundFlowEntity.WITHDRAW_STATUS_AGREE);
//        objectQueryWrapper.eq("member_id" ,member.getId());
//        List<DappFundFlowEntity> dappFundFlowEntities = dappFundFlowDao.selectList(objectQueryWrapper);
        List<DappFundFlowEntity> dappFundFlowEntities = dappFundFlowDao.selectAmountTotalByTypeAndMemberIdAndDateAndState(
                member.getId(),
                FlowTypeEnum.ZHI_YA.getValue(),
                DappFundFlowEntity.WITHDRAW_STATUS_AGREE,
                new Date());
        BigDecimal zhiyaAmount = new BigDecimal(redisUtils.getString(DataDicEnum.MEMBER_ZHIYA_AMOUNT.getValue()));
        Integer zhiyaTime = Integer.parseInt(redisUtils.getString(DataDicEnum.MEMBER_ZHIYA_TIME.getValue()));
        if(CollUtil.isNotEmpty(dappFundFlowEntities)){
            if(dappFundFlowEntities.size() >= zhiyaTime){
                throw new FebsException("今日暂停质押");
            }
            BigDecimal teamAchieveMemberSum = dappFundFlowEntities.stream().map(DappFundFlowEntity::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add).negate();
            if(zhiyaAmount.compareTo(teamAchieveMemberSum.add(transferDto.getAmount())) < 0){
                throw new FebsException("今日最多质押"+zhiyaAmount.subtract(teamAchieveMemberSum).setScale(4,BigDecimal.ROUND_DOWN));
            }
        }
        String hasStart = redisUtils.getString(DataDicEnum.SYSTEM_START_FLAG.getValue());
        BigDecimal minAmount = new BigDecimal(redisUtils.getString(DataDicEnum.GFA_BUY_MIN_AMOUNT.getValue()));
@@ -253,11 +281,11 @@
                    if (transferDto.getAmount().compareTo(minAmount) < 0) {
                        throw new FebsException("超过购买限制");
                    }
                    if (BigDecimal.ZERO.compareTo(gfaDays) >= 0) {
                        throw new FebsException("今日暂停质押");
                    }
                    if (transferDto.getAmount().compareTo(gfaDays) > 0) {
                        throw new FebsException("今日最多质押"+gfaDays);
//                    if (BigDecimal.ZERO.compareTo(gfaDays) >= 0) {
//                        throw new FebsException("今日暂停质押");
//                    }
                    if (transferDto.getAmount().compareTo(zhiyaAmount) > 0) {
                        throw new FebsException("今日最多质押"+zhiyaAmount);
                    }
                } else {
                    throw new FebsException("暂停质押");
@@ -298,6 +326,7 @@
            //新增一条用户质押记录
            DappAchieve dappAchieve = new DappAchieve();
            dappAchieve.setMemberId(memberId);
            dappAchieve.setPrice(transferDto.getPrice());
            dappAchieve.setAmount(amount);
            BigDecimal achieveReleasePercent = new BigDecimal("0.01").multiply(
                    new BigDecimal(redisUtils.getString(DataDicEnum.GFA_ACHIEVE_RELEASE.getValue())).setScale(2,BigDecimal.ROUND_DOWN)
@@ -328,7 +357,14 @@
    @Override
    public IPage<DappAchieve> dappAchieveInPage(DappAchieve dappAchieve, QueryRequest request) {
        Page<DappAchieve> page = new Page<>(request.getPageNum(), request.getPageSize());
        return dappAchieveMapper.selectInPage(page, dappAchieve);
        IPage<DappAchieve> dappAchieveIPage = dappAchieveMapper.selectInPage(page, dappAchieve);
        List<DappAchieve> records = dappAchieveIPage.getRecords();
        if(CollUtil.isNotEmpty(records)){
            for(DappAchieve dappAchieve1 : records){
                dappAchieve1.setUsdtAmount(dappAchieve1.getAmount().multiply(dappAchieve1.getPrice()).setScale(2,BigDecimal.ROUND_DOWN));
            }
        }
        return dappAchieveIPage;
    }
    @Override
@@ -356,8 +392,11 @@
            }
            flowType = FlowTypeEnum.DAI_BI_OUT.getValue();
            flowDes = FlowTypeEnum.DAI_BI_OUT.getDescrition();
            dappMemberEntity.setBalance(balance.subtract(amount).setScale(2,BigDecimal.ROUND_DOWN));
            dappMemberDao.updateBalanceWithVersion(dappMemberEntity);
        }else{
            if(new BigDecimal("100").compareTo(amount) > 0){
            if(new BigDecimal("1").compareTo(amount) > 0){
                throw new FebsException("最小数量为100");
            }
            if(usdtBalance.compareTo(amount) < 0){
@@ -365,6 +404,9 @@
            }
            flowType = FlowTypeEnum.USDT_OUT.getValue();
            flowDes = FlowTypeEnum.USDT_OUT.getDescrition();
            dappMemberEntity.setUsdtBalance(usdtBalance.subtract(amount).setScale(2,BigDecimal.ROUND_DOWN));
            dappMemberDao.updateUsdtBalanceWithVersion(dappMemberEntity);
        }
        DappFundFlowEntity fundFlowTuiJian = new DappFundFlowEntity(
@@ -377,9 +419,9 @@
                dappMemberEntity.getAddress());
        dappFundFlowDao.insert(fundFlowTuiJian);
        dappMemberEntity.setBalance(balance.subtract(amount).setScale(2,BigDecimal.ROUND_DOWN));
        dappMemberEntity.setUsdtBalance(usdtBalance.subtract(amount).setScale(2,BigDecimal.ROUND_DOWN));
        dappMemberDao.updateBalanceAndUsdtBalanceWithVersion(dappMemberEntity);
//        dappMemberEntity.setBalance(balance.subtract(amount).setScale(2,BigDecimal.ROUND_DOWN));
//        dappMemberEntity.setUsdtBalance(usdtBalance.subtract(amount).setScale(2,BigDecimal.ROUND_DOWN));
//        dappMemberDao.updateBalanceAndUsdtBalanceWithVersion(dappMemberEntity);
        return new FebsResponse().success();
    }