| | |
| | | package cc.mrbird.febs.dapp.service.impl; |
| | | |
| | | 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.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.DateTime; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | |
| | | 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<DappMemberEntity> dappMemberEntities = dappMemberDao.selectList(null); |
| | | 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(); |
| | | |
| | | List<MemberCoinWithdrawEntity> memberCoinWithdrawEntities = memberCoinWithdrawDao.selectListByDate(member.getId(),new Date()); |
| | | if(CollUtil.isNotEmpty(memberCoinWithdrawEntities)){ |
| | | throw new FebsException("今日已提现"); |
| | | DappMemberEntity memberEntity = dappMemberDao.selectById(member.getId()); |
| | | BigDecimal usdtBalance = memberEntity.getUsdtBalance(); |
| | | if(1 != memberEntity.getNodeType()){ |
| | | if(BigDecimal.ZERO.compareTo(usdtBalance) >= 0){ |
| | | throw new FebsException("额度不足"); |
| | | } |
| | | |
| | | if(BigDecimal.ZERO.compareTo(withdrawDto.getAmount()) >= 0){ |
| | | throw new FebsException("请输入正确的数量"); |
| | | } |
| | | if(withdrawDto.getAmount().compareTo(usdtBalance) > 0){ |
| | | throw new FebsException("额度不足"); |
| | | } |
| | | }else{ |
| | | if(BigDecimal.ZERO.compareTo(withdrawDto.getAmount()) >= 0){ |
| | | throw new FebsException("请输入正确的数量"); |
| | | } |
| | | } |
| | | // List<MemberCoinWithdrawEntity> memberCoinWithdrawEntities = memberCoinWithdrawDao.selectListByDate(member.getId(),new Date()); |
| | | // if(CollUtil.isNotEmpty(memberCoinWithdrawEntities)){ |
| | | // throw new FebsException("今日已提现"); |
| | | // } |
| | | |
| | | DappWalletCoinEntity walletCoin = dappWalletCoinDao.selectByMemberId(member.getId()); |
| | | if (walletCoin.getAvailableAmount().compareTo(withdrawDto.getAmount()) < 0) { |
| | |
| | | BigDecimal feeAmount = withdrawDto.getAmount().multiply(withdrawPercent).setScale(2, BigDecimal.ROUND_DOWN); |
| | | |
| | | updateWalletCoinWithLock(withdrawDto.getAmount(), member.getId(), 2); |
| | | if(1 != memberEntity.getNodeType()){ |
| | | 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("贡献暂未开启"); |
| | | } |
| | | |
| | | DateTime startTime = DateUtil.parseDateTime("2024-07-09 17:00:00"); |
| | | if(DateUtil.compare(DateUtil.date(), startTime) < 0){ |
| | | 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.BUCAHNG_CHI.getType(), |
| | | DataDictionaryEnum.BUCAHNG_CHI.getCode() |
| | | ).getValue()); |
| | | apiIndexInfoVo.setJiedianChi(dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.JIE_DIAN_CHI.getType(), |
| | | DataDictionaryEnum.JIE_DIAN_CHI.getCode() |
| | | ).getValue()); |
| | | List<DappStorage> dappStorages = dappStorageMapper.selectList(null); |
| | | BigDecimal reduce = dappStorages.stream().map(DappStorage::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal bigDecimal = reduce.multiply(new BigDecimal(AppContants.DAO_NODE_PERCENT)).setScale(2, BigDecimal.ROUND_DOWN); |
| | | apiIndexInfoVo.setJiedianChi(bigDecimal.toString()); |
| | | |
| | | // apiIndexInfoVo.setJiedianChi(dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | // DataDictionaryEnum.JIE_DIAN_CHI.getType(), |
| | | // DataDictionaryEnum.JIE_DIAN_CHI.getCode() |
| | | // ).getValue()); |
| | | apiIndexInfoVo.setJijinghuiChi(dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.JI_JING_HUI_CHI.getType(), |
| | | DataDictionaryEnum.JI_JING_HUI_CHI.getCode() |
| | |
| | | return apiIndexInfoVo; |
| | | } |
| | | |
| | | @Override |
| | | public List<ApiStorageInfoVo> storageIndex() { |
| | | List<ApiStorageInfoVo> apiStorageInfoVos = new ArrayList<>(); |
| | | |
| | | DateTime nowTime = DateUtil.parseTime(DateUtil.formatTime(new Date())); |
| | | DateTime perkTime = DateUtil.parseTime("17:00:00"); |
| | | String startTimeStr = null; |
| | | if(DateUtil.compare(nowTime,perkTime) >= 0){ |
| | | startTimeStr = DateUtil.formatDate(DateUtil.offsetDay(new Date(), 0)) + " 17:00:00"; |
| | | }else{ |
| | | startTimeStr = DateUtil.formatDate(DateUtil.offsetDay(new Date(), -1)) + " 17:00:00"; |
| | | } |
| | | DateTime startTime = DateUtil.parseDateTime(startTimeStr); |
| | | |
| | | List<DappStorage> dappStorages = dappStorageMapper.selectSumByAmountDescFiveToFive(startTime, 0, 10); |
| | | // 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<>(); |
| | | |
| | | DateTime nowTime = DateUtil.parseTime(DateUtil.formatTime(new Date())); |
| | | DateTime perkTime = DateUtil.parseTime("17:00:00"); |
| | | String startTimeStr = null; |
| | | if(DateUtil.compare(nowTime,perkTime) >= 0){ |
| | | startTimeStr = DateUtil.formatDate(DateUtil.offsetDay(new Date(), 0)) + " 17:00:00"; |
| | | }else{ |
| | | startTimeStr = DateUtil.formatDate(DateUtil.offsetDay(new Date(), -1)) + " 17:00:00"; |
| | | } |
| | | DateTime startTime = DateUtil.parseDateTime(startTimeStr); |
| | | // List<DappMemberEntity> dappMemberEntityList = dappMemberDao.selectListByDateFiveToFiver(startTime); |
| | | |
| | | List<DappStorage> dappStorages = dappStorageMapper.selectListByDateFiveToFiver(startTime); |
| | | Set<Long> collect = dappStorages.stream().map(DappStorage::getMemberId).collect(Collectors.toSet()); |
| | | |
| | | // List<DappMemberEntity> dappMemberEntityList = dappMemberDao.selectListByDate(new Date()); |
| | | if(CollUtil.isNotEmpty(collect)){ |
| | | for(Long memberId : collect){ |
| | | DappMemberEntity member = dappMemberDao.selectById(memberId); |
| | | if(StrUtil.isEmpty(member.getRefererId())){ |
| | | continue; |
| | | } |
| | | if(2 == member.getActiveStatus()){ |
| | | 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(); |
| | | |