| | |
| | | |
| | | import cc.mrbird.febs.common.configure.i18n.MessageSourceUtils; |
| | | import cc.mrbird.febs.common.contants.AppContants; |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cc.mrbird.febs.common.entity.QueryRequest; |
| | | import cc.mrbird.febs.common.exception.FebsException; |
| | | import cc.mrbird.febs.common.utils.FebsUtil; |
| | |
| | | import cc.mrbird.febs.dapp.dto.PriceSettingDto; |
| | | import cc.mrbird.febs.dapp.dto.TeamListDto; |
| | | import cc.mrbird.febs.dapp.entity.*; |
| | | import cc.mrbird.febs.dapp.enumerate.DataDictionaryEnum; |
| | | import cc.mrbird.febs.dapp.mapper.*; |
| | | import cc.mrbird.febs.dapp.service.DappMemberService; |
| | | import cc.mrbird.febs.dapp.vo.TeamListVo; |
| | | import cc.mrbird.febs.dapp.vo.*; |
| | | import cc.mrbird.febs.rabbit.producer.ChainProducer; |
| | | import cc.mrbird.febs.system.entity.User; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | private final RedisUtils redisUtils; |
| | | |
| | | private final DappAchieveMemberTreeDao dappAchieveMemberTreeDao; |
| | | private final DataDictionaryCustomMapper dataDictionaryCustomMapper; |
| | | private final DappSystemProfitDao dappSystemProfitDao; |
| | | private final ChainProducer chainProducer; |
| | | private final DappFundFlowDao dappFundFlowDao; |
| | | |
| | | private final DappNodeOrderMapper dappNodeOrderMapper; |
| | | private final DappMemberNodeMapper dappMemberNodeMapper; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | throw new FebsException("recommender is not exist"); |
| | | } |
| | | |
| | | List<DappMemberEntity> child = dappMemberDao.selectChildMemberDirectOrNot(connectDto.getInviteId(), 1); |
| | | if (child.size() == 6) { |
| | | throw new FebsException("Invite Code is Invalid"); |
| | | } |
| | | // List<DappMemberEntity> child = dappMemberDao.selectChildMemberDirectOrNot(connectDto.getInviteId(), 1, null); |
| | | // if (child.size() == 6) { |
| | | // throw new FebsException("Invite Code is Invalid"); |
| | | // } |
| | | } else { |
| | | connectDto.setInviteId(null); |
| | | } |
| | | member = insertMember(connectDto.getAddress(), null); |
| | | member = insertMember(connectDto.getAddress(), connectDto.getInviteId()); |
| | | //升级用户的代理等级 |
| | | // DappMemberEntity dappMemberEntity = dappMemberDao.selectMemberInfoByInviteId(connectDto.getInviteId()); |
| | | // chainProducer.sendAgentUpMsg(dappMemberEntity.getId()); |
| | | } |
| | | |
| | | String key = LoginUserUtil.getLoginKey(connectDto.getAddress(), connectDto.getNonce(), connectDto.getSign()); |
| | | redisUtils.set(connectDto.getAddress(), member); |
| | | redisUtils.hset(AppContants.REDIS_KEY_MEMBER_INFO, connectDto.getAddress(), member); |
| | | |
| | | Map<Object, Object> keys = redisUtils.hmget(AppContants.REDIS_KEY_SIGN); |
| | | if (keys == null) { |
| | |
| | | if (currentUser.getDeptId() == null) { |
| | | member.setCurrentUser(currentUser.getUserId()); |
| | | } |
| | | return dappMemberDao.selectInPage(member, page); |
| | | IPage<DappMemberEntity> dappMemberEntityIPage = dappMemberDao.selectInPage(member, page); |
| | | List<DappMemberEntity> records = dappMemberEntityIPage.getRecords(); |
| | | if(CollUtil.isNotEmpty(records)){ |
| | | for(DappMemberEntity memberEntity : records){ |
| | | Long memberId = memberEntity.getId(); |
| | | //直推收益 |
| | | BigDecimal directProfit = dappFundFlowDao.selectSumAmountByMemberIdAndTypeAndStatus(memberId,3,2); |
| | | memberEntity.setDirectProfit(directProfit); |
| | | //购买节点数量 |
| | | List<DappMemberNodeVo> dappMemberNodeVos = dappMemberNodeMapper.selectListByMemberId(memberId); |
| | | memberEntity.setMemberNodeCnt(CollUtil.isEmpty(dappMemberNodeVos) ? 0 : dappMemberNodeVos.size()); |
| | | |
| | | BigDecimal memberNodeSumPrice = BigDecimal.ZERO; |
| | | if(CollUtil.isNotEmpty(dappMemberNodeVos)){ |
| | | for(DappMemberNodeVo dappMemberNodeVo : dappMemberNodeVos){ |
| | | BigDecimal nodePrice = dappMemberNodeVo.getNodePrice(); |
| | | memberNodeSumPrice = memberNodeSumPrice.add(nodePrice); |
| | | } |
| | | } |
| | | memberEntity.setMemberNodeSumPrice(memberNodeSumPrice.setScale(8,BigDecimal.ROUND_DOWN)); |
| | | } |
| | | } |
| | | return dappMemberEntityIPage; |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Override |
| | | public DappMemberEntity insertMember(String address, String refererId) { |
| | | |
| | | return insertMember(address, refererId, "BSC", "normal"); |
| | | return insertMember(address, refererId, "BSC", DataDictionaryEnum.MEMBER.getCode()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | member.setChainType(chainType); |
| | | member.setAccountType(accountType); |
| | | member.setActiveStatus(2); |
| | | // member.setBalance(ChainService.getInstance(ChainEnum.BSC_TFC.name()).balanceOf(address)); |
| | | // member.setUsdtBalance(ChainService.getInstance(ChainEnum.BSC_USDT.name()).balanceOf(address)); |
| | | |
| | | dappMemberDao.insert(member); |
| | | |
| | | DappWalletCoinEntity walletCoin = new DappWalletCoinEntity(); |
| | | walletCoin.setMemberId(member.getId()); |
| | | dappWalletCoinDao.insert(walletCoin); |
| | | |
| | | DappWalletMineEntity walletMine = new DappWalletMineEntity(); |
| | | walletMine.setMemberId(member.getId()); |
| | | dappWalletMineDao.insert(walletMine); |
| | | |
| | | if (StrUtil.isEmpty(refererId)) { |
| | | refererId = "0"; |
| | |
| | | boolean flag = false; |
| | | String parentId = refererId; |
| | | String ids = ""; |
| | | String feeProfitIds = ""; |
| | | |
| | | while (!flag && StringUtils.isNotBlank(parentId)) { |
| | | if (StrUtil.isBlank(ids)) { |
| | | ids += parentId; |
| | | } else { |
| | | ids += ("," + parentId); |
| | | } |
| | | |
| | | if (StrUtil.isBlank(feeProfitIds)) { |
| | | feeProfitIds += parentId; |
| | | } else { |
| | | feeProfitIds += ("," + parentId); |
| | | } |
| | | |
| | | DappMemberEntity parentMember = dappMemberDao.selectMemberInfoByInviteId(parentId); |
| | |
| | | } |
| | | } |
| | | member.setRefererIds(ids); |
| | | member.setFeeProfitIds(feeProfitIds); |
| | | } |
| | | dappMemberDao.updateById(member); |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public TeamListVo findTeamList(TeamListDto teamListDto) { |
| | | public TeamListVo findTeamList() { |
| | | DappMemberEntity member = LoginUserUtil.getAppUser(); |
| | | |
| | | DappAchieveMemberTreeEntity topNode = dappAchieveMemberTreeDao.selectNodeByDeep(member.getId(), 1); |
| | | return buildTeamMatrix(topNode); |
| | | //如果没有加入动能即返回null |
| | | DappSystemProfit dappSystemProfit = dappSystemProfitDao.selectByMemberIdAndState(member.getId(), DappSystemProfit.STATE_IN); |
| | | if(ObjectUtil.isEmpty(dappSystemProfit)){ |
| | | return null; |
| | | } |
| | | //升级用户的代理等级 |
| | | DappMemberEntity dappMemberEntity = dappMemberDao.selectMemberInfoByInviteId(member.getRefererId()); |
| | | chainProducer.sendAgentUpMsg(dappMemberEntity.getId()); |
| | | return buildTeamMatrix(member.getId()); |
| | | } |
| | | |
| | | public TeamListVo buildTeamMatrix(DappAchieveMemberTreeEntity node) { |
| | | List<DappAchieveMemberTreeEntity> childNodes = dappAchieveMemberTreeDao.selectMatrixChildNode(node.getTopNode(), node.getTreeNode()); |
| | | @Override |
| | | public void setSystemFee(AdminSystemFeeVo adminSystemFeeVo) { |
| | | String rebatePercent = adminSystemFeeVo.getRebatePercent(); |
| | | DataDictionaryCustom rebateDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.REBATE_PERCENT.getType(), DataDictionaryEnum.REBATE_PERCENT.getCode()); |
| | | rebateDic.setValue(rebatePercent); |
| | | dataDictionaryCustomMapper.updateById(rebateDic); |
| | | |
| | | String serviceFee = adminSystemFeeVo.getServiceFee(); |
| | | DataDictionaryCustom serviceFeeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.WITHDRAW_SERVICE_FEE.getType(), DataDictionaryEnum.WITHDRAW_SERVICE_FEE.getCode()); |
| | | serviceFeeDic.setValue(serviceFee); |
| | | dataDictionaryCustomMapper.updateById(serviceFeeDic); |
| | | |
| | | String memberFee = adminSystemFeeVo.getMemberFee(); |
| | | DataDictionaryCustom memberFeeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.MEMBER_FEE.getType(), DataDictionaryEnum.MEMBER_FEE.getCode()); |
| | | memberFeeDic.setValue(memberFee); |
| | | dataDictionaryCustomMapper.updateById(memberFeeDic); |
| | | |
| | | String symbolPrice = adminSystemFeeVo.getSymbolPrice(); |
| | | DataDictionaryCustom symbolPriceDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.SYMBOL_PRICE.getType(), DataDictionaryEnum.SYMBOL_PRICE.getCode()); |
| | | symbolPriceDic.setValue(symbolPrice); |
| | | dataDictionaryCustomMapper.updateById(symbolPriceDic); |
| | | |
| | | String directProfit = adminSystemFeeVo.getDirectProfit(); |
| | | DataDictionaryCustom directProfitDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.DIRECT_PROFIT.getType(), DataDictionaryEnum.DIRECT_PROFIT.getCode()); |
| | | directProfitDic.setValue(directProfit); |
| | | dataDictionaryCustomMapper.updateById(directProfitDic); |
| | | } |
| | | |
| | | @Override |
| | | public ApiRunListInfoVo findRunListInfo() { |
| | | ApiRunListInfoVo apiRunListInfoVo = new ApiRunListInfoVo(); |
| | | //获取当前是第几轮队列 |
| | | String redisKey = "QUEUE_COUNT"; |
| | | String memberOutCount = redisUtils.getString(redisKey); |
| | | DataDictionaryCustom queueCountSet = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.QUEUE_COUNT.getType(), DataDictionaryEnum.QUEUE_COUNT.getCode()); |
| | | String queueCount = queueCountSet.getValue(); |
| | | if(StrUtil.isBlank(memberOutCount)|| !queueCount.equals(memberOutCount)){ |
| | | redisUtils.set(redisKey,queueCount,0L); |
| | | memberOutCount = queueCount; |
| | | } |
| | | //出局条件的人数 |
| | | /** |
| | | * 初始大小 5+4*0 |
| | | * 1 1,2,3,4,5 1出局 5+4*0 |
| | | * 2 2,3,4,5,1(复投),7,8,9,10 2出局 5+4*1 |
| | | * 3 3,4,5,1(复投),7,8,9,10,2(复投),12,13,14,15 3出局 5+4*2 |
| | | * 4 4,5,1(复投),7,8,9,10,2(复投),12,13,14,15,3(复投),17,18,19,20 4出局 5+4*3 |
| | | */ |
| | | Integer memberCount = Integer.parseInt(memberOutCount) * 4 + 5; |
| | | //判断当前是否符合出局条件 |
| | | QueryWrapper<DappSystemProfit> objectQueryWrapper = new QueryWrapper<>(); |
| | | objectQueryWrapper.eq("state",DappSystemProfit.STATE_IN); |
| | | //实际投资人数 |
| | | Integer selectCount = dappSystemProfitDao.selectCount(objectQueryWrapper); |
| | | int runPercentNum = memberCount - selectCount; |
| | | runPercentNum = 5-runPercentNum > 0 ? 5-runPercentNum : 1; |
| | | apiRunListInfoVo.setRunPercent(new BigDecimal(runPercentNum).multiply(new BigDecimal(0.4)).setScale(BigDecimal.ROUND_DOWN,1)); |
| | | // BigDecimal runPercent = new BigDecimal(selectCount).divide(new BigDecimal(memberCount), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)); |
| | | // apiRunListInfoVo.setRunPercent(runPercent); |
| | | //实际投资人数小于出局条件人数 |
| | | //符合则出局 实际投资人数等于出局条件人数 |
| | | DappSystemProfit dappSystemProfitIn = dappSystemProfitDao.selectSystemProfitInByState(DappSystemProfit.STATE_IN); |
| | | apiRunListInfoVo.setLuckyMemberNext(ObjectUtil.isEmpty(dappSystemProfitIn) ? 0L : dappSystemProfitIn.getId()); |
| | | DappSystemProfit dappSystemProfitOut = dappSystemProfitDao.selectSystemProfitOutByState(DappSystemProfit.STATE_OUT); |
| | | apiRunListInfoVo.setLuckyMember(ObjectUtil.isEmpty(dappSystemProfitOut) ? 0L : dappSystemProfitOut.getId()); |
| | | return apiRunListInfoVo; |
| | | } |
| | | |
| | | @Override |
| | | public IPage<AdminDappSystemProfitVo> selectSystemProfitInPage(DappSystemProfit dappSystemProfit, QueryRequest request) { |
| | | Page<AdminDappSystemProfitVo> page = new Page<>(request.getPageNum(), request.getPageSize()); |
| | | return dappSystemProfitDao.selectSystemProfitInPage(dappSystemProfit, page); |
| | | } |
| | | |
| | | @Override |
| | | public IPage<AdminSystemProfitFlowListVo> getSystemProfitFlowList(DappSystemProfit dappSystemProfit, QueryRequest request) { |
| | | Page<AdminSystemProfitFlowListVo> page = new Page<>(request.getPageNum(), request.getPageSize()); |
| | | return dappSystemProfitDao.selectSystemProfitFlowListInPage(dappSystemProfit, page); |
| | | } |
| | | |
| | | @Override |
| | | public IPage<AdminTeamInfoVo> getTeamInfo(DappMemberEntity dappMemberEntity, QueryRequest request) { |
| | | Page<AdminTeamInfoVo> page = new Page<>(request.getPageNum(), request.getPageSize()); |
| | | dappMemberEntity = this.baseMapper.selectById(dappMemberEntity.getId()); |
| | | IPage<AdminTeamInfoVo> adminTeamInfoVoIPage = this.baseMapper.findTeamInfoListInPage(page, dappMemberEntity); |
| | | List<AdminTeamInfoVo> records = adminTeamInfoVoIPage.getRecords(); |
| | | if(CollUtil.isNotEmpty(records)){ |
| | | for(AdminTeamInfoVo adminTeamInfoVo : records){ |
| | | Long memberId = adminTeamInfoVo.getId(); |
| | | List<DappMemberEntity> direct = dappMemberDao.selectChildMemberDirectOrNot(adminTeamInfoVo.getInviteId(), 1, 1); |
| | | adminTeamInfoVo.setDirectCnt(direct.size()); |
| | | DappSystemProfit dappSystemProfit = dappSystemProfitDao.selectByMemberIdAndState(memberId,DappSystemProfit.STATE_IN); |
| | | adminTeamInfoVo.setSystemProfitId(ObjectUtil.isEmpty(dappSystemProfit) ? 0L : dappSystemProfit.getId()); |
| | | BigDecimal directProfit = dappFundFlowDao.selectSumAmountByMemberIdAndTypeAndStatus(memberId,3,2); |
| | | adminTeamInfoVo.setDirectProfit(directProfit); |
| | | BigDecimal levelProfit = dappFundFlowDao.selectSumAmountByMemberIdAndTypeAndStatus(memberId,4,2); |
| | | adminTeamInfoVo.setLevelProfit(levelProfit); |
| | | BigDecimal luckyProfit = dappFundFlowDao.selectSumAmountByMemberIdAndTypeAndStatus(memberId,7,2); |
| | | adminTeamInfoVo.setLuckyProfit(luckyProfit); |
| | | } |
| | | } |
| | | return adminTeamInfoVoIPage; |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse getNodeInfo() { |
| | | List<DappNodeOrderVo> dappNodeOrderVos = dappNodeOrderMapper.selectNodeOrderList(); |
| | | return new FebsResponse().success().data(dappNodeOrderVos); |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse getMemberNode() { |
| | | DappMemberEntity member = LoginUserUtil.getAppUser(); |
| | | List<DappMemberNodeVo> dappMemberNodeVos = dappMemberNodeMapper.selectListByMemberId(member.getId()); |
| | | return new FebsResponse().success().data(dappMemberNodeVos); |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse getMemberInfo() { |
| | | DappMemberEntity member = LoginUserUtil.getAppUser(); |
| | | DappMemberInfoVo dappMemberInfoVo = dappMemberDao.selectByMemberId(member.getId()); |
| | | return new FebsResponse().success().data(dappMemberInfoVo); |
| | | } |
| | | |
| | | @Override |
| | | public IPage<DappMemberNodeVo> getMemberNodeInfo(DappMemberEntity dappMemberEntity, QueryRequest request) { |
| | | Page<DappMemberNodeVo> page = new Page<>(request.getPageNum(), request.getPageSize()); |
| | | return dappMemberNodeMapper.findMemberNodeInPage(page, dappMemberEntity); |
| | | } |
| | | |
| | | public TeamListVo buildTeamMatrix(Long memberId) { |
| | | DappMemberEntity member = dappMemberDao.selectById(memberId); |
| | | TeamListVo teamListVo = new TeamListVo(); |
| | | teamListVo.setName(node.getInviteId()); |
| | | teamListVo.setHasMoney(node.getHasMoney()); |
| | | teamListVo.setAddress(member.getAddress()); |
| | | teamListVo.setAccountType(member.getAccountType()); |
| | | teamListVo.setActiveStatus(member.getActiveStatus()); |
| | | List<DappMemberEntity> dappMemberEntities = dappMemberDao.selectMemberInfoByRefererId(member.getInviteId()); |
| | | teamListVo.setDirectCnt(dappMemberEntities.size()); |
| | | |
| | | if (CollUtil.isEmpty(childNodes)) { |
| | | if (CollUtil.isEmpty(dappMemberEntities)) { |
| | | return teamListVo; |
| | | } |
| | | |
| | | List<TeamListVo> list = new ArrayList<>(); |
| | | for (DappAchieveMemberTreeEntity childNode : childNodes) { |
| | | list.add(buildTeamMatrix(childNode)); |
| | | for (DappMemberEntity childNode : dappMemberEntities) { |
| | | list.add(buildTeamMatrix(childNode.getId())); |
| | | } |
| | | teamListVo.setChildren(list); |
| | | return teamListVo; |
| | | } |
| | | } |