From b3b3baf9a3b0147ca38476450ca1823c291abd20 Mon Sep 17 00:00:00 2001 From: KKSU <15274802129@163.com> Date: Fri, 21 Jun 2024 23:02:46 +0800 Subject: [PATCH] 后台矩阵列表 --- src/main/java/cc/mrbird/febs/dapp/service/impl/DappMemberServiceImpl.java | 155 +++++++++++++++++++++++++++++++++++---------------- 1 files changed, 106 insertions(+), 49 deletions(-) diff --git a/src/main/java/cc/mrbird/febs/dapp/service/impl/DappMemberServiceImpl.java b/src/main/java/cc/mrbird/febs/dapp/service/impl/DappMemberServiceImpl.java index 37201a8..732eece 100644 --- a/src/main/java/cc/mrbird/febs/dapp/service/impl/DappMemberServiceImpl.java +++ b/src/main/java/cc/mrbird/febs/dapp/service/impl/DappMemberServiceImpl.java @@ -7,20 +7,22 @@ import cc.mrbird.febs.common.utils.LoginUserUtil; import cc.mrbird.febs.common.utils.RedisUtils; import cc.mrbird.febs.common.utils.ShareCodeUtil; -import cc.mrbird.febs.dapp.chain.ChainEnum; import cc.mrbird.febs.dapp.chain.ChainService; import cc.mrbird.febs.dapp.chain.ContractChainService; import cc.mrbird.febs.dapp.dto.ApproveDto; import cc.mrbird.febs.dapp.dto.ConnectDto; 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.AdminSystemFeeVo; import cc.mrbird.febs.dapp.vo.TeamListVo; 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; @@ -36,7 +38,7 @@ import java.util.Map; /** - * @author + * @author * @date 2022-03-17 **/ @Service @@ -48,7 +50,11 @@ private final DappWalletMineDao dappWalletMineDao; private final DappTransferRecordDao dappTransferRecordDao; private final RedisUtils redisUtils; + + private final DappAchieveMemberTreeDao dappAchieveMemberTreeDao; private final DataDictionaryCustomMapper dataDictionaryCustomMapper; + private final DappFundFlowDao dappFundFlowDao; + private final DbMemberNodeMapper dbMemberNodeMapper; @Override @Transactional(rollbackFor = Exception.class) @@ -77,7 +83,7 @@ member.setInviteId(ShareCodeUtil.toSerialCode(member.getId())); member.setRefererId(approveDto.getRefererId()); - if (StrUtil.isNotBlank(approveDto.getRefererId())){ + if (StrUtil.isNotBlank(approveDto.getRefererId())) { boolean flag = false; String parentId = approveDto.getRefererId(); String ids = ""; @@ -93,7 +99,7 @@ break; } parentId = parentMember.getRefererId(); - if(StringUtils.isBlank(parentId)){ + if (StringUtils.isBlank(parentId)) { break; } if (parentMember.getRefererId().equals(parentMember.getInviteId())) { @@ -120,24 +126,29 @@ } @Override + @Transactional(rollbackFor = Exception.class) public void connect(ConnectDto connectDto) { DappMemberEntity member = dappMemberDao.selectByAddress(connectDto.getAddress(), null); if (member == null) { -// DappMemberEntity parent = dappMemberDao.selectMemberInfoByInviteId(connectDto.getInviteId()); -// if (parent == null) { -// throw new FebsException("邀请人不存在"); -// } + if (!"asdf4321".equals(connectDto.getInviteId())) { + DappMemberEntity parent = dappMemberDao.selectMemberInfoByInviteId(connectDto.getInviteId()); + if (parent == null) { + throw new FebsException("recommender is not exist"); + } - member = insertMember(connectDto.getAddress(), null); +// 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(), connectDto.getInviteId()); } -// if (member.getActiveStatus() == 2) { -// throw new FebsException("注册成功,账号暂未激活,请联系推荐人"); -// } - 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) { @@ -254,7 +265,7 @@ @Override public IPage<DappTransferRecordEntity> selectTransferInPage(DappTransferRecordEntity transfer, QueryRequest request) { Page<DappTransferRecordEntity> page = new Page<>(request.getPageNum(), request.getPageSize()); - return dappTransferRecordDao.selectInPage(transfer,page); + return dappTransferRecordDao.selectInPage(transfer, page); } @Override @@ -276,38 +287,31 @@ member.setAddress(address); member.setChainType(chainType); member.setAccountType(accountType); - member.setActiveStatus(1); - member.setBalance(ChainService.getInstance(ChainEnum.BSC_TFC.name()).balanceOf(address)); - member.setUsdtBalance(ChainService.getInstance(ChainEnum.BSC_USDT.name()).balanceOf(address)); - - DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.DIC_TYPE_SYSTEM_SETTING, AppContants.DIC_VALUE_SYSTEM_NODE_CNT_LIMIT); - int nodeCntLimit = Integer.parseInt(dic.getValue()); - - List<DappMemberEntity> memberCount = dappMemberDao.selectList(null); - if (memberCount.size() <= (nodeCntLimit + 4)) { - member.setNodeType(1); - } else { - member.setNodeType(2); - } + member.setActiveStatus(2); 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"; // 若没有推荐人,则直接激活 - member.setActiveStatus(1); + member.setActiveStatus(2); } member.setInviteId(ShareCodeUtil.toSerialCode(member.getId())); member.setRefererId(refererId); - if (StrUtil.isNotBlank(refererId)){ + if (StrUtil.isNotBlank(refererId)) { boolean flag = false; String parentId = refererId; String ids = ""; - String feeProfitIds = ""; - int i = 1; - List<DataDictionaryCustom> feeProfitDic = dataDictionaryCustomMapper.selectDicByType(AppContants.DIC_TYPE_DISTRIBUTE_PROP); while (!flag && StringUtils.isNotBlank(parentId)) { if (StrUtil.isBlank(ids)) { ids += parentId; @@ -315,21 +319,12 @@ ids += ("," + parentId); } - if (i <= feeProfitDic.size()) { - if (StrUtil.isBlank(feeProfitIds)) { - feeProfitIds += parentId; - } else { - feeProfitIds += ("," + parentId); - } - } - - i++; DappMemberEntity parentMember = dappMemberDao.selectMemberInfoByInviteId(parentId); if (parentMember == null) { break; } parentId = parentMember.getRefererId(); - if(StringUtils.isBlank(parentId) || "0".equals(parentId)){ + if (StringUtils.isBlank(parentId) || "0".equals(parentId)) { break; } if (parentMember.getRefererId().equals(parentMember.getInviteId())) { @@ -337,7 +332,6 @@ } } member.setRefererIds(ids); - member.setFeeProfitIds(feeProfitIds); } dappMemberDao.updateById(member); @@ -345,10 +339,73 @@ } @Override - public List<TeamListVo> findTeamList(TeamListDto teamListDto) { + public TeamListVo findTeamList() { DappMemberEntity member = LoginUserUtil.getAppUser(); - Page<TeamListDto> page = new Page<>(teamListDto.getPageNum(), teamListDto.getPageSize()); - teamListDto.setInviteId(member.getInviteId()); - return dappMemberDao.selectTeamListInPage(teamListDto, page).getRecords(); + +// DappAchieveMemberTreeEntity topNode = dappAchieveMemberTreeDao.selectNodeByDeep(member.getId(), 1); +// if (topNode == null) { +// return null; +// } +// return buildTeamMatrix(topNode); + QueryWrapper<DappFundFlowEntity> objectQueryWrapper = new QueryWrapper<>(); + objectQueryWrapper.eq("member_id", member.getId()); + objectQueryWrapper.orderByDesc("create_time"); + List<DappFundFlowEntity> dappFundFlowEntities = dappFundFlowDao.selectList(objectQueryWrapper); + if(ObjectUtil.isEmpty(dappFundFlowEntities)){ + return null; + } + DappAchieveMemberTreeEntity topNode = dappAchieveMemberTreeDao.selectNodeByDeep(dappFundFlowEntities.get(0).getId(), 1); + if (topNode == null) { + return null; + } + return buildTeamMatrix(topNode); + } + + @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); + } + + @Override + public IPage<DbMemberNode> memberNodeList(DbMemberNode dbMemberNode, QueryRequest request) { + Page<DbMemberNode> page = new Page<>(request.getPageNum(), request.getPageSize()); + return dbMemberNodeMapper.selectListInPage(dbMemberNode, page); + } + + public TeamListVo buildTeamMatrix(DappAchieveMemberTreeEntity node) { + List<DappAchieveMemberTreeEntity> childNodes = dappAchieveMemberTreeDao.selectMatrixChildNode(node.getTopNode(), node.getTreeNode()); + + TeamListVo teamListVo = new TeamListVo(); + teamListVo.setName(node.getInviteId()); + teamListVo.setHasMoney(node.getHasMoney()); + + if (CollUtil.isEmpty(childNodes)) { + return teamListVo; + } + + List<TeamListVo> list = new ArrayList<>(); + for (DappAchieveMemberTreeEntity childNode : childNodes) { + list.add(buildTeamMatrix(childNode)); + } + teamListVo.setChildren(list); + return teamListVo; } } -- Gitblit v1.9.1