Commit 05ea4456 authored by licc's avatar licc

优化月度肥料任务

parent 0b532595
...@@ -212,6 +212,9 @@ public class DayTaskServiceImpl implements DayTaskService { ...@@ -212,6 +212,9 @@ public class DayTaskServiceImpl implements DayTaskService {
return R.ok(0, true); return R.ok(0, true);
} }
//如果用户的团队业绩不存在的,新增本月团队业绩
addTeamPerformance(userList);
boolean bool = monthlyIncome(totalMoney, userList); boolean bool = monthlyIncome(totalMoney, userList);
if (!bool) { if (!bool) {
return R.ok(1, false); return R.ok(1, false);
...@@ -238,81 +241,81 @@ public class DayTaskServiceImpl implements DayTaskService { ...@@ -238,81 +241,81 @@ public class DayTaskServiceImpl implements DayTaskService {
totalMoney = totalMoney.add(orderInfo.getPayment()); totalMoney = totalMoney.add(orderInfo.getPayment());
} }
double number = Math.floor(totalMoney.doubleValue() / 3980 / 12); double number = Math.floor(totalMoney.doubleValue() / 3980 / 12);
if (number == 0) {
return R.ok(0, true);
}
//1、判断当前月是否是业绩开始的第一个月 //1、判断当前月是否是业绩开始的第一个月
List<TeamPerformance> teamPerformances = teamPerformanceMapper.getByBeforeTime(yearMonth); List<TeamPerformance> teamPerformances = teamPerformanceMapper.getByBeforeTime(yearMonth);
//2、集合为空 是业绩开始的第一个月 //2、集合为空 是业绩开始的第一个月
if (CollectionUtils.isEmpty(teamPerformances)) { if (CollectionUtils.isEmpty(teamPerformances)) {
if (number != 0) { //获取月业绩前20用户
//获取月业绩前20用户 List<TeamPerformance> list = teamPerformanceMapper.userTwenty(yearMonth);
List<TeamPerformance> list = teamPerformanceMapper.userTwenty(yearMonth); if (CollectionUtils.isEmpty(list)) {
if (CollectionUtils.isEmpty(list)) { return R.ok(0, true);
return R.ok(0, true); }
}
//获取20名进步最大的月业绩和 //获取20名进步最大的月业绩和
Double twentyTotal = teamPerformanceMapper.countTwenty(yearMonth); Double twentyTotal = teamPerformanceMapper.countTwenty(yearMonth);
List<AccountInfo> accountInfoList = new ArrayList<>(); List<AccountInfo> accountInfoList = new ArrayList<>();
List<TradeRecord> tradeRecordList = new ArrayList<>(); List<TradeRecord> tradeRecordList = new ArrayList<>();
List<ProgressPrize> addPrizeList = new ArrayList<>(); List<ProgressPrize> addPrizeList = new ArrayList<>();
List<ProgressPrize> updatePrizeList = new ArrayList<>(); List<ProgressPrize> updatePrizeList = new ArrayList<>();
for (TeamPerformance user : list) { for (TeamPerformance user : list) {
//获取最大进步奖 百分比 //获取最大进步奖 百分比
MemberPercent memberPercent = memberPercentMapper.getByLevelAndType(user.getUserLevel(), MemberPercent memberPercent = memberPercentMapper.getByLevelAndType(user.getUserLevel(),
MemberPercentEnum.MONTH_BEST_AWARD.getCode()); MemberPercentEnum.MONTH_BEST_AWARD.getCode());
//计算收益
double userTeamPerformance = user.getMonthTeamPerformance().doubleValue();
double percent = memberPercent.getPercent().doubleValue();
double income = Math.floor(number * 3980 * percent * userTeamPerformance / twentyTotal);
//获取账户信息 //计算收益
AccountInfo accountInfo = accountMapper.getByUserId(user.getUserId()); double userTeamPerformance = user.getMonthTeamPerformance().doubleValue();
double percent = memberPercent.getPercent().doubleValue();
double income = Math.floor(number * 3980 * percent * userTeamPerformance / twentyTotal);
//用户月收益 =其他收益+最大进步奖收益 //获取账户信息
BigDecimal earningsMonth = accountInfo.getEarningsMonth().add(BigDecimal.valueOf(income)); AccountInfo accountInfo = accountMapper.getByUserId(user.getUserId());
accountInfo.setEarningsMonth(earningsMonth);
//用户总收益 =其他总收益 + 最大进步奖收益 //用户月收益 =其他收益+最大进步奖收益
BigDecimal earningsTotal = accountInfo.getEarningsTotal().add(BigDecimal.valueOf(income)); BigDecimal earningsMonth = accountInfo.getEarningsMonth().add(BigDecimal.valueOf(income));
accountInfo.setEarningsTotal(earningsTotal); accountInfo.setEarningsMonth(earningsMonth);
accountInfoList.add(accountInfo);
//添加最大进步奖信息 不存在:新增 存在,修改 //用户总收益 =其他总收益 + 最大进步奖收益
BigDecimal awardMoney = new BigDecimal(income).setScale(2, RoundingMode.HALF_UP); BigDecimal earningsTotal = accountInfo.getEarningsTotal().add(BigDecimal.valueOf(income));
ProgressPrize progressPrize = progressPrizeMapper.getByUserIdYearMonth(user.getUserId(), yearMonth); accountInfo.setEarningsTotal(earningsTotal);
if (null == progressPrize) { accountInfoList.add(accountInfo);
ProgressPrize prize = new ProgressPrize();
prize.setAwardMoney(awardMoney.doubleValue());
prize.setUserId(user.getUserId());
prize.setGrowthRate(0.0);
prize.setYearMonth(yearMonth);
addPrizeList.add(prize);
} else {
progressPrize.setYearMonth(yearMonth);
progressPrize.setAwardMoney(awardMoney.doubleValue());
updatePrizeList.add(progressPrize);
}
//添加交易流水记录 //添加最大进步奖信息 不存在:新增 存在,修改
TradeRecord tradeRecord = new TradeRecord(); BigDecimal awardMoney = new BigDecimal(income).setScale(2, RoundingMode.HALF_UP);
tradeRecord.setUserId(user.getUserId()); ProgressPrize progressPrize = progressPrizeMapper.getByUserIdYearMonth(user.getUserId(), yearMonth);
tradeRecord.setTradeType(TradeRecordEnum.PROGRESS_PRIZE.getCode()); if (null == progressPrize) {
tradeRecord.setTradeNo(null); ProgressPrize prize = new ProgressPrize();
tradeRecord.setStatus(TradeStatusEnum.NO_SETTLE_ACCOUNTS.getCode()); prize.setAwardMoney(awardMoney.doubleValue());
tradeRecord.setMoney(BigDecimal.valueOf(income)); prize.setUserId(user.getUserId());
tradeRecordList.add(tradeRecord); prize.setGrowthRate(0.0);
prize.setYearMonth(yearMonth);
addPrizeList.add(prize);
} else {
progressPrize.setYearMonth(yearMonth);
progressPrize.setAwardMoney(awardMoney.doubleValue());
updatePrizeList.add(progressPrize);
} }
//更新账户信息,添加交易流水记录 //添加交易流水记录
boolean bool = accountManager.updateAccountAddRecordAddPrize(accountInfoList, tradeRecordList, TradeRecord tradeRecord = new TradeRecord();
addPrizeList, updatePrizeList); tradeRecord.setUserId(user.getUserId());
if (!bool) { tradeRecord.setTradeType(TradeRecordEnum.PROGRESS_PRIZE.getCode());
return R.ok(1, false); tradeRecord.setTradeNo(null);
} tradeRecord.setStatus(TradeStatusEnum.NO_SETTLE_ACCOUNTS.getCode());
tradeRecord.setMoney(BigDecimal.valueOf(income));
tradeRecordList.add(tradeRecord);
}
//更新账户信息,添加交易流水记录
boolean bool = accountManager.updateAccountAddRecordAddPrize(accountInfoList, tradeRecordList,
addPrizeList, updatePrizeList);
if (!bool) {
return R.ok(1, false);
} }
log.info("本月最大进步奖日定时任务执行成功");
return R.ok(0, true); return R.ok(0, true);
} }
...@@ -463,7 +466,9 @@ public class DayTaskServiceImpl implements DayTaskService { ...@@ -463,7 +466,9 @@ public class DayTaskServiceImpl implements DayTaskService {
if (null != memberPercent) { if (null != memberPercent) {
//获取本月团队总金额 //获取本月团队总金额
TeamPerformance teamPerformance = teamPerformanceMapper.getByUserIdAndTime(user.getUserId(), yearMonth); TeamPerformance teamPerformance = teamPerformanceMapper.getByUserIdAndTime(user.getUserId(), yearMonth);
if(null ==teamPerformance){
}
//获取该等级团队总金额 //获取该等级团队总金额
Double teamTotal = teamPerformanceMapper.countTeamMoney(user.getUserLevel(), yearMonth); Double teamTotal = teamPerformanceMapper.countTeamMoney(user.getUserLevel(), yearMonth);
if (null != teamPerformance && null != teamTotal) { if (null != teamPerformance && null != teamTotal) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment