From 581e2ea0be32a78c23f18db85e27bd130041f0f3 Mon Sep 17 00:00:00 2001 From: KKSU <15274802129@163.com> Date: Fri, 05 Jul 2024 17:10:04 +0800 Subject: [PATCH] 逻辑 --- src/test/java/cc/mrbird/febs/MemberTest.java | 315 ++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 256 insertions(+), 59 deletions(-) diff --git a/src/test/java/cc/mrbird/febs/MemberTest.java b/src/test/java/cc/mrbird/febs/MemberTest.java index 3319332..e6da7cf 100644 --- a/src/test/java/cc/mrbird/febs/MemberTest.java +++ b/src/test/java/cc/mrbird/febs/MemberTest.java @@ -1,17 +1,6 @@ package cc.mrbird.febs; -import cc.mrbird.febs.common.contants.AppContants; -import cc.mrbird.febs.dapp.entity.DappMemberEntity; -import cc.mrbird.febs.dapp.entity.DataDictionaryCustom; -import cc.mrbird.febs.dapp.mapper.DappMemberDao; -import cc.mrbird.febs.dapp.mapper.DataDictionaryCustomMapper; -import cn.hutool.core.util.StrUtil; -import org.apache.commons.lang3.StringUtils; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; - -import java.util.List; /** * @author wzy @@ -20,52 +9,260 @@ @SpringBootTest public class MemberTest { - @Autowired - private DappMemberDao dappMemberDao; - - @Autowired - private DataDictionaryCustomMapper dataDictionaryCustomMapper; - - @Test - public void refererIdsTest() { - DappMemberEntity member = dappMemberDao.selectById(24); - - boolean flag = false; - String parentId = "35087336"; - 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; - } else { - ids += ("," + parentId); - } - - if (i <= 4) { - 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)){ - break; - } - if (parentMember.getRefererId().equals(parentMember.getInviteId())) { - flag = true; - } - } - member.setRefererIds(ids); - member.setFeeProfitIds(feeProfitIds); - } +// @Autowired +// private DappMemberService dappMemberService; +// @Autowired +// private DappFundFlowDao dappFundFlowDao; +// +// @Resource +// private DappSystemService dappSystemService; +// +// @Resource +// private DappStorageMapper dappStorageMapper; +// +// @Resource +// private DataDictionaryCustomMapper dataDictionaryCustomMapper; +// +// @Resource +// private DappMemberDao dappMemberDao; +// +// @Test +// public void register() {//注册 +// ConnectDto connectDto = new ConnectDto(); +// connectDto.setAddress("0x597e5F0EDB294e7d28EB10A95aa2EEcd169a2dd7"); +// connectDto.setInviteId("53609999"); +// dappMemberService.connect(connectDto); +// } +// +// @Test +// public void registerV2() {//存储 +// Long memberId = 348L; +// BigDecimal bigDecimal = new BigDecimal("500"); +// DappFundFlowEntity fundFlow = new DappFundFlowEntity( +// memberId, +// bigDecimal.abs(), +// MoneyFlowEnum.CUN_CHU.getValue(), +// 1, +// BigDecimal.ZERO, +// StrUtil.format(MoneyFlowEnum.CUN_CHU.getDescrition(),bigDecimal)); +// dappFundFlowDao.insert(fundFlow); +// +// } +// +// @Test +// public void registerV3() {//存储 +// dappSystemService.teamPerk(4360L); +// +// } +// +// @Test +// public void registerV4() {//存储 +// +// DataDictionaryCustom jiliChiDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( +// DataDictionaryEnum.JILI_CHI.getType(), +// DataDictionaryEnum.JILI_CHI.getCode() +// ); +// +// BigDecimal realAmount = BigDecimal.ZERO; +// //DAO永动激励池50% +// BigDecimal jiLiTotal = new BigDecimal(jiliChiDic.getValue()).multiply(new BigDecimal("0.5")).setScale(2, BigDecimal.ROUND_DOWN); +// if(BigDecimal.ZERO.compareTo(jiLiTotal) >= 0){ +// return; +// } +// +// +// /** +// * 其中50%给予当天大单排名激励前4名,40%、30%、20、10% +// */ +// BigDecimal daDanTotal = jiLiTotal.multiply(new BigDecimal("0.5")).setScale(2, BigDecimal.ROUND_DOWN); +// if(daDanTotal.compareTo(BigDecimal.ZERO) > 0){ +// +// int oneCount = 4; +// int twoCount = 3; +// int threeCount = 2; +// int fourCount = 1; +// int count = oneCount + twoCount + threeCount + fourCount; +// //每一份的奖励数量 +// BigDecimal everyAmount = daDanTotal.divide(new BigDecimal(count)); +// +// if(everyAmount.compareTo(BigDecimal.ZERO) > 0){ +// DappStorage dappStorageOne = dappStorageMapper.selectAmountByDesc(DateUtil.offsetDay(new Date(),0),0,1); +// if(ObjectUtil.isNotEmpty(dappStorageOne)){ +// BigDecimal multiply = everyAmount.multiply(new BigDecimal(oneCount)); +// dappSystemService.updateBalanceInsertFlow( +// multiply, +// dappStorageOne.getMemberId(), +// MoneyFlowEnum.DA_DAN_JI_LI_PERK.getValue(), +// StrUtil.format(MoneyFlowEnum.DA_DAN_JI_LI_PERK.getDescrition(),daDanTotal,multiply)); +// +// realAmount = realAmount.add(multiply); +// } +// DappStorage dappStorageTwo = dappStorageMapper.selectAmountByDesc(DateUtil.offsetDay(new Date(),0),1,1); +// if(ObjectUtil.isNotEmpty(dappStorageTwo)){ +// BigDecimal multiply = everyAmount.multiply(new BigDecimal(twoCount)); +// dappSystemService.updateBalanceInsertFlow( +// multiply, +// dappStorageTwo.getMemberId(), +// MoneyFlowEnum.DA_DAN_JI_LI_PERK.getValue(), +// StrUtil.format(MoneyFlowEnum.DA_DAN_JI_LI_PERK.getDescrition(),daDanTotal,multiply)); +// +// realAmount = realAmount.add(multiply); +// } +// DappStorage dappStorageThree = dappStorageMapper.selectAmountByDesc(DateUtil.offsetDay(new Date(),0),2,1); +// if(ObjectUtil.isNotEmpty(dappStorageThree)){ +// BigDecimal multiply = everyAmount.multiply(new BigDecimal(threeCount)); +// dappSystemService.updateBalanceInsertFlow( +// multiply, +// dappStorageThree.getMemberId(), +// MoneyFlowEnum.DA_DAN_JI_LI_PERK.getValue(), +// StrUtil.format(MoneyFlowEnum.DA_DAN_JI_LI_PERK.getDescrition(),daDanTotal,multiply)); +// +// realAmount = realAmount.add(multiply); +// } +// DappStorage dappStorageFour = dappStorageMapper.selectAmountByDesc(DateUtil.offsetDay(new Date(),0),3,1); +// if(ObjectUtil.isNotEmpty(dappStorageFour)){ +// BigDecimal multiply = everyAmount.multiply(new BigDecimal(fourCount)); +// dappSystemService.updateBalanceInsertFlow( +// multiply, +// dappStorageFour.getMemberId(), +// MoneyFlowEnum.DA_DAN_JI_LI_PERK.getValue(), +// StrUtil.format(MoneyFlowEnum.DA_DAN_JI_LI_PERK.getDescrition(),daDanTotal,multiply)); +// +// realAmount = realAmount.add(multiply); +// } +// } +// } +// +// /** +// * 另外50% 给予当天直推总业绩排名激励前10名,第1名40%,2-4名30%,5-10名30% +// */ +// BigDecimal directTotal = jiLiTotal.multiply(new BigDecimal("0.5")).setScale(2, BigDecimal.ROUND_DOWN); +// /** +// * 存放直推业绩<上级的memberId,直推总业绩> +// */ +// HashMap<Long, BigDecimal> map = new HashMap<>(); +// +// List<DappStorage> dappStorages = dappStorageMapper.selectListByDate(DateUtil.offsetDay(new Date(),0)); +// 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()); +// +// int startNum = 1; +// for (Map.Entry<Long, BigDecimal> entry : topTenEntries) { +// +// Long memberId = entry.getKey(); +// BigDecimal directAchieve = entry.getValue(); +// //第一名 +// if(startNum == 1){ +// BigDecimal bigDecimal = directTotal.multiply(new BigDecimal("0.4")).setScale(2, BigDecimal.ROUND_DOWN); +// dappSystemService.updateBalanceInsertFlow( +// bigDecimal, +// memberId, +// MoneyFlowEnum.ZHI_TUI_JI_LI_PERK.getValue(), +// StrUtil.format(MoneyFlowEnum.ZHI_TUI_JI_LI_PERK.getDescrition(),directAchieve,startNum,bigDecimal)); +// +// realAmount = realAmount.add(bigDecimal); +// }else if(startNum > 1 && startNum <=4){ +// BigDecimal bigDecimal = directTotal.multiply(new BigDecimal("0.3")).setScale(2, BigDecimal.ROUND_DOWN); +// BigDecimal divide = bigDecimal.divide(new BigDecimal("3"), 2, BigDecimal.ROUND_DOWN); +// +// dappSystemService.updateBalanceInsertFlow( +// divide, +// memberId, +// MoneyFlowEnum.ZHI_TUI_JI_LI_PERK.getValue(), +// StrUtil.format(MoneyFlowEnum.ZHI_TUI_JI_LI_PERK.getDescrition(),directAchieve,startNum,divide)); +// +// realAmount = realAmount.add(divide); +// }else{ +// BigDecimal bigDecimal = directTotal.multiply(new BigDecimal("0.3")).setScale(2, BigDecimal.ROUND_DOWN); +// BigDecimal divide = bigDecimal.divide(new BigDecimal("6"), 2, BigDecimal.ROUND_DOWN); +// +// dappSystemService.updateBalanceInsertFlow( +// divide, +// memberId, +// MoneyFlowEnum.ZHI_TUI_JI_LI_PERK.getValue(), +// StrUtil.format(MoneyFlowEnum.ZHI_TUI_JI_LI_PERK.getDescrition(),directAchieve,startNum,divide)); +// +// realAmount = realAmount.add(divide); +// } +// startNum = startNum + 1; +// } +// } +// +// BigDecimal subtract = new BigDecimal(jiliChiDic.getValue()).subtract(realAmount); +// jiliChiDic.setValue(subtract.toString()); +// dataDictionaryCustomMapper.updateById(jiliChiDic); +// } +// @Test +// public void testv5(){ +// Long memberId = 1L; +// List<TeamDownVo> objects = new ArrayList<>(); +// +// DappMemberEntity memberEntity = dappMemberDao.selectById(memberId); +// List<DappMemberEntity> directMembers = dappMemberDao.selectChildMemberDirectOrNot(memberEntity.getInviteId(), 1, null); +// +// if(CollUtil.isNotEmpty(directMembers)){ +// +// for(DappMemberEntity directMember : directMembers){ +// TeamDownVo teamDownVo = new TeamDownVo(); +// +// +// +// teamDownVo.setAddress(directMember.getAddress()); +// List<DappMemberEntity> teamMembers = dappMemberDao.selectChildMemberDirectOrNot(directMember.getInviteId(), 2, null); +// if(CollUtil.isEmpty(teamMembers)){ +// teamDownVo.setActiveCnt(0); +// teamDownVo.setActiveAchieve(BigDecimal.ZERO); +// }else{ +// List<DappMemberEntity> teamCntAva = teamMembers.stream().filter(dappMemberEntity -> dappMemberEntity.getActiveStatus() == 1).collect(Collectors.toList()); +// List<Long> collectTeam = teamCntAva.stream().map(DappMemberEntity::getId).collect(Collectors.toList()); +// +// if(CollUtil.isNotEmpty(collectTeam)){ +// QueryWrapper<DappStorage> collectTeamWrapper = new QueryWrapper<>(); +// collectTeamWrapper.in("member_id",collectTeam); +// collectTeamWrapper.eq("state",1); +// List<DappStorage> dappStoragesTeam = dappStorageMapper.selectList(collectTeamWrapper); +// BigDecimal teamAchieve = dappStoragesTeam.stream() +// .map(DappStorage::getAmount) // 映射amount到流中 +// .reduce(BigDecimal.ZERO, BigDecimal::add); +// +// teamDownVo.setActiveCnt(teamCntAva.size()); +// teamDownVo.setActiveAchieve(teamAchieve); +// }else{ +// teamDownVo.setActiveCnt(0); +// teamDownVo.setActiveAchieve(BigDecimal.ZERO); +// } +// } +// +// objects.add(teamDownVo); +// } +// } +// System.out.println(objects); +// } } -- Gitblit v1.9.1