xiaoyong931011
2023-06-02 1c60c0f2ab36bce52690451442399d5b113eb0e4
src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java
@@ -454,7 +454,7 @@
        coinACntDic.setValue(coinACnt.toString());
        dataDictionaryCustomMapper.updateById(coinACntDic);
        coinAPrice = coinAUsdtCnt.divide(coinACnt,8,BigDecimal.ROUND_DOWN);
        coinAPrice = coinAUsdtCnt.divide(coinACnt,12,BigDecimal.ROUND_DOWN);
        aCoinPriceDic.setValue(coinAPrice.toString());
        dataDictionaryCustomMapper.updateById(aCoinPriceDic);
@@ -701,18 +701,18 @@
                BigDecimal ausdPrice = new BigDecimal(ausdPriceDic.getValue());
                BigDecimal ausdAmountNeed = ausdPercentUsdt.divide(ausdPrice);
                if(BigDecimal.ZERO.compareTo(ausdAmount) >= 0){
                    throw new FebsException("AUSD数量不足");
                    throw new FebsException("AUSDT数量不足");
                }
                if(ausdAmountNeed.compareTo(ausdAmount) > 0){
                    throw new FebsException("AUSD数量不足");
                    throw new FebsException("AUSDT数量不足");
                }
                /**
                 * 出局复投要求等于戓大于自己上次投资金额
                 */
                BigDecimal maxAmount = dappChargeUsdtMapper.selectByMaxAmountMemberId(member.getId());
                if(maxAmount.compareTo(transferADto.getAmount()) > 0){
                    throw new FebsException("投资金额不能小于"+maxAmount.setScale(4,BigDecimal.ROUND_DOWN));
                }
//                BigDecimal maxAmount = dappChargeUsdtMapper.selectByMaxAmountMemberId(member.getId());
//                if(maxAmount.compareTo(transferADto.getAmount()) > 0){
//                    throw new FebsException("投资金额不能小于"+maxAmount.setScale(4,BigDecimal.ROUND_DOWN));
//                }
                //生成一条进行中的入金资金流水记录
                DappFundFlowEntity fundFlow = new DappFundFlowEntity(
                        member.getId(),
@@ -760,7 +760,6 @@
                flow.setFromHash(transferADto.getTxHash());
                flow.setStatus(DappFundFlowEntity.WITHDRAW_STATUS_AGREE);
                dappFundFlowDao.updateById(flow);
                dappMemberDao.updateMemberActiveStatus(1,member.getId());
                /**
                 * 发送消息处理返利逻辑
                 */
@@ -978,4 +977,131 @@
        IPage<DappFundFlowVo> records = dappFundFlowDao.selectVoInPage(page, dappFundFlowEntity);
        return records.getRecords();
    }
    @Override
    public void roundCoin(RoundCoinDto roundCoinDto) {
        DappMemberEntity member = LoginUserUtil.getAppUser();
        DappMemberEntity dappMemberEntity = dappMemberDao.selectById(member.getId());
        String address = roundCoinDto.getAddress();
        DappMemberEntity memberParent = dappMemberDao.selectByAddress(address, null);
        if(ObjectUtil.isEmpty(memberParent)){
            throw new FebsException("请输入正确的地址");
        }
        BigDecimal coinCnt = roundCoinDto.getCoinCnt();
        if(BigDecimal.ZERO.compareTo(coinCnt) >= 0){
            throw new FebsException("输入正确的数量");
        }
        DappWalletCoinEntity dappWalletCoinEntity = dappWalletCoinDao.selectByMemberId(dappMemberEntity.getId());
        BigDecimal availableAmount = dappWalletCoinEntity.getAvailableAmount();
        if(availableAmount.compareTo(coinCnt) < 0){
            throw new FebsException("数量不足");
        }
        //减少闪兑钱包
        this.updateWalletCoinWithLock(coinCnt,dappMemberEntity.getId(),2);
        //插入资产闪对的流水
        DappFundFlowEntity aCoinCntFlow = new DappFundFlowEntity(
                dappMemberEntity.getId(),
                coinCnt.negate(),
                FundFlowEnum.ANDAO_MEMBER_TO_MENBER.getCode(),
                2,
                BigDecimal.ZERO);
        dappFundFlowDao.insert(aCoinCntFlow);
        //闪对钱包20% 手续费(扣币)
        DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                PoolEnum.ANDAO_MEMBER_TO_MENBER_PERCENT.getType(),
                PoolEnum.ANDAO_MEMBER_TO_MENBER_PERCENT.getCode());
        BigDecimal feePercent = new BigDecimal(StrUtil.isEmpty(dic.getValue()) ? "0.2" : dic.getValue());
        //手续费
        BigDecimal feeCnt = coinCnt.multiply(feePercent).setScale(4,BigDecimal.ROUND_DOWN);
        //闪对钱包获取的
        BigDecimal aCoinCntReal = coinCnt.subtract(feeCnt).setScale(4, BigDecimal.ROUND_DOWN);
        //增加闪对钱包
        this.updateWalletCoinWithLock(aCoinCntReal,memberParent.getId(),1);
        //插入资产闪对的流水
        DappFundFlowEntity dappFundFlowEntity = new DappFundFlowEntity(
                memberParent.getId(),
                aCoinCntReal,
                FundFlowEnum.ANDAO_MEMBER_TO_MENBER.getCode(),
                2,
                BigDecimal.ZERO);
        dappFundFlowDao.insert(dappFundFlowEntity);
        //金本位底池数量
        DataDictionaryCustom coinAUsdtPriceDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                PoolEnum.COIN_A_USDT_PRICE.getType(),
                PoolEnum.COIN_A_USDT_PRICE.getCode()
        );
        BigDecimal coinAUsdtCnt = new BigDecimal(coinAUsdtPriceDic.getValue());
        //币本位底池数量
        DataDictionaryCustom coinACntDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                PoolEnum.COIN_A_CNT.getType(),
                PoolEnum.COIN_A_CNT.getCode()
        );
        BigDecimal coinACnt = new BigDecimal(coinACntDic.getValue());
        coinACnt = coinACnt.subtract(feeCnt).setScale(4,BigDecimal.ROUND_DOWN);
        coinACntDic.setValue(coinACnt.toString());
        dataDictionaryCustomMapper.updateById(coinACntDic);
        DataDictionaryCustom aCoinPriceDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                PoolEnum.COIN_A_PRICE.getType(),
                PoolEnum.COIN_A_PRICE.getCode()
        );
        BigDecimal coinAPrice = new BigDecimal(aCoinPriceDic.getValue());
        coinAPrice = coinAUsdtCnt.divide(coinACnt,12,BigDecimal.ROUND_DOWN);
        aCoinPriceDic.setValue(coinAPrice.toString());
        dataDictionaryCustomMapper.updateById(aCoinPriceDic);
        chainProducer.sendAntKLineMsg(0);
    }
    @Override
    public void roundCoinAusdt(RoundCoinDto roundCoinDto) {
        DappMemberEntity member = LoginUserUtil.getAppUser();
        DappMemberEntity dappMemberEntity = dappMemberDao.selectById(member.getId());
        String address = roundCoinDto.getAddress();
        DappMemberEntity memberParent = dappMemberDao.selectByAddress(address, null);
        if(ObjectUtil.isEmpty(memberParent)){
            throw new FebsException("请输入正确的地址");
        }
        BigDecimal coinCnt = roundCoinDto.getCoinCnt();
        if(BigDecimal.ZERO.compareTo(coinCnt) >= 0){
            throw new FebsException("输入正确的数量");
        }
        DappUsdtPerkEntity dappUsdtPerkEntity = dappUsdtPerkEntityMapper.selectByMemberId(dappMemberEntity.getId());
        BigDecimal availableAmount = dappUsdtPerkEntity.getAusdAmount();
        if(availableAmount.compareTo(coinCnt) < 0){
            throw new FebsException("数量不足");
        }
        dappUsdtPerkEntity.setAusdAmount(availableAmount.subtract(coinCnt));
        dappUsdtPerkEntityMapper.updateById(dappUsdtPerkEntity);
        //插入资产闪对的流水
        DappFundFlowEntity aCoinCntFlow = new DappFundFlowEntity(
                dappMemberEntity.getId(),
                coinCnt.negate(),
                FundFlowEnum.AUSDT_MEMBER_TO_MENBER.getCode(),
                2,
                BigDecimal.ZERO);
        dappFundFlowDao.insert(aCoinCntFlow);
        DappUsdtPerkEntity parentEntity = dappUsdtPerkEntityMapper.selectByMemberId(memberParent.getId());
        BigDecimal availableAmountParent = parentEntity.getAusdAmount();
        parentEntity.setAusdAmount(availableAmountParent.add(coinCnt));
        dappUsdtPerkEntityMapper.updateById(parentEntity);
        //插入资产闪对的流水
        DappFundFlowEntity aCoinCntFlowParent = new DappFundFlowEntity(
                memberParent.getId(),
                coinCnt,
                FundFlowEnum.AUSDT_MEMBER_TO_MENBER.getCode(),
                2,
                BigDecimal.ZERO);
        dappFundFlowDao.insert(aCoinCntFlowParent);
    }
}