xiaoyong931011
2022-11-30 b603c6cfda6ff46e09310d724d0b7374db12496b
20221124
8 files modified
3 files added
100 ■■■■■ changed files
lib/abi-0.4.0.jar patch | view | raw | blame | history
lib/client-0.4.0.jar patch | view | raw | blame | history
lib/utils-0.4.0.jar patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/service/DappSystemService.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java 41 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java 18 ●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/rabbit/QueueConstants.java 1 ●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/rabbit/QueueEnum.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/rabbit/RabbitConfiguration.java 19 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/rabbit/consumer/ChainConsumer.java 8 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/rabbit/producer/ChainProducer.java 9 ●●●●● patch | view | raw | blame | history
lib/abi-0.4.0.jar
Binary files differ
lib/client-0.4.0.jar
Binary files differ
lib/utils-0.4.0.jar
Binary files differ
src/main/java/cc/mrbird/febs/dapp/service/DappSystemService.java
@@ -28,4 +28,6 @@
    void levelProfit(Long id);
    //计算是否有人出局
    void memberOut(Long id);
    //转账拨币
    void bnbTransfer(Long id);
}
src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java
@@ -52,6 +52,7 @@
    private final DappWalletService dappWalletService;
    private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
    private final DappSystemProfitDao dappSystemProfitDao;
    private final ChainProducer chainProducer;
    @Override
@@ -338,16 +339,20 @@
                BigDecimal memberLevelProfit = levelProfitTotal.multiply(profit).multiply(memberLevel);
                DappFundFlowEntity fundFlow = new DappFundFlowEntity(refererMember.getId(), memberLevelProfit, 4, 2, BigDecimal.ZERO,null,dappSystemProfit.getId());
                DappFundFlowEntity fundFlow = new DappFundFlowEntity(refererMember.getId(), memberLevelProfit, 4, 1, BigDecimal.ZERO,null,dappSystemProfit.getId());
                dappFundFlowDao.insert(fundFlow);
                //发送转币消息
                chainProducer.sendBnbTransferMsg(fundFlow.getId());
                systemProfitTotal = systemProfitTotal.add(memberLevelProfit);
            }
        }
        //如果还有剩余给技术方
        if(levelProfitTotal.compareTo(systemProfitTotal) > 0){
            BigDecimal avaProfit = levelProfitTotal.subtract(systemProfit);
            DappFundFlowEntity fundFlow = new DappFundFlowEntity(memberId, avaProfit, 5, 2, BigDecimal.ZERO,null,dappSystemProfit.getId());
            DappFundFlowEntity fundFlow = new DappFundFlowEntity(memberId, avaProfit, 5, 1, BigDecimal.ZERO,null,dappSystemProfit.getId());
            dappFundFlowDao.insert(fundFlow);
            //发送转币消息
            chainProducer.sendBnbTransferMsg(fundFlow.getId());
        }
    }
@@ -401,14 +406,16 @@
        dappSystemProfitDao.updateById(dappSystemProfitNow);
        //todo 直接拿走0.95ge
        DappFundFlowEntity fundFlowOut = new DappFundFlowEntity(dappSystemProfitNow.getMemberId(), new BigDecimal(0.95), 7, 2, BigDecimal.ZERO, null,dappSystemProfitNow.getId());
        DappFundFlowEntity fundFlowOut = new DappFundFlowEntity(dappSystemProfitNow.getMemberId(), new BigDecimal(0.95), 7, 1, BigDecimal.ZERO, null,dappSystemProfitNow.getId());
        dappFundFlowDao.insert(fundFlowOut);
        //发送转币消息
        chainProducer.sendBnbTransferMsg(fundFlowOut.getId());
        //复投 成功{type: 1, txHash: result.transactionHash, id: res.data, flag: 'success', buyType: 2}
        DataDictionaryCustom investAmountSet = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.INVEST_AMOUNT.getType(), DataDictionaryEnum.INVEST_AMOUNT.getCode());
        BigDecimal investAmount = new BigDecimal(investAmountSet.getValue());
        //todo 直接运行转账
        String txHash = "复投";
        DappFundFlowEntity fundFlow = new DappFundFlowEntity(dappSystemProfitNow.getMemberId(), investAmount, 6, 2, BigDecimal.ZERO, txHash);
        DappFundFlowEntity fundFlow = new DappFundFlowEntity(dappSystemProfitNow.getMemberId(), investAmount, 6, 1, BigDecimal.ZERO, txHash);
        dappFundFlowDao.insert(fundFlow);
        TransferDto transferDto = new TransferDto();
