| | |
| | | import cc.mrbird.febs.dapp.enumerate.NodeType; |
| | | import cc.mrbird.febs.dapp.mapper.*; |
| | | import cc.mrbird.febs.dapp.service.DappWalletService; |
| | | import cc.mrbird.febs.dapp.vo.ApiIndexInfoVo; |
| | | import cc.mrbird.febs.dapp.vo.MemberNodeVo; |
| | | import cc.mrbird.febs.dapp.vo.NodeTypeVo; |
| | | import cc.mrbird.febs.dapp.vo.WalletInfoVo; |
| | | import cc.mrbird.febs.dapp.vo.*; |
| | | import cc.mrbird.febs.rabbit.producer.ChainProducer; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.date.DateUtil; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author |
| | |
| | | |
| | | BigDecimal runPerk = dappFundFlowDao.selectSumRunPerkByMemberId(member.getId()); |
| | | walletInfo.setRunPerk(runPerk); |
| | | |
| | | |
| | | List<DappStorage> allAddressNums = dappStorageMapper.selectListGroupByMemberId(); |
| | | walletInfo.setAddressNum(CollUtil.isEmpty(allAddressNums) ? 0 : allAddressNums.size()); |
| | | |
| | | DappStorage dappStorage = dappStorageMapper.selectOneByCreateTimeDesc(0, 1); |
| | | walletInfo.setBuChangDate(ObjectUtil.isEmpty(dappStorage) ? |
| | | DateUtil.offsetDay(new Date(), 1) : DateUtil.offsetDay(dappStorage.getCreateTime(), 1)); |
| | | walletInfo.setBuchangChi(dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.BUCAHNG_CHI.getType(), |
| | | DataDictionaryEnum.BUCAHNG_CHI.getCode() |
| | | ).getValue()); |
| | | |
| | | walletInfo.setJilichi(dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.JILI_CHI.getType(), |
| | | DataDictionaryEnum.JILI_CHI.getCode() |
| | | ).getValue()); |
| | | |
| | | return walletInfo; |
| | | } |
| | |
| | | public void withdraw(WithdrawDto withdrawDto) { |
| | | DappMemberEntity member = LoginUserUtil.getAppUser(); |
| | | |
| | | DappMemberEntity memberEntity = dappMemberDao.selectById(member.getId()); |
| | | BigDecimal usdtBalance = memberEntity.getUsdtBalance(); |
| | | if(BigDecimal.ZERO.compareTo(usdtBalance) >= 0){ |
| | | throw new FebsException("额度不足"); |
| | | } |
| | | if(withdrawDto.getAmount().compareTo(usdtBalance) > 0){ |
| | | throw new FebsException("额度不足"); |
| | | } |
| | | |
| | | List<MemberCoinWithdrawEntity> memberCoinWithdrawEntities = memberCoinWithdrawDao.selectListByDate(member.getId(),new Date()); |
| | | if(CollUtil.isNotEmpty(memberCoinWithdrawEntities)){ |
| | | throw new FebsException("今日已提现"); |
| | |
| | | BigDecimal feeAmount = withdrawDto.getAmount().multiply(withdrawPercent).setScale(2, BigDecimal.ROUND_DOWN); |
| | | |
| | | updateWalletCoinWithLock(withdrawDto.getAmount(), member.getId(), 2); |
| | | |
| | | memberEntity.setUsdtBalance(usdtBalance.subtract(withdrawDto.getAmount()).setScale(2,BigDecimal.ROUND_DOWN)); |
| | | dappMemberDao.updateById(memberEntity); |
| | | |
| | | DappFundFlowEntity fundFlow = new DappFundFlowEntity( |
| | | member.getId(), |
| | |
| | | throw new FebsException("功能升级中"); |
| | | } |
| | | |
| | | DataDictionaryCustom startSymbolDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.START_SYMBOL.getType(), |
| | | DataDictionaryEnum.START_SYMBOL.getCode() |
| | | ); |
| | | if("STOP".equals(startSymbolDic.getValue())){ |
| | | throw new FebsException("贡献暂未开启"); |
| | | } |
| | | |
| | | BigDecimal amount = transferDto.getAmount(); |
| | | if(BigDecimal.ZERO.compareTo(amount) >= 0){ |
| | | throw new FebsException("请输入正确的存储数量"); |
| | |
| | | throw new FebsException("存储数量必须是"+bigDecimal+"的整数倍"); |
| | | } |
| | | |
| | | DappStorage dappStorage = dappStorageMapper.selectAmountByAmountDesc(0, 1); |
| | | DappStorage dappStorage = dappStorageMapper.selectAmountByAmountDesc(member.getId(),0, 1); |
| | | if(ObjectUtil.isNotEmpty(dappStorage)){ |
| | | if(amount.compareTo(dappStorage.getAmount()) < 0){ |
| | | throw new FebsException("存储数量必须大于:"+dappStorage.getAmount()); |
| | |
| | | DataDictionaryEnum.JI_SHU_CHI.getType(), |
| | | DataDictionaryEnum.JI_SHU_CHI.getCode() |
| | | ).getValue()); |
| | | List<DappStorage> dappStorages = dappStorageMapper.selectListGroupByMemberId(); |
| | | apiIndexInfoVo.setAddressNum(CollUtil.isEmpty(dappStorages) ? 0 : dappStorages.size()); |
| | | |
| | | DappStorage dappStorage = dappStorageMapper.selectOneByCreateTimeDesc(0, 1); |
| | | apiIndexInfoVo.setBuChangDate(ObjectUtil.isEmpty(dappStorage) ? |
| | | DateUtil.offsetDay(new Date(), 1) : DateUtil.offsetDay(dappStorage.getCreateTime(), 1)); |
| | | return apiIndexInfoVo; |
| | | } |
| | | |
| | | @Override |
| | | public List<ApiStorageInfoVo> storageIndex() { |
| | | List<ApiStorageInfoVo> apiStorageInfoVos = new ArrayList<>(); |
| | | List<DappStorage> dappStorages = dappStorageMapper.selectSumByAmountDesc(DateUtil.offsetHour(new Date(), -1), 0, 10); |
| | | if(CollUtil.isNotEmpty(dappStorages)){ |
| | | for(DappStorage dappStorage : dappStorages){ |
| | | ApiStorageInfoVo apiStorageInfoVo = new ApiStorageInfoVo(); |
| | | apiStorageInfoVo.setAddress(dappMemberDao.selectById(dappStorage.getMemberId()).getAddress()); |
| | | apiStorageInfoVo.setAmount(dappStorage.getAmount()); |
| | | |
| | | apiStorageInfoVos.add(apiStorageInfoVo); |
| | | } |
| | | } |
| | | |
| | | return apiStorageInfoVos; |
| | | } |
| | | |
| | | @Override |
| | | public List<ApiStorageInfoVo> directIndex() { |
| | | List<ApiStorageInfoVo> apiStorageInfoVos = new ArrayList<>(); |
| | | /** |
| | | * 存放直推业绩<上级的memberId,直推总业绩> |
| | | */ |
| | | HashMap<Long, BigDecimal> map = new HashMap<>(); |
| | | |
| | | List<DappStorage> dappStorages = dappStorageMapper.selectListByDate(new Date()); |
| | | if(CollUtil.isNotEmpty(dappStorages)){ |
| | | for(DappStorage dappStorage : dappStorages){ |
| | | DappMemberEntity member = dappMemberDao.selectById(dappStorage.getMemberId()); |
| | | if(StrUtil.isEmpty(member.getRefererId())){ |
| | | continue; |
| | | } |
| | | DappMemberEntity memberRef = dappMemberDao.selectMemberInfoByInviteId(member.getRefererId()); |
| | | if(ObjectUtil.isEmpty(memberRef)){ |
| | | continue; |
| | | } |
| | | Long id = memberRef.getId(); |
| | | if(map.containsKey(id)){ |
| | | BigDecimal bigDecimal = map.get(id); |
| | | BigDecimal add = bigDecimal.add(dappStorage.getAmount()); |
| | | map.put(id,add); |
| | | }else{ |
| | | map.put(id,dappStorage.getAmount()); |
| | | } |
| | | } |
| | | } |
| | | /** |
| | | * 获取这个map的直推总业绩前十,分发奖励 |
| | | */ |
| | | if(!map.isEmpty()){ |
| | | // 使用Stream API按照BigDecimal从大到小排序 |
| | | List<Map.Entry<Long, BigDecimal>> topTenEntries = map.entrySet().stream() |
| | | .sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())) |
| | | .limit(10) |
| | | .collect(Collectors.toList()); |
| | | for (Map.Entry<Long, BigDecimal> entry : topTenEntries) { |
| | | |
| | | Long memberId = entry.getKey(); |
| | | BigDecimal directAchieve = entry.getValue(); |
| | | ApiStorageInfoVo apiStorageInfoVo = new ApiStorageInfoVo(); |
| | | apiStorageInfoVo.setAddress(dappMemberDao.selectById(memberId).getAddress()); |
| | | apiStorageInfoVo.setAmount(directAchieve); |
| | | |
| | | apiStorageInfoVos.add(apiStorageInfoVo); |
| | | } |
| | | } |
| | | return apiStorageInfoVos; |
| | | } |
| | | |
| | | @Override |
| | | public List<ApiDirectInfoVo> directNumIndex() { |
| | | List<ApiDirectInfoVo> apiDirectInfoVos = new ArrayList<>(); |
| | | /** |
| | | * 存放直推人数<上级的memberId,直推人数> |
| | | */ |
| | | HashMap<Long, BigDecimal> map = new HashMap<>(); |
| | | |
| | | List<DappMemberEntity> dappMemberEntityList = dappMemberDao.selectListByDate(new Date()); |
| | | if(CollUtil.isNotEmpty(dappMemberEntityList)){ |
| | | for(DappMemberEntity member : dappMemberEntityList){ |
| | | if(StrUtil.isEmpty(member.getRefererId())){ |
| | | continue; |
| | | } |
| | | DappMemberEntity memberRef = dappMemberDao.selectMemberInfoByInviteId(member.getRefererId()); |
| | | if(ObjectUtil.isEmpty(memberRef)){ |
| | | continue; |
| | | } |
| | | Long id = memberRef.getId(); |
| | | if(map.containsKey(id)){ |
| | | BigDecimal bigDecimal = map.get(id); |
| | | BigDecimal add = bigDecimal.add(new BigDecimal("1")); |
| | | map.put(id,add); |
| | | }else{ |
| | | map.put(id,new BigDecimal("1")); |
| | | } |
| | | } |
| | | } |
| | | /** |
| | | * 获取这个map的直推人数前十,分发奖励 |
| | | */ |
| | | if(!map.isEmpty()){ |
| | | // 使用Stream API按照BigDecimal从大到小排序 |
| | | List<Map.Entry<Long, BigDecimal>> topTenEntries = map.entrySet().stream() |
| | | .sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())) |
| | | .limit(10) |
| | | .collect(Collectors.toList()); |
| | | for (Map.Entry<Long, BigDecimal> entry : topTenEntries) { |
| | | |
| | | Long memberId = entry.getKey(); |
| | | BigDecimal directCnt = entry.getValue(); |
| | | ApiDirectInfoVo apiDirectInfoVo = new ApiDirectInfoVo(); |
| | | apiDirectInfoVo.setAddress(dappMemberDao.selectById(memberId).getAddress()); |
| | | apiDirectInfoVo.setAmount(directCnt); |
| | | |
| | | apiDirectInfoVos.add(apiDirectInfoVo); |
| | | } |
| | | } |
| | | |
| | | |
| | | return apiDirectInfoVos; |
| | | } |
| | | |
| | | public MemberNodeVo buildTeamMatrix(DbMemberNode dbMemberNode) { |
| | | Long id = dbMemberNode.getId(); |
| | | |