| | |
| | | package cc.mrbird.febs.dapp.service.impl; |
| | | |
| | | import cc.mrbird.febs.common.contants.AppContants; |
| | | import cc.mrbird.febs.common.utils.LoginUserUtil; |
| | | import cc.mrbird.febs.common.utils.RedisUtils; |
| | | import cc.mrbird.febs.dapp.dto.SystemDto; |
| | | import cc.mrbird.febs.dapp.entity.*; |
| | | import cc.mrbird.febs.dapp.enumerate.DataDictionaryEnum; |
| | | import cc.mrbird.febs.dapp.enumerate.InviteRule; |
| | | import cc.mrbird.febs.dapp.enumerate.NodeType; |
| | | import cc.mrbird.febs.dapp.enumerate.*; |
| | | import cc.mrbird.febs.dapp.mapper.*; |
| | | import cc.mrbird.febs.dapp.service.DappSystemService; |
| | | import cc.mrbird.febs.dapp.service.DappWalletService; |
| | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | private final RedisUtils redisUtils; |
| | | private final DappFundFlowDao dappFundFlowDao; |
| | | private final DappMemberDao dappMemberDao; |
| | | private final DappStorageMapper dappStorageMapper; |
| | | |
| | | private final DappAchieveTreeDao dappAchieveTreeDao; |
| | | private final DappAchieveMemberTreeDao dappAchieveMemberTreeDao; |
| | |
| | | DappMemberEntity dappMemberEntityDirect = dappMemberDao.selectMemberInfoByInviteId(member.getRefererId()); |
| | | if(ObjectUtil.isNotEmpty(dappMemberEntityDirect)){ |
| | | Long id = dappMemberEntityDirect.getId(); |
| | | chainProducer.sendNodeMsgLong(id); |
| | | // chainProducer.sendNodeMsgLong(id); |
| | | } |
| | | |
| | | //如果添加的为右节点,那么进入判断 |
| | |
| | | @Override |
| | | public void invitePerkMsg(Long id) { |
| | | /** |
| | | * 推荐规则: |
| | | * 无直推奖励,推2个3层,3个6层,4个10层。1%见点奖(有效层级内,每个每1%),共10层,共%10。 |
| | | * * 二、DAO成员动态: |
| | | * * 1.直推1个拿2代,直推10个拿20代,直推15个拿30代,最高30代 |
| | | * * 2. 1-5代奖励7% |
| | | * * 6-10代奖励6% |
| | | * * 11-15代奖励5% |
| | | * * 15-20代奖励4% |
| | | * * 21-25代奖励4% |
| | | * * 26-30代奖励7% |
| | | */ |
| | | DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectById(id); |
| | | if(ObjectUtil.isEmpty(dappFundFlowEntity)){ |
| | | // DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectById(id); |
| | | // if(ObjectUtil.isEmpty(dappFundFlowEntity)){ |
| | | // return; |
| | | // } |
| | | // if(DappFundFlowEntity.WITHDRAW_STATUS_AGREE != dappFundFlowEntity.getStatus()){ |
| | | // return; |
| | | // } |
| | | DappStorage dappStorage = dappStorageMapper.selectById(id); |
| | | |
| | | if(ObjectUtil.isEmpty(dappStorage)){ |
| | | return; |
| | | } |
| | | BigDecimal amount = dappFundFlowEntity.getAmount().abs(); |
| | | BigDecimal amount = dappStorage.getReleaseAmount().abs(); |
| | | /** |
| | | * 往上循环十层,判断每一层是否有见点奖 |
| | | * 往上循环30层,判断每一层是否有见点奖 |
| | | */ |
| | | Long memberId = dappFundFlowEntity.getMemberId(); |
| | | for(int i = 1;i <= 10;i++){ |
| | | Long memberId = dappStorage.getMemberId(); |
| | | for(int i = 1;i <= 30;i++){ |
| | | DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberId); |
| | | String refererId = dappMemberEntity.getRefererId(); |
| | | //上级不存在,则停止循环。 |
| | |
| | | if(1 != activeStatus){ |
| | | continue; |
| | | } |
| | | //获取上级全部的直推 |
| | | //获取上级全部的激活直推 |
| | | String inviteId = dappMemberEntityRef.getInviteId(); |
| | | QueryWrapper<DappMemberEntity> memberInviteQuery = new QueryWrapper<>(); |
| | | memberInviteQuery.eq("referer_id",inviteId); |
| | | memberInviteQuery.eq("active_status",1); |
| | | List<DappMemberEntity> memberInviteList = dappMemberDao.selectList(memberInviteQuery); |
| | | |
| | | //如果没有直推,则跳过 |
| | |
| | | BigDecimal perkPercent = new BigDecimal(rule.getPerkPercent()).multiply(new BigDecimal("0.01")); |
| | | BigDecimal perkAmount = perkPercent.multiply(amount); |
| | | Long perkMemberId = dappMemberEntityRef.getId(); |
| | | //生成一条流水 |
| | | DappFundFlowEntity rePutInFlow = new DappFundFlowEntity( |
| | | perkMemberId, |
| | | |
| | | this.updateBalanceInsertFlow( |
| | | perkAmount, |
| | | 15, |
| | | 2, |
| | | null, |
| | | null); |
| | | dappFundFlowDao.insert(rePutInFlow); |
| | | //更新用户的金额 |
| | | dappWalletService.updateWalletCoinWithLock(perkAmount, perkMemberId, 1); |
| | | perkMemberId, |
| | | MoneyFlowEnum.DYNAMIC_PERK.getValue(), |
| | | StrUtil.format(MoneyFlowEnum.DYNAMIC_PERK.getDescrition(),amount,memberInviteList.size(),perkAmount)); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void nodePerkMsg(Long id) { |
| | | DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectById(id); |
| | | |
| | | if(MoneyFlowEnum.CUN_CHU.getValue() != dappFundFlowEntity.getType()){ |
| | | return; |
| | | } |
| | | if(DappFundFlowEntity.WITHDRAW_STATUS_AGREE != dappFundFlowEntity.getStatus()){ |
| | | return; |
| | | } |
| | | |
| | | BigDecimal amount = dappFundFlowEntity.getAmount(); |
| | | |
| | | /** |
| | | * 激励池 6% |
| | | */ |
| | | BigDecimal jiliAmount = new BigDecimal(AppContants.DAO_JI_LI_PERCENT).multiply(amount); |
| | | |
| | | DataDictionaryCustom jiliChiDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.JILI_CHI.getType(), |
| | | DataDictionaryEnum.JILI_CHI.getCode() |
| | | ); |
| | | BigDecimal addJili = new BigDecimal(jiliChiDic.getValue()).add(jiliAmount).setScale(2,BigDecimal.ROUND_DOWN); |
| | | jiliChiDic.setValue(addJili.toString()); |
| | | dataDictionaryCustomMapper.updateById(jiliChiDic); |
| | | |
| | | /** |
| | | * 补偿池 2% |
| | | */ |
| | | BigDecimal buchangAmount = new BigDecimal(AppContants.DAO_BU_CHANG_PERCENT).multiply(amount); |
| | | DataDictionaryCustom buchangChiDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.BUCAHNG_CHI.getType(), |
| | | DataDictionaryEnum.BUCAHNG_CHI.getCode() |
| | | ); |
| | | BigDecimal addBuchang = new BigDecimal(buchangChiDic.getValue()).add(buchangAmount).setScale(2,BigDecimal.ROUND_DOWN); |
| | | buchangChiDic.setValue(addBuchang.toString()); |
| | | dataDictionaryCustomMapper.updateById(buchangChiDic); |
| | | |
| | | /** |
| | | * 团队 5 %加权分红(people数量) |
| | | */ |
| | | // BigDecimal tuanDuiAmount = amount.multiply(new BigDecimal(AppContants.DAO_TEAM_PERK_PERCENT)); |
| | | // DataDictionaryCustom tuanDuiChiDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | // DataDictionaryEnum.TUAN_DUI_CHI.getType(), |
| | | // DataDictionaryEnum.TUAN_DUI_CHI.getCode() |
| | | // ); |
| | | // BigDecimal tuanDuiChi = new BigDecimal(tuanDuiChiDic.getValue()).add(tuanDuiAmount).setScale(2,BigDecimal.ROUND_DOWN); |
| | | // tuanDuiChiDic.setValue(tuanDuiChi.toString()); |
| | | // dataDictionaryCustomMapper.updateById(tuanDuiChiDic); |
| | | |
| | | /** |
| | | * 技术 2 %加权分红(people数量) |
| | | */ |
| | | BigDecimal jiShuAmount = amount.multiply(new BigDecimal(AppContants.DAO_JI_SHU_PERCENT)); |
| | | DataDictionaryCustom jiShuChiDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.JI_SHU_CHI.getType(), |
| | | DataDictionaryEnum.JI_SHU_CHI.getCode() |
| | | ); |
| | | BigDecimal jiShuChi = new BigDecimal(jiShuChiDic.getValue()).add(jiShuAmount).setScale(2,BigDecimal.ROUND_DOWN); |
| | | jiShuChiDic.setValue(jiShuChi.toString()); |
| | | dataDictionaryCustomMapper.updateById(jiShuChiDic); |
| | | |
| | | /** |
| | | * 基金会 3 %加权分红(people数量) |
| | | */ |
| | | BigDecimal jiJingHuiAmount = amount.multiply(new BigDecimal(AppContants.DAO_JI_JING_HUI_PERCENT)); |
| | | DataDictionaryCustom jiJingHuiChiDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.JI_JING_HUI_CHI.getType(), |
| | | DataDictionaryEnum.JI_JING_HUI_CHI.getCode() |
| | | ); |
| | | BigDecimal jiJingHuiChi = new BigDecimal(jiJingHuiChiDic.getValue()).add(jiJingHuiAmount).setScale(2,BigDecimal.ROUND_DOWN); |
| | | jiJingHuiChiDic.setValue(jiJingHuiChi.toString()); |
| | | dataDictionaryCustomMapper.updateById(jiJingHuiChiDic); |
| | | |
| | | /** |
| | | * DAO联盟委员会 : 5% |
| | | */ |
| | | BigDecimal daoNodeAmountTotal = new BigDecimal(AppContants.DAO_NODE_PERCENT).multiply(amount); |
| | | //沉淀剩余 |
| | | BigDecimal daoNodeAmountAva = BigDecimal.ZERO; |
| | | |
| | | QueryWrapper<DappMemberEntity> objectQueryWrapper = new QueryWrapper<>(); |
| | | objectQueryWrapper.eq("node_type",1); |
| | | List<DappMemberEntity> dappMemberEntities = dappMemberDao.selectList(objectQueryWrapper); |
| | | if(CollUtil.isNotEmpty(dappMemberEntities)){ |
| | | BigDecimal daoNodeAmount = daoNodeAmountTotal.divide(new BigDecimal(dappMemberEntities.size()),2,BigDecimal.ROUND_DOWN); |
| | | for(DappMemberEntity nodeMember : dappMemberEntities){ |
| | | //生成一条流水 |
| | | DappFundFlowEntity rePutInFlow = new DappFundFlowEntity( |
| | | nodeMember.getId(), |
| | | daoNodeAmount, |
| | | MoneyFlowEnum.NODE_PERK.getValue(), |
| | | 2, |
| | | null, |
| | | StrUtil.format(MoneyFlowEnum.NODE_PERK.getDescrition(),amount,dappMemberEntities.size(),daoNodeAmount)); |
| | | dappFundFlowDao.insert(rePutInFlow); |
| | | //更新用户的金额 |
| | | dappWalletService.updateWalletCoinWithLock(daoNodeAmount, nodeMember.getId(), 1); |
| | | } |
| | | }else{ |
| | | daoNodeAmountAva = daoNodeAmountTotal; |
| | | } |
| | | |
| | | if(BigDecimal.ZERO.compareTo(daoNodeAmountAva) < 0){ |
| | | DataDictionaryCustom jieDianChiDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.JIE_DIAN_CHI.getType(), |
| | | DataDictionaryEnum.JIE_DIAN_CHI.getCode() |
| | | ); |
| | | BigDecimal jieDianChi = new BigDecimal(jieDianChiDic.getValue()).add(daoNodeAmountAva).setScale(2,BigDecimal.ROUND_DOWN); |
| | | jieDianChiDic.setValue(jieDianChi.toString()); |
| | | dataDictionaryCustomMapper.updateById(jieDianChiDic); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void directPerkMsg(Long id) { |
| | | DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectById(id); |
| | | |
| | | if(MoneyFlowEnum.CUN_CHU.getValue() != dappFundFlowEntity.getType()){ |
| | | return; |
| | | } |
| | | if(DappFundFlowEntity.WITHDRAW_STATUS_AGREE != dappFundFlowEntity.getStatus()){ |
| | | return; |
| | | } |
| | | |
| | | Long memberId = dappFundFlowEntity.getMemberId(); |
| | | DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberId); |
| | | if(ObjectUtil.isEmpty(dappMemberEntity)){ |
| | | return; |
| | | } |
| | | if(ObjectUtil.isEmpty(dappMemberEntity.getRefererId())){ |
| | | return; |
| | | } |
| | | DappMemberEntity directMember = dappMemberDao.selectMemberInfoByInviteId(dappMemberEntity.getRefererId()); |
| | | if(ObjectUtil.isEmpty(directMember)){ |
| | | return; |
| | | } |
| | | |
| | | BigDecimal amount = dappFundFlowEntity.getAmount(); |
| | | /* |
| | | 直推 8% |
| | | */ |
| | | BigDecimal directAmount = new BigDecimal(AppContants.DIRECT_PERCENT).multiply(amount); |
| | | if(BigDecimal.ZERO.compareTo(directAmount) >= 0){ |
| | | return; |
| | | } |
| | | |
| | | this.updateBalanceInsertFlow( |
| | | directAmount, |
| | | directMember.getId(), |
| | | MoneyFlowEnum.DIRECT_PERK.getValue(), |
| | | StrUtil.format(MoneyFlowEnum.DIRECT_PERK.getDescrition(),amount,directAmount)); |
| | | } |
| | | |
| | | @Override |
| | | public void updateBalanceInsertFlow (BigDecimal daoNodeAmount,Long memberId,Integer type,String description){ |
| | | if(BigDecimal.ZERO.compareTo(daoNodeAmount) > 0){ |
| | | return; |
| | | } |
| | | DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberId); |
| | | if(ObjectUtil.isEmpty(dappMemberEntity)){ |
| | | return; |
| | | } |
| | | if(1 != dappMemberEntity.getActiveStatus()){ |
| | | return; |
| | | } |
| | | |
| | | //减少用户的总额度 |
| | | // BigDecimal usdtBalance = dappMemberEntity.getUsdtBalance(); |
| | | // if(BigDecimal.ZERO.compareTo(usdtBalance) >= 0){ |
| | | // return; |
| | | // } |
| | | // if(daoNodeAmount.compareTo(usdtBalance) >= 0){ |
| | | // daoNodeAmount = usdtBalance; |
| | | // usdtBalance = BigDecimal.ZERO; |
| | | // }else{ |
| | | // usdtBalance = usdtBalance.subtract(daoNodeAmount); |
| | | // } |
| | | |
| | | //总额度为0,用户变成未激活 |
| | | // if(BigDecimal.ZERO.compareTo(usdtBalance) >= 0){ |
| | | // dappMemberEntity.setActiveStatus(2); |
| | | // //更新用户所有的业绩为已失效 |
| | | // QueryWrapper<DappStorage> objectQueryWrapper = new QueryWrapper<>(); |
| | | // objectQueryWrapper.eq("member_id",memberId); |
| | | // objectQueryWrapper.eq("state",1); |
| | | // List<DappStorage> dappStorages = dappStorageMapper.selectList(objectQueryWrapper); |
| | | // if(CollUtil.isNotEmpty(dappStorages)){ |
| | | // for(DappStorage dappStorage : dappStorages){ |
| | | // dappStorage.setState(2); |
| | | // dappStorageMapper.updateById(dappStorage); |
| | | // } |
| | | // } |
| | | // } |
| | | // dappMemberEntity.setUsdtBalance(usdtBalance); |
| | | // dappMemberDao.updateById(dappMemberEntity); |
| | | |
| | | dappWalletService.updateWalletCoinWithLock(daoNodeAmount, memberId, 1); |
| | | DappFundFlowEntity nodeFlow = new DappFundFlowEntity( |
| | | memberId, |
| | | daoNodeAmount, |
| | | type, |
| | | 2, |
| | | BigDecimal.ZERO, |
| | | description); |
| | | dappFundFlowDao.insert(nodeFlow); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * |
| | | * 3. DAO成员团队奖:5%加权分红(people数量) |
| | | * DAO1:小区业绩30万/币 加权分红50% |
| | | * DAO2:小区业绩100万/币 加权分红30% |
| | | * DAO3:小区业绩500万/币加权分红20% |
| | | */ |
| | | @Override |
| | | public void teamPerk(Long id) { |
| | | DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectById(id); |
| | | if(ObjectUtil.isEmpty(dappFundFlowEntity)){ |
| | | return; |
| | | } |
| | | BigDecimal amount = dappFundFlowEntity.getAmount().abs(); |
| | | log.info("买入贡献值-平分总金额-{}",amount); |
| | | /** |
| | | * 获取节点平分百分比 perkPercent |
| | | * 获取平分的份数 perKNum |
| | | * 获取每一份的金额 perkAmount |
| | | * 获取节点总数 buyNodeNum |
| | | * 如果perKNum大于buyNodeNum,则每个人获得(amount * perkPercent)/ perKNum = perkAmount |
| | | * 如果超出,再超出的人没有奖励 |
| | | */ |
| | | DataDictionaryCustom perkPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.PERK_PERCENT.getType(), |
| | | DataDictionaryEnum.PERK_PERCENT.getCode() |
| | | ); |
| | | BigDecimal perkPercent = new BigDecimal(ObjectUtil.isEmpty(perkPercentDic) ? "10" : perkPercentDic.getValue()).multiply(new BigDecimal("0.01")); |
| | | |
| | | DataDictionaryCustom perKNumDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.PERK_NUM.getType(), |
| | | DataDictionaryEnum.PERK_NUM.getCode() |
| | | ); |
| | | BigDecimal perKNum = new BigDecimal(ObjectUtil.isEmpty(perKNumDic) ? "200" : perKNumDic.getValue()); |
| | | if(MoneyFlowEnum.CUN_CHU.getValue() != dappFundFlowEntity.getType()){ |
| | | return; |
| | | } |
| | | if(DappFundFlowEntity.WITHDRAW_STATUS_AGREE != dappFundFlowEntity.getStatus()){ |
| | | return; |
| | | } |
| | | BigDecimal amount = dappFundFlowEntity.getAmount(); |
| | | //5%加权分红(people数量) |
| | | BigDecimal totalAmount = amount.multiply(new BigDecimal(AppContants.DAO_TEAM_PERK_PERCENT)).setScale(2, BigDecimal.ROUND_DOWN); |
| | | |
| | | BigDecimal perkAmount = amount.multiply(perkPercent).divide(perKNum, 8, BigDecimal.ROUND_DOWN); |
| | | if(BigDecimal.ZERO.compareTo(perkAmount) >= 0){ |
| | | |
| | | //沉淀数量 |
| | | BigDecimal tuanDuiAva = BigDecimal.ZERO; |
| | | |
| | | QueryWrapper<DappMemberEntity> daoOneQuery = new QueryWrapper<>(); |
| | | daoOneQuery.eq("level", MemberLevelEnum.DAO_1.getCode()); |
| | | List<DappMemberEntity> daoOnes = dappMemberDao.selectList(daoOneQuery); |
| | | if(CollUtil.isNotEmpty(daoOnes)){ |
| | | BigDecimal bigDecimal = totalAmount.multiply(new BigDecimal("0.5")).setScale(2, BigDecimal.ROUND_DOWN); |
| | | tuanDuiAva = tuanDuiAva.add(bigDecimal); |
| | | //每人平分数量 |
| | | BigDecimal divide = bigDecimal.divide(new BigDecimal(daoOnes.size()), 2, BigDecimal.ROUND_DOWN); |
| | | for(DappMemberEntity memberEntity : daoOnes){ |
| | | this.updateBalanceInsertFlow( |
| | | divide, |
| | | memberEntity.getId(), |
| | | MoneyFlowEnum.TEAM_ONE_PERK.getValue(), |
| | | StrUtil.format(MoneyFlowEnum.TEAM_ONE_PERK.getDescrition(),divide)); |
| | | } |
| | | } |
| | | |
| | | QueryWrapper<DappMemberEntity> daoTwoQuery = new QueryWrapper<>(); |
| | | daoTwoQuery.eq("level", MemberLevelEnum.DAO_2.getCode()); |
| | | List<DappMemberEntity> daoTwos = dappMemberDao.selectList(daoTwoQuery); |
| | | if(CollUtil.isNotEmpty(daoTwos)){ |
| | | BigDecimal bigDecimal = totalAmount.multiply(new BigDecimal("0.3")).setScale(2, BigDecimal.ROUND_DOWN); |
| | | tuanDuiAva = tuanDuiAva.add(bigDecimal); |
| | | //每人平分数量 |
| | | BigDecimal divide = bigDecimal.divide(new BigDecimal(daoTwos.size()), 2, BigDecimal.ROUND_DOWN); |
| | | for(DappMemberEntity memberEntity : daoTwos){ |
| | | this.updateBalanceInsertFlow( |
| | | divide, |
| | | memberEntity.getId(), |
| | | MoneyFlowEnum.TEAM_TWO_PERK.getValue(), |
| | | StrUtil.format(MoneyFlowEnum.TEAM_TWO_PERK.getDescrition(),divide)); |
| | | } |
| | | } |
| | | |
| | | QueryWrapper<DappMemberEntity> daoThreeQuery = new QueryWrapper<>(); |
| | | daoThreeQuery.eq("level", MemberLevelEnum.DAO_3.getCode()); |
| | | List<DappMemberEntity> daoThrees = dappMemberDao.selectList(daoThreeQuery); |
| | | if(CollUtil.isNotEmpty(daoThrees)){ |
| | | BigDecimal bigDecimal = totalAmount.multiply(new BigDecimal("0.2")).setScale(2, BigDecimal.ROUND_DOWN); |
| | | tuanDuiAva = tuanDuiAva.add(bigDecimal); |
| | | //每人平分数量 |
| | | BigDecimal divide = bigDecimal.divide(new BigDecimal(daoThrees.size()), 2, BigDecimal.ROUND_DOWN); |
| | | for(DappMemberEntity memberEntity : daoThrees){ |
| | | this.updateBalanceInsertFlow( |
| | | divide, |
| | | memberEntity.getId(), |
| | | MoneyFlowEnum.TEAM_THREE_PERK.getValue(), |
| | | StrUtil.format(MoneyFlowEnum.TEAM_THREE_PERK.getDescrition(),divide)); |
| | | } |
| | | } |
| | | |
| | | DataDictionaryCustom tuanDuiChiDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.TUAN_DUI_CHI.getType(), |
| | | DataDictionaryEnum.TUAN_DUI_CHI.getCode() |
| | | ); |
| | | BigDecimal tuanDuiAvaTotal = totalAmount.subtract(tuanDuiAva).setScale(2, BigDecimal.ROUND_DOWN); |
| | | if(BigDecimal.ZERO.compareTo(tuanDuiAvaTotal) < 0){ |
| | | BigDecimal tuanDuiChi = new BigDecimal(tuanDuiChiDic.getValue()).add(tuanDuiAvaTotal).setScale(2,BigDecimal.ROUND_DOWN); |
| | | tuanDuiChiDic.setValue(tuanDuiChi.toString()); |
| | | dataDictionaryCustomMapper.updateById(tuanDuiChiDic); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void MemberLevel(Long id) { |
| | | |
| | | DappMemberEntity dappMemberEntity = dappMemberDao.selectById(id); |
| | | if(StrUtil.isEmpty(dappMemberEntity.getRefererIds())){ |
| | | return; |
| | | } |
| | | //获取全部上级 |
| | | ArrayList<DappMemberEntity> activeMembers = new ArrayList<>(); |
| | | List<String> refererIds = Arrays.asList(StrUtil.split(dappMemberEntity.getRefererIds(),",")); |
| | | for(String inviteId : refererIds){ |
| | | DappMemberEntity memberEntity = dappMemberDao.selectMemberInfoByInviteId(inviteId); |
| | | if(ObjectUtil.isNotEmpty(memberEntity)){ |
| | | activeMembers.add(memberEntity); |
| | | } |
| | | } |
| | | if(CollUtil.isEmpty(activeMembers)){ |
| | | return; |
| | | } |
| | | |
| | | QueryWrapper<DappMemberEntity> objectQueryWrapper = new QueryWrapper<>(); |
| | | objectQueryWrapper.ge("buy_node",0); |
| | | List<DappMemberEntity> dappMemberEntities = dappMemberDao.selectList(objectQueryWrapper); |
| | | if(CollUtil.isEmpty(dappMemberEntities)){ |
| | | return; |
| | | } |
| | | |
| | | //奖励总份数 |
| | | BigDecimal totalPerkNum = BigDecimal.ZERO; |
| | | for(DappMemberEntity dappMemberEntity : dappMemberEntities){ |
| | | //如果账号未激活,则无法领取收益 |
| | | if(1 != dappMemberEntity.getActiveStatus()){ |
| | | for(DappMemberEntity activeMember : activeMembers){ |
| | | //获取每一个上级的所有直推,分辨大小区是否满足业绩需求 |
| | | List<DappMemberEntity> directMembers = dappMemberDao.selectChildMemberDirectOrNot(activeMember.getInviteId(), 1, null); |
| | | if(CollUtil.isEmpty(directMembers)){ |
| | | continue; |
| | | } |
| | | BigDecimal buyNode = new BigDecimal(dappMemberEntity.getBuyNode()); |
| | | totalPerkNum = totalPerkNum.add(buyNode); |
| | | if(perKNum.compareTo(totalPerkNum) < 0){ |
| | | return; |
| | | } |
| | | //奖励金额 |
| | | BigDecimal memberPerk = perkAmount.multiply(buyNode); |
| | | if(BigDecimal.ZERO.compareTo(memberPerk) >= 0){ |
| | | if(directMembers.size() < 2){ |
| | | continue; |
| | | } |
| | | dappWalletService.updateWalletCoinWithLock(memberPerk, dappMemberEntity.getId(), 1); |
| | | //获取activeMember的每一个直推的团队有效业绩 |
| | | HashMap<Long, BigDecimal> daXiaoQu = new HashMap<>(); |
| | | for(DappMemberEntity directMember : directMembers){ |
| | | //每一个直推的团队 |
| | | List<DappMemberEntity> direct = dappMemberDao.selectChildMemberDirectOrNot(directMember.getInviteId(), 2, null); |
| | | if(CollUtil.isEmpty(direct)){ |
| | | continue; |
| | | } |
| | | //获取直推的团队的全部有效业绩 |
| | | List<Long> collect = direct.stream().map(DappMemberEntity::getId).collect(Collectors.toList()); |
| | | QueryWrapper<DappStorage> storageQueryWrapper = new QueryWrapper<>(); |
| | | storageQueryWrapper.in("member_id",collect); |
| | | // storageQueryWrapper.eq("state",1); |
| | | List<DappStorage> dappStorages = dappStorageMapper.selectList(storageQueryWrapper); |
| | | if(CollUtil.isEmpty(dappStorages)){ |
| | | continue; |
| | | } |
| | | |
| | | DappFundFlowEntity fundFlow = new DappFundFlowEntity( |
| | | dappMemberEntity.getId(), |
| | | memberPerk, |
| | | 14, |
| | | 2, |
| | | BigDecimal.ZERO, |
| | | null); |
| | | dappFundFlowDao.insert(fundFlow); |
| | | BigDecimal directAchieve = dappStorages.stream() |
| | | .map(DappStorage::getAmount) // 映射amount到流中 |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | daXiaoQu.put(directMember.getId(),directAchieve); |
| | | } |
| | | if(daXiaoQu.isEmpty()){ |
| | | continue; |
| | | } |
| | | //输出小区的总业绩 |
| | | BigDecimal sum = sumExcludingMax(daXiaoQu); |
| | | BigDecimal dao_1_levelAchieve = new BigDecimal(MemberLevelEnum.DAO_1.getLevelAchieve()); |
| | | BigDecimal dao_2_levelAchieve = new BigDecimal(MemberLevelEnum.DAO_2.getLevelAchieve()); |
| | | BigDecimal dao_3_levelAchieve = new BigDecimal(MemberLevelEnum.DAO_3.getLevelAchieve()); |
| | | if(sum.compareTo(dao_3_levelAchieve) >= 0){ |
| | | activeMember.setLevel(MemberLevelEnum.DAO_3.getCode()); |
| | | dappMemberDao.updateById(activeMember); |
| | | }else if(sum.compareTo(dao_2_levelAchieve) >= 0 && sum.compareTo(dao_3_levelAchieve) < 0){ |
| | | activeMember.setLevel(MemberLevelEnum.DAO_2.getCode()); |
| | | dappMemberDao.updateById(activeMember); |
| | | }else if(sum.compareTo(dao_1_levelAchieve) >= 0 && sum.compareTo(dao_2_levelAchieve) < 0){ |
| | | activeMember.setLevel(MemberLevelEnum.DAO_1.getCode()); |
| | | dappMemberDao.updateById(activeMember); |
| | | }else{ |
| | | activeMember.setLevel(MemberLevelEnum.DAO_0.getCode()); |
| | | dappMemberDao.updateById(activeMember); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 计算HashMap中除最大值以外的数据的累计和 |
| | | * |
| | | * @param map 包含Long作为key和BigDecimal作为value的HashMap |
| | | * @return 除最大值以外的数据的累计和 |
| | | * @throws NullPointerException 如果HashMap为空,则抛出此异常 |
| | | */ |
| | | public static BigDecimal sumExcludingMax(HashMap<Long, BigDecimal> map) { |
| | | if (map == null) { |
| | | throw new NullPointerException("HashMap cannot be null"); |
| | | } |
| | | |
| | | log.info("买入贡献值-总人数{},-每人金额{}",dappMemberEntities.size(),perkAmount); |
| | | // 使用Stream API找到最大的BigDecimal值及其对应的key |
| | | Optional<Map.Entry<Long, BigDecimal>> maxEntry = map.entrySet().stream() |
| | | .max((e1, e2) -> e1.getValue().compareTo(e2.getValue())); |
| | | |
| | | // 检查是否找到了最大值 |
| | | if (maxEntry.isPresent()) { |
| | | // 移除最大值对应的键值对 |
| | | map.remove(maxEntry.get().getKey()); |
| | | |
| | | // 计算剩余数据的累计和 |
| | | BigDecimal sumOfRemaining = map.entrySet().stream() |
| | | .map(Map.Entry::getValue) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | |
| | | // 返回累计和 |
| | | return sumOfRemaining; |
| | | } else { |
| | | // 如果没有找到最大值(即HashMap为空),则返回BigDecimal.ZERO |
| | | return BigDecimal.ZERO; |
| | | } |
| | | } |
| | | |
| | | // 主函数,用于测试 |
| | | public static void main(String[] args) { |
| | | HashMap<Long, BigDecimal> map = new HashMap<>(); |
| | | map.put(1L, new BigDecimal("100.00")); |
| | | map.put(2L, new BigDecimal("200.00")); |
| | | map.put(4L, new BigDecimal("200.00")); |
| | | map.put(3L, new BigDecimal("50.00")); |
| | | |
| | | BigDecimal sum = sumExcludingMax(map); |
| | | System.out.println("Sum of remaining values excluding the maximum: " + sum); |
| | | } |
| | | |
| | | } |