| | |
| | | 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.LevelProfitEnum; |
| | | import cc.mrbird.febs.dapp.mapper.*; |
| | | import cc.mrbird.febs.dapp.service.DappSystemService; |
| | | import cc.mrbird.febs.dapp.service.DappWalletService; |
| | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.date.DateUnit; |
| | | 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 lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | private final DappAchieveMemberTreeDao dappAchieveMemberTreeDao; |
| | | private final DappWalletService dappWalletService; |
| | | private final DataDictionaryCustomMapper dataDictionaryCustomMapper; |
| | | private final DappSystemProfitDao dappSystemProfitDao; |
| | | |
| | | |
| | | @Override |
| | |
| | | dappFundFlowDao.insert(profitFlow); |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void levelProfit(Long id) { |
| | | DappSystemProfit dappSystemProfit = dappSystemProfitDao.selectById(id); |
| | | if(ObjectUtil.isEmpty(dappSystemProfit)){ |
| | | return; |
| | | } |
| | | Long memberId = dappSystemProfit.getMemberId(); |
| | | //获取用户的上级用户信息 |
| | | DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberId); |
| | | if(ObjectUtil.isEmpty(dappMemberEntity)){ |
| | | return; |
| | | } |
| | | String refererIds = dappMemberEntity.getRefererIds(); |
| | | if(StrUtil.isEmpty(refererIds)){ |
| | | return; |
| | | } |
| | | DataDictionaryCustom levelProfitSet = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.LEVEL_PROFIT.getType(), DataDictionaryEnum.LEVEL_PROFIT.getCode()); |
| | | BigDecimal levelProfit = new BigDecimal(StrUtil.isEmpty(levelProfitSet.getValue()) ? "0.3" : levelProfitSet.getValue()); |
| | | //投入金额减去技术方收益 |
| | | DataDictionaryCustom systemProfitSet = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.SYSTEM_PROFIT.getType(), DataDictionaryEnum.SYSTEM_PROFIT.getCode()); |
| | | BigDecimal systemProfit = new BigDecimal(StrUtil.isEmpty(systemProfitSet.getValue()) ? "0.05" : systemProfitSet.getValue()); |
| | | BigDecimal amount = dappSystemProfit.getAmount().subtract(systemProfit); |
| | | //层级奖励总奖金 |
| | | BigDecimal levelProfitTotal = amount.multiply(levelProfit); |
| | | //实发层级奖励 -- 如果还有剩余给技术方 |
| | | BigDecimal systemProfitTotal = BigDecimal.ZERO; |
| | | //返回十层 |
| | | List<String> refererIdList = StrUtil.split(refererIds, ','); |
| | | //i:计数层数,同时i也为对应层数应推广的人数,当达到对应的直推人数时,才能获取对应层级奖励 |
| | | for(int i = 0;i < 10; i++){ |
| | | if(systemProfitTotal.compareTo(levelProfitTotal) < 0){ |
| | | String inviteId = refererIdList.get(i); |
| | | //获取每层用户的直推人数,判断能否获得这个层级的层级奖励 |
| | | DappMemberEntity refererMember = dappMemberDao.selectMemberInfoByInviteId(inviteId); |
| | | //获取直推用户数量 |
| | | QueryWrapper<DappMemberEntity> objectQueryWrapper = new QueryWrapper<>(); |
| | | objectQueryWrapper.eq("referer_id",refererMember.getInviteId()); |
| | | Integer selectCount = dappMemberDao.selectCount(objectQueryWrapper); |
| | | if(i > selectCount){ |
| | | continue; |
| | | } |
| | | //获取对应层级奖励 |
| | | BigDecimal profit = LevelProfitEnum.YI.getProfit(i); |
| | | BigDecimal memberLevelProfit = levelProfitTotal.multiply(profit); |
| | | |
| | | DappFundFlowEntity fundFlow = new DappFundFlowEntity(refererMember.getId(), memberLevelProfit, 4, 2, BigDecimal.ZERO,null,dappSystemProfit.getId()); |
| | | dappFundFlowDao.insert(fundFlow); |
| | | systemProfitTotal = systemProfitTotal.add(memberLevelProfit); |
| | | } |
| | | } |
| | | //如果还有剩余给技术方 |
| | | if(levelProfitTotal.compareTo(systemProfitTotal) > 0){ |
| | | BigDecimal avaProfit = levelProfitTotal.subtract(systemProfit); |
| | | DappFundFlowEntity fundFlow = new DappFundFlowEntity(memberId, avaProfit, 5, 2, BigDecimal.ZERO,null,dappSystemProfit.getId()); |
| | | dappFundFlowDao.insert(fundFlow); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void memberOut(Long id) { |
| | | //获取当前是第几轮队列 |
| | | //判断当前是否符合出局条件 |
| | | //符合则出局,轮数+1 |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | String refererIds = "1,2,3,4,5," + |
| | | "6,7,8,9,10," + |
| | | "11,12,13,14,15"; |
| | | List<String> refererIdList = StrUtil.split(refererIds, ','); |
| | | System.out.println(refererIdList); |
| | | } |
| | | } |