@@ -421,6 +428,32 @@
        dappWalletService.transferAgain(transferDto);
    }
    @Override
    public void bnbTransfer(Long id) {
        //获取对应的流水记录
        DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectById(id);
        if(DappFundFlowEntity.WITHDRAW_STATUS_AGREE == dappFundFlowEntity.getStatus()){
            return;
        }
        //金额
        BigDecimal amount = dappFundFlowEntity.getAmount();
        Long memberId = dappFundFlowEntity.getMemberId();
        DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberId);
        if(ObjectUtil.isEmpty(dappMemberEntity)){
            return;
        }
        //目标地址
        String address = dappMemberEntity.getAddress();
        String hash = ChainService.getInstance(ChainEnum.BSC_USDT.name()).transfer(address, amount);
        if(StrUtil.isEmpty(hash)){
            return;
        }
        dappFundFlowEntity.setToHash(hash);
        dappFundFlowEntity.setStatus(DappFundFlowEntity.WITHDRAW_STATUS_AGREE);
        dappFundFlowDao.updateById(dappFundFlowEntity);
    }
    public static void main(String[] args) {
        String refererIds = "1,2,3,4,5," +
                            "6,7,8,9,10," +
src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java
@@ -180,13 +180,16 @@
                DappFundFlowEntity flow = dappFundFlowDao.selectById(transferDto.getId());
                flow.setFromHash(transferDto.getTxHash());
                flow.setSystemProfitId(dappSystemProfit.getId());
                flow.setStatus(DappFundFlowEntity.WITHDRAW_STATUS_AGREE);
                dappFundFlowDao.updateById(flow);
                //直接拿走0.05个BNB放入技术方
                DataDictionaryCustom systemProfit = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.SYSTEM_PROFIT.getType(), DataDictionaryEnum.SYSTEM_PROFIT.getCode());
                String systemProfitStr = StrUtil.isEmpty(systemProfit.getValue()) ? "0.05" : systemProfit.getValue();
                DappFundFlowEntity systemProfitFlow = new DappFundFlowEntity(member.getId(), new BigDecimal(systemProfitStr), 2, 2, BigDecimal.ZERO, transferDto.getTxHash(),dappSystemProfit.getId());
                DappFundFlowEntity systemProfitFlow = new DappFundFlowEntity(member.getId(), new BigDecimal(systemProfitStr), 2, 1, BigDecimal.ZERO, transferDto.getTxHash(),dappSystemProfit.getId());
                dappFundFlowDao.insert(systemProfitFlow);
                //发送转币消息
                chainProducer.sendBnbTransferMsg(systemProfitFlow.getId());
                //直接返利30%给直接上级
                DappMemberEntity dappMemberEntity = dappMemberDao.selectById(member.getId());
                String refererId = dappMemberEntity.getRefererId();
@@ -196,8 +199,10 @@
                BigDecimal directProfitStr = new BigDecimal(StrUtil.isEmpty(directProfitSet.getValue()) ? "0.3" : directProfitSet.getValue());
                BigDecimal directProfit = (transferDto.getAmount().subtract(new BigDecimal(systemProfitStr))).multiply(directProfitStr).setScale(BigDecimal.ROUND_DOWN, 2);
                
                DappFundFlowEntity fundFlow = new DappFundFlowEntity(refererMember.getId(), directProfit, 3, 2, BigDecimal.ZERO, transferDto.getTxHash(),dappSystemProfit.getId());
                DappFundFlowEntity fundFlow = new DappFundFlowEntity(refererMember.getId(), directProfit, 3, 1, BigDecimal.ZERO, transferDto.getTxHash(),dappSystemProfit.getId());
                dappFundFlowDao.insert(fundFlow);
                //发送转币消息
                chainProducer.sendBnbTransferMsg(fundFlow.getId());
                //层级奖励30%
                chainProducer.sendLevelProfitMsg(dappSystemProfit.getId());
                //发送一个消息,计算当前是否有人可以出局
@@ -388,13 +393,16 @@
            DappFundFlowEntity flow = dappFundFlowDao.selectById(transferDto.getId());
            flow.setFromHash(transferDto.getTxHash());
            flow.setSystemProfitId(dappSystemProfit.getId());
            flow.setStatus(DappFundFlowEntity.WITHDRAW_STATUS_AGREE);
            dappFundFlowDao.updateById(flow);
            //直接拿走0.05个BNB放入技术方
            DataDictionaryCustom systemProfit = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.SYSTEM_PROFIT.getType(), DataDictionaryEnum.SYSTEM_PROFIT.getCode());
            String systemProfitStr = StrUtil.isEmpty(systemProfit.getValue()) ? "0.05" : systemProfit.getValue();
            DappFundFlowEntity systemProfitFlow = new DappFundFlowEntity(member.getId(), new BigDecimal(systemProfitStr), 2, 2, BigDecimal.ZERO, transferDto.getTxHash(),dappSystemProfit.getId());
            DappFundFlowEntity systemProfitFlow = new DappFundFlowEntity(member.getId(), new BigDecimal(systemProfitStr), 2, 1, BigDecimal.ZERO, transferDto.getTxHash(),dappSystemProfit.getId());
            dappFundFlowDao.insert(systemProfitFlow);
            //发送转币消息
            chainProducer.sendBnbTransferMsg(systemProfitFlow.getId());
            //直接返利30%给直接上级
            DappMemberEntity dappMemberEntity = dappMemberDao.selectById(member.getId());
            String refererId = dappMemberEntity.getRefererId();
