|  |  |  | 
|---|
|  |  |  | DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.DYNAMIC_BONUS.getType(), DataDictionaryEnum.DYNAMIC_BONUS.getCode()); | 
|---|
|  |  |  | // 隔代字典 | 
|---|
|  |  |  | DataDictionaryCustom indrectDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.INDRECT_BONUS.getType(), DataDictionaryEnum.INDRECT_BONUS.getCode()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 直接父级 | 
|---|
|  |  |  | MallMember parent = mallMemberMapper.selectInfoByInviteId(member.getReferrerId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | // 减去成本后算收益 | 
|---|
|  |  |  | BigDecimal amount = item.getPrice().subtract(item.getCostPrice()).multiply(BigDecimal.valueOf(item.getCnt())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // =======直推返利== start ===== | 
|---|
|  |  |  | // 直接奖励收益 | 
|---|
|  |  |  | BigDecimal dynamicProfit = amount.divide(new BigDecimal(dic.getValue()), 2, RoundingMode.HALF_UP); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (StrUtil.isBlank(parent.getReferrerId())) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<String> parents = StrUtil.split(parent.getReferrerIds(), ','); | 
|---|
|  |  |  | List<MallMember> members = mallMemberMapper.selectByInviteIds(parents); | 
|---|
|  |  |  | if (CollUtil.isEmpty(members)) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 隔代比例 | 
|---|
|  |  |  | BigDecimal indrectDicProp = new BigDecimal(indrectDic.getValue()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 隔代推荐奖 收益 | 
|---|
|  |  |  | BigDecimal direct = dynamicProfit.divide(indrectDicProp, 2, RoundingMode.HALF_UP); | 
|---|
|  |  |  | for (MallMember parentMember : members) { | 
|---|
|  |  |  | if (parent.getInviteId().equals(parentMember.getInviteId())) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (direct.compareTo(BigDecimal.ONE) < 1) { | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | int reduce =  walletService.reduce(direct, parentMember.getId(), "score"); | 
|---|
|  |  |  | if (reduce == 2) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | walletService.add(direct, parentMember.getId(), "commission"); | 
|---|
|  |  |  | moneyFlowService.addMoneyFlow(parentMember.getId(), direct, MoneyFlowTypeEnum.RECOMMEND_BONUS.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.COMMISSION.getValue()); | 
|---|
|  |  |  | moneyFlowService.addMoneyFlow(parentMember.getId(), direct.negate(), MoneyFlowTypeEnum.RECOMMEND_BONUS.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.SCORE.getValue()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | direct = direct.divide(indrectDicProp, 2, RoundingMode.HALF_UP); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (dynamicProfit.compareTo(BigDecimal.ZERO) < 1) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | moneyFlowService.addMoneyFlow(parent.getId(), dynamicProfit, MoneyFlowTypeEnum.DYNAMIC_ACHIEVE.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.COMMISSION.getValue()); | 
|---|
|  |  |  | moneyFlowService.addMoneyFlow(parent.getId(), dynamicProfit.negate(), MoneyFlowTypeEnum.DYNAMIC_ACHIEVE.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.SCORE.getValue()); | 
|---|
|  |  |  | // =======直推返利== end ===== | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // =======隔代奖== start ===== | 
|---|
|  |  |  | if (StrUtil.isBlank(parent.getReferrerId())) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<String> parents = StrUtil.split(parent.getReferrerIds(), ','); | 
|---|
|  |  |  | List<MallMember> members = mallMemberMapper.selectByInviteIds(parents); | 
|---|
|  |  |  | if (CollUtil.isEmpty(members)) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 隔代比例 | 
|---|
|  |  |  | BigDecimal indrectDicProp = new BigDecimal(indrectDic.getValue()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 隔代推荐奖 收益 | 
|---|
|  |  |  | BigDecimal direct = dynamicProfit.divide(indrectDicProp, 2, RoundingMode.HALF_UP); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // direct 收益小于1,则跳出 | 
|---|
|  |  |  | if (direct.compareTo(BigDecimal.ONE) < 1) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (MallMember parentMember : members) { | 
|---|
|  |  |  | if (parent.getInviteId().equals(parentMember.getInviteId())) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | int reduceResult =  walletService.reduce(direct, parentMember.getId(), "score"); | 
|---|
|  |  |  | if (reduceResult == 2) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | walletService.add(direct, parentMember.getId(), "commission"); | 
|---|
|  |  |  | moneyFlowService.addMoneyFlow(parentMember.getId(), direct, MoneyFlowTypeEnum.RECOMMEND_BONUS.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.COMMISSION.getValue()); | 
|---|
|  |  |  | moneyFlowService.addMoneyFlow(parentMember.getId(), direct.negate(), MoneyFlowTypeEnum.RECOMMEND_BONUS.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.SCORE.getValue()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | direct = direct.divide(indrectDicProp, 2, RoundingMode.HALF_UP); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // =======隔代奖== end ===== | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public void agentProfit(Date profitDate) { | 
|---|
|  |  |  | log.info("#####==代理分红==start==#####"); | 
|---|
|  |  |  | if (profitDate == null) { | 
|---|