| | |
| | | private Integer state; |
| | | public static final int STATE_IN = 1; |
| | | public static final int STATE_OUT = 2; |
| | | //层级奖励是否产生 1:否 2:是 |
| | | private Integer levelProfit; |
| | | public static final int ENUM_NO = 1; |
| | | public static final int ENUM_YES = 2; |
| | | |
| | | public DappSystemProfit(Long memberId, BigDecimal amount) { |
| | | this.memberId = memberId; |
| | |
| | | public BigDecimal getProfit(int memberCnt) { |
| | | for (LevelProfitEnum value : LevelProfitEnum.values()) { |
| | | if (value.memberCnt == memberCnt) { |
| | | return new BigDecimal(value.profit).multiply(new BigDecimal(0.01)).setScale(BigDecimal.ROUND_DOWN, 2); |
| | | return new BigDecimal(value.profit).multiply(new BigDecimal(0.01)).setScale(2,BigDecimal.ROUND_DOWN); |
| | | } |
| | | } |
| | | return BigDecimal.ZERO; |
| | |
| | | DappSystemProfit selectSystemProfitByState(@Param("state") int stateOut); |
| | | |
| | | DappSystemProfit selectByIdForUpdate(@Param("id") Long id,@Param("state") int stateOut); |
| | | |
| | | void updateLevelProfitById(@Param("levelProfit") int levelProfit,@Param("id")Long id); |
| | | |
| | | void updateStateById(@Param("state") int stateOut,@Param("id")Long id); |
| | | } |
| | |
| | | if(ObjectUtil.isEmpty(dappSystemProfit)){ |
| | | return; |
| | | } |
| | | Integer levelProfitState = dappSystemProfit.getLevelProfit(); |
| | | |
| | | if(DappSystemProfit.ENUM_YES == levelProfitState){ |
| | | return; |
| | | } |
| | | Long memberId = dappSystemProfit.getMemberId(); |
| | | //获取用户的上级用户信息 |
| | | DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberId); |
| | |
| | | //返回十层 |
| | | List<String> refererIdList = StrUtil.split(refererIds, ','); |
| | | //i:计数层数,同时i也为对应层数应推广的人数,当达到对应的直推人数时,才能获取对应层级奖励 |
| | | for(int i = 0;i < 10; i++){ |
| | | if(CollUtil.isEmpty(refererIdList)){ |
| | | return; |
| | | } |
| | | //层级奖励最大循环次数 |
| | | int maxLevel = 10; |
| | | if(maxLevel > refererIdList.size()){ |
| | | maxLevel = refererIdList.size(); |
| | | } |
| | | for(int i = 0;i < maxLevel; i++){ |
| | | if(systemProfitTotal.compareTo(levelProfitTotal) < 0){ |
| | | String inviteId = refererIdList.get(i); |
| | | //获取每层用户的直推人数,判断能否获得这个层级的层级奖励 |
| | |
| | | continue; |
| | | } |
| | | //获取对应层级奖励 |
| | | BigDecimal profit = LevelProfitEnum.YI.getProfit(i); |
| | | BigDecimal profit = LevelProfitEnum.YI.getProfit(i+1); |
| | | String accountType = refererMember.getAccountType(); |
| | | //根据会员的等级类型,获取对应的百分比收益 |
| | | DataDictionaryCustom memberLevelSet = dataDictionaryCustomMapper.selectDicDataByTypeAndCode("MEMBER_LEVEL", accountType); |
| | |
| | | //发送转币消息 |
| | | chainProducer.sendBnbTransferMsg(fundFlow.getId()); |
| | | } |
| | | |
| | | dappSystemProfitDao.updateLevelProfitById(DappSystemProfit.ENUM_YES,dappSystemProfit.getId()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | redisUtils.set(redisKey,realCount,0L); |
| | | |
| | | DappSystemProfit dappSystemProfitNow = dappSystemProfitDao.selectByIdForUpdate(dappSystemProfit.getId(),DappSystemProfit.STATE_IN); |
| | | dappSystemProfitNow.setState(DappSystemProfit.STATE_OUT); |
| | | dappSystemProfitDao.updateById(dappSystemProfitNow); |
| | | dappSystemProfitDao.updateStateById(DappSystemProfit.STATE_OUT,dappSystemProfitNow.getId()); |
| | | |
| | | //todo 直接拿走0.95ge |
| | | DappFundFlowEntity fundFlowOut = new DappFundFlowEntity(dappSystemProfitNow.getMemberId(), new BigDecimal(0.95), 7, 1, BigDecimal.ZERO, null,dappSystemProfitNow.getId()); |
| | |
| | | transferDto.setBuyType(2); |
| | | transferDto.setId(fundFlow.getId()); |
| | | transferDto.setFlag("success"); |
| | | transferDto.setAmount(investAmount); |
| | | transferDto.setMemberId(dappSystemProfitNow.getMemberId()); |
| | | dappWalletService.transferAgain(transferDto); |
| | | } |
| | |
| | | log.info("{}",id); |
| | | //获取对应的流水记录 |
| | | DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectById(id); |
| | | if(ObjectUtil.isEmpty(dappFundFlowEntity)){ |
| | | return; |
| | | } |
| | | if(DappFundFlowEntity.WITHDRAW_STATUS_AGREE == dappFundFlowEntity.getStatus()){ |
| | | return; |
| | | } |
| | |
| | | } |
| | | |
| | | if ("success".equals(transferDto.getFlag())) { |
| | | DappFundFlowEntity flow = dappFundFlowDao.selectById(transferDto.getId()); |
| | | if(DappFundFlowEntity.WITHDRAW_STATUS_AGREE == flow.getStatus()){ |
| | | return null; |
| | | } |
| | | //插入一条会员入列记录,即加入动能队列 |
| | | DappSystemProfit dappSystemProfit = new DappSystemProfit(member.getId(), transferDto.getAmount()); |
| | | dappSystemProfitDao.insert(dappSystemProfit); |
| | | //升级成为Agent |
| | | dappMemberDao.updateMemberAccountType(DataDictionaryEnum.AGENT.getCode(),member.getId()); |
| | | |
| | | DappFundFlowEntity flow = dappFundFlowDao.selectById(transferDto.getId()); |
| | | flow.setFromHash(transferDto.getTxHash()); |
| | | flow.setSystemProfitId(dappSystemProfit.getId()); |
| | | flow.setStatus(DappFundFlowEntity.WITHDRAW_STATUS_AGREE); |
| | | dappFundFlowDao.updateById(flow); |
| | | //升级成为Agent |
| | | dappMemberDao.updateMemberAccountType(DataDictionaryEnum.AGENT.getCode(),member.getId()); |
| | | |
| | | //直接拿走0.05个BNB放入技术方 |
| | | DataDictionaryCustom systemProfit = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.SYSTEM_PROFIT.getType(), DataDictionaryEnum.SYSTEM_PROFIT.getCode()); |
| | |
| | | |
| | | DataDictionaryCustom directProfitSet = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.DIRECT_PROFIT.getType(), DataDictionaryEnum.DIRECT_PROFIT.getCode()); |
| | | 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); |
| | | BigDecimal subtract = transferDto.getAmount().subtract(new BigDecimal(systemProfitStr)); |
| | | BigDecimal directProfit = subtract.multiply(directProfitStr).setScale(2,BigDecimal.ROUND_DOWN); |
| | | |
| | | DappFundFlowEntity fundFlow = new DappFundFlowEntity(refererMember.getId(), directProfit, 3, 1, BigDecimal.ZERO, transferDto.getTxHash(),dappSystemProfit.getId()); |
| | | dappFundFlowDao.insert(fundFlow); |
| | |
| | | |
| | | DataDictionaryCustom directProfitSet = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.DIRECT_PROFIT.getType(), DataDictionaryEnum.DIRECT_PROFIT.getCode()); |
| | | 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); |
| | | BigDecimal directProfit = (transferDto.getAmount().subtract(new BigDecimal(systemProfitStr))).multiply(directProfitStr).setScale(2,BigDecimal.ROUND_DOWN); |
| | | |
| | | DappFundFlowEntity fundFlow = new DappFundFlowEntity(refererMember.getId(), directProfit, 3, 1, BigDecimal.ZERO, transferDto.getTxHash(),dappSystemProfit.getId()); |
| | | dappFundFlowDao.insert(fundFlow); |
| | |
| | | |
| | | import cc.mrbird.febs.dapp.service.DappSystemService; |
| | | import cc.mrbird.febs.rabbit.QueueConstants; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.rabbitmq.client.Channel; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.amqp.core.Message; |
| | |
| | | @Autowired |
| | | private DappSystemService dappSystemService; |
| | | |
| | | @RabbitListener(queues = QueueConstants.ACHIEVE_TREE) |
| | | public void achieveTree(String id) { |
| | | log.info("收到业绩树消息"); |
| | | dappSystemService.achieveTree(Long.parseLong(id)); |
| | | } |
| | | |
| | | /** |
| | | * 生产者在tfc应用 |
| | | * @param data |
| | | */ |
| | | @RabbitListener(queues = QueueConstants.TFC_NEW_PRICE) |
| | | public void tfcNewPrice(String data) { |
| | | // dappSystemService.tfcNewPrice(data); |
| | | } |
| | | |
| | | /** |
| | | * @param data |
| | | */ |
| | | @RabbitListener(queues = QueueConstants.DISTRIB_PROFIT) |
| | | public void feeDistribute(String data) { |
| | | dappSystemService.feeDistribute(data); |
| | | } |
| | | // @RabbitListener(queues = QueueConstants.ACHIEVE_TREE) |
| | | // public void achieveTree(String id) { |
| | | // log.info("收到业绩树消息"); |
| | | // dappSystemService.achieveTree(Long.parseLong(id)); |
| | | // } |
| | | // |
| | | // /** |
| | | // * 生产者在tfc应用 |
| | | // * @param data |
| | | // */ |
| | | // @RabbitListener(queues = QueueConstants.TFC_NEW_PRICE) |
| | | // public void tfcNewPrice(String data) { |
| | | //// dappSystemService.tfcNewPrice(data); |
| | | // } |
| | | // |
| | | // /** |
| | | // * @param data |
| | | // */ |
| | | // @RabbitListener(queues = QueueConstants.DISTRIB_PROFIT) |
| | | // public void feeDistribute(String data) { |
| | | // dappSystemService.feeDistribute(data); |
| | | // } |
| | | |
| | | /**层级奖励分发消息 |
| | | * @param id |
| | | */ |
| | | @RabbitListener(queues = QueueConstants.QUEUE_LEVEL_PROFIT) |
| | | public void levelProfit(Long id) { |
| | | log.info("消费层级奖励分发消息:{}", id); |
| | | dappSystemService.levelProfit(id); |
| | | } |
| | | |
| | |
| | | */ |
| | | @RabbitListener(queues = QueueConstants.QUEUE_MEMBER_OUT) |
| | | public void memberOut(Long id) { |
| | | log.info("消费计算是否有人出局:{}", id); |
| | | dappSystemService.memberOut(id); |
| | | } |
| | | |
| | |
| | | */ |
| | | @RabbitListener(queues = QueueConstants.QUEUE_BNB_TRANSFER) |
| | | public void bnbTransfer(Long id) { |
| | | log.info("消费转账拨币:{}", id); |
| | | dappSystemService.bnbTransfer(id); |
| | | } |
| | | } |
| | |
| | | * 计算是否有人出局分发消息 |
| | | */ |
| | | public void sendMemberOutMsg(Long id) { |
| | | log.info("计算是否有人出局:{}", DateUtil.now()); |
| | | log.info("计算是否有人出局:{}", id); |
| | | CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString()); |
| | | rabbitTemplate.convertAndSend(QueueEnum.LEVEL_PROFIT.getExchange(), QueueEnum.LEVEL_PROFIT.getRoute(), id, correlationData); |
| | | rabbitTemplate.convertAndSend(QueueEnum.MEMBER_OUT.getExchange(), QueueEnum.MEMBER_OUT.getRoute(), id, correlationData); |
| | | } |
| | | |
| | | /** |
| | |
| | | for update |
| | | </select> |
| | | |
| | | <update id="updateLevelProfitById"> |
| | | update dapp_system_profit |
| | | set level_Profit = #{levelProfit} |
| | | where id = #{id} |
| | | </update> |
| | | |
| | | <update id="updateStateById"> |
| | | update dapp_system_profit |
| | | set state = #{state} |
| | | where id = #{id} |
| | | </update> |
| | | |
| | | </mapper> |
| | |
| | | transferDto.setFee(BigDecimal.ZERO); |
| | | transferDto.setType(1); |
| | | transferDto.setBuyType(2); |
| | | transferDto.setMemberId(106L); |
| | | transferDto.setMemberId(119L); |
| | | Long transfer = dappWalletService.transfer(transferDto); |
| | | transferDto.setTxHash("ceshi"+ DateUtil.now()); |
| | | transferDto.setId(transfer); |
| | | transferDto.setFlag("success"); |
| | | dappWalletService.transfer(transferDto); |
| | | } |
| | | @Test |
| | |
| | | TransferDto transferDto = new TransferDto(); |
| | | transferDto.setType(1); |
| | | transferDto.setTxHash("ceshi"+ DateUtil.now()); |
| | | transferDto.setId(324L); |
| | | transferDto.setId(422L); |
| | | transferDto.setFlag("success"); |
| | | transferDto.setBuyType(2); |
| | | transferDto.setAmount(new BigDecimal(1.05)); |
| | | transferDto.setFee(BigDecimal.ZERO); |
| | | transferDto.setMemberId(106L); |
| | | transferDto.setMemberId(111L); |
| | | dappWalletService.transfer(transferDto); |
| | | } |
| | | |
| | | @Test |
| | | public void resetMatrix() { |
| | | // dappSystemService.resetMatrix(); |
| | | // dappAchieveMemberTreeDao.emptyTable(); |
| | | dappSystemService.levelProfit(9L); |
| | | dappSystemService.memberOut(9L); |
| | | } |
| | | |
| | | @Test |