cfgLowAchieve.put(ConstantUtil._lev_8, 200D);
cfgLowAchieve.put(ConstantUtil._lev_s_1, 300D);
cfgLowAchieve.put(ConstantUtil._lev_s_2, 300D);
cfgLowAchieve.put(ConstantUtil._lev_s_3, 300D);
/**遍历经销商,当前经销商已有职级等信息*/
TBounsConf bouns = null;
TDistributorBoun distBonus = null;
String distbutorCode = null;
for (TDistributor dist : allDistributors) {
distbutorCode = dist.getDistributorCode();
if(ConstantUtil._top_.equals(distbutorCode)){
continue;
}
distBonus = new TDistributorBoun();
/**经销商编码*/
distBonus.setDistributorCode(distbutorCode);
/**经销商ID*/
distBonus.setDistributorId(dist.getId());
/**计算日期*/
distBonus.setBounsDate(new Date());
tgGrade = tgMap.get(distbutorCode);/**业绩*/
Long rank = dist.getRankId(); /**职级*/
bouns = bonusCfgMap.get(rank); /**职级对应的奖金分类*/
/**计算之前,必须满足本月个人累计PV的最低消费额度****/
if(tgGrade.getPersonAchieve()>=cfgLowAchieve.get(rank)){
/***********************计算直接奖金***************/
distBonus.setDirectBouns(tgGrade.getDirectAchieve_BV()* bouns.getDirectP()/100);
/***********************计算间接奖金,见①和②***************************/
/**查询出所有直接下线*/
dirchildList = tDistributorService.findAllDirChildrenDistributors(dist.getId(), dist.getFloors()+1);
/**①查询出所有直接下线,直接下线中大于200BV的部分纳入间接奖*/
double directBouns =0D;
for(TDistributor dirChild: dirchildList){
/**若职级大于上线的职级,则获取不到它的间接奖*/
if(dirChild.getRankId()> rank){
continue;
}else{
/**获取当前节点直接奖比例*/
double dirChildBonus = bonusCfgMap.get(dirChild.getRankId()).getDirectP()/100;
/**累计当前的直接下线的间接奖*/
double dir = tgMap.get(dirChild.getDistributorCode()).getBonusAchieve();
directBouns += (dir>200D?(dir-200D ):0D)* (bouns.getDirectP()/100 - dirChildBonus);
}
}
/**查询出所有间接下线*/
indirchildList = tDistributorService.findAllIndirChildrenDistributors(dist.getId(), dist.getFloors()+1);
/**②查询出所有间接下线,间接下线中要分两部分计算间接奖,第一部分:大于200的部分,第二部分:小于等于200的部分纳入间接奖*/
double indirectBouns = 0D;
for(TDistributor indirChild: indirchildList){
/**获取当前节点直接奖比例*/
double dirChildBonus = bonusCfgMap.get(indirChild.getRankId()).getDirectP()/100;
/**indirChild本身的个人累计*/
double selfAchieve = tgMap.get(indirChild.getDistributorCode()).getBonusAchieve();
/**大于200的情况*/
if(selfAchieve>200 && indirChild.getRankId()<=rank){
/***超过200的部分*/
indirectBouns += (selfAchieve-200D )* (bouns.getDirectP()/100 - dirChildBonus);
/**等于200的部分,需要获取上级经销商的职级奖比例*/
indirectBouns += 200D*(bouns.getDirectP()/100-bonusCfgMap.get(tgMap.get(indirChild.getSponsorCode()).getRank()).getDirectP()/100);
/**小于等于200的情况*/
}else{
indirectBouns += selfAchieve*(bouns.getDirectP()/100-bonusCfgMap.get(tgMap.get(indirChild.getSponsorCode()).getRank()).getDirectP()/100);
}
indirChild = null;
}
distBonus.setIndirectBouns((directBouns + indirectBouns)<0D?0D:(directBouns + indirectBouns)); /**①+②*/
/**领导奖计算*/