@@ -404,8 +412,10 @@
            BigDecimal directProfitStr = new BigDecimal(StrUtil.isEmpty(directProfitSet.getValue()) ? "0.3" : directProfitSet.getValue());
            BigDecimal directProfit = (transferDto.getAmount().subtract(new BigDecimal(systemProfitStr))).multiply(directProfitStr).setScale(BigDecimal.ROUND_DOWN, 2);
            DappFundFlowEntity fundFlow = new DappFundFlowEntity(refererMember.getId(), directProfit, 3, 2, BigDecimal.ZERO, transferDto.getTxHash(),dappSystemProfit.getId());
            DappFundFlowEntity fundFlow = new DappFundFlowEntity(refererMember.getId(), directProfit, 3, 1, BigDecimal.ZERO, transferDto.getTxHash(),dappSystemProfit.getId());
            dappFundFlowDao.insert(fundFlow);
            //发送转币消息
            chainProducer.sendBnbTransferMsg(fundFlow.getId());
            //层级奖励30%
            chainProducer.sendLevelProfitMsg(dappSystemProfit.getId());
            //发送一个消息,计算当前是否有人可以出局
src/main/java/cc/mrbird/febs/rabbit/QueueConstants.java
@@ -6,6 +6,7 @@
 **/
public class QueueConstants {
    public static final String QUEUE_BNB_TRANSFER = "queue_bnb_transfer";
    public static final String QUEUE_MEMBER_OUT = "queue_bnb_member_out";
    public static final String QUEUE_LEVEL_PROFIT = "queue_bnb_level_profit_transfer";
src/main/java/cc/mrbird/febs/rabbit/QueueEnum.java
@@ -5,6 +5,8 @@
@Getter
public enum QueueEnum {
    //转账拨币
    BNB_TRANSFER("exchange_bnb_transfer", "route_key_bnb_transfer", "queue_bnb_transfer"),
    //计算是否有人出局
    MEMBER_OUT("exchange_bnb_member_out", "route_key_bnb_member_out", "queue_bnb_member_out"),
    //层级奖励
src/main/java/cc/mrbird/febs/rabbit/RabbitConfiguration.java
@@ -139,4 +139,23 @@
        return BindingBuilder.bind(memberOutQueue()).to(memberOutExchange()).with(QueueEnum.MEMBER_OUT.getRoute());
    }
    // === 计算是否有人出局 end ===
    // === 转账拨币 start ===
    @Bean
    public DirectExchange bnbTransferExchange() {
        return new DirectExchange(QueueEnum.BNB_TRANSFER.getExchange());
    }
    @Bean
    public Queue bnbTransferQueue() {
        return new Queue(QueueEnum.BNB_TRANSFER.getQueue());
    }
    @Bean
    public Binding bnbTransferBind() {
        return BindingBuilder.bind(bnbTransferQueue()).to(bnbTransferExchange()).with(QueueEnum.BNB_TRANSFER.getRoute());
    }
    // === 转账拨币 end ===
}
src/main/java/cc/mrbird/febs/rabbit/consumer/ChainConsumer.java
@@ -60,4 +60,12 @@
    public void memberOut(Long id) {
        dappSystemService.memberOut(id);
    }
    /**转账拨币
     * @param id
     */
    @RabbitListener(queues = QueueConstants.QUEUE_BNB_TRANSFER)
    public void bnbTransfer(Long id) {
        dappSystemService.bnbTransfer(id);
    }
}
src/main/java/cc/mrbird/febs/rabbit/producer/ChainProducer.java
@@ -82,4 +82,13 @@
        CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
        rabbitTemplate.convertAndSend(QueueEnum.LEVEL_PROFIT.getExchange(), QueueEnum.LEVEL_PROFIT.getRoute(), id, correlationData);
    }
    /**
     * 转账拨币
     */
    public void sendBnbTransferMsg(Long id) {
        log.info("转账拨币:{}", id);
        CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
        rabbitTemplate.convertAndSend(QueueEnum.BNB_TRANSFER.getExchange(), QueueEnum.BNB_TRANSFER.getRoute(), id, correlationData);
    }
}