|
@@ -23,6 +23,8 @@ import cn.newfeifan.mall.module.distri.service.partitionbrothers.PartitionBrothe
|
|
import cn.newfeifan.mall.module.distri.service.partitionson.PartitionSonService;
|
|
import cn.newfeifan.mall.module.distri.service.partitionson.PartitionSonService;
|
|
import cn.newfeifan.mall.module.distri.service.ptprofit.PtProfitService;
|
|
import cn.newfeifan.mall.module.distri.service.ptprofit.PtProfitService;
|
|
import cn.newfeifan.mall.module.distri.service.ptprofitlog.PtProfitLogService;
|
|
import cn.newfeifan.mall.module.distri.service.ptprofitlog.PtProfitLogService;
|
|
|
|
+import cn.newfeifan.mall.module.member.dal.dataobject.user.MemberUserDO;
|
|
|
|
+import cn.newfeifan.mall.module.member.service.user.MemberUserService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -99,6 +101,8 @@ public class PartitionCrashServiceImpl implements PartitionCrashService {
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
private DailyAwardRecordsService dailyAwardRecordsService;
|
|
private DailyAwardRecordsService dailyAwardRecordsService;
|
|
|
|
+ @Resource
|
|
|
|
+ private MemberUserService memberUserService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -171,10 +175,16 @@ public class PartitionCrashServiceImpl implements PartitionCrashService {
|
|
List<PartitionBrothersSaveReqVO> partitionBrothersSaveReqVOS = new ArrayList<>();
|
|
List<PartitionBrothersSaveReqVO> partitionBrothersSaveReqVOS = new ArrayList<>();
|
|
List<PartitionCrashSaveReqVO> partitionCrashSaveReqVOS = new ArrayList<>();
|
|
List<PartitionCrashSaveReqVO> partitionCrashSaveReqVOS = new ArrayList<>();
|
|
|
|
|
|
|
|
+ // 本来在下面,搬上来,因为游客收益要扣减
|
|
|
|
+ IntegralDO ptIntegralDO = integralService.selectByUser(PT_ID);
|
|
|
|
+
|
|
duserDOS.forEach(k -> {
|
|
duserDOS.forEach(k -> {
|
|
|
|
|
|
// 获取当前用户的钱包
|
|
// 获取当前用户的钱包
|
|
IntegralDO integralDO = integralService.selectByUser(k.getUserId());
|
|
IntegralDO integralDO = integralService.selectByUser(k.getUserId());
|
|
|
|
+ // 获取当前用户信息
|
|
|
|
+ MemberUserDO user = memberUserService.getUser(k.getUserId());
|
|
|
|
+
|
|
// 获取当前父亲的钱包
|
|
// 获取当前父亲的钱包
|
|
Long parent = sonAndParent.get(k.getUserId());
|
|
Long parent = sonAndParent.get(k.getUserId());
|
|
IntegralDO parentIntegralDo = integralService.selectByUser(parent);
|
|
IntegralDO parentIntegralDo = integralService.selectByUser(parent);
|
|
@@ -217,7 +227,7 @@ public class PartitionCrashServiceImpl implements PartitionCrashService {
|
|
sonBuilder.price(sonSumPrice);
|
|
sonBuilder.price(sonSumPrice);
|
|
|
|
|
|
// 获取当前用户的兄弟分区
|
|
// 获取当前用户的兄弟分区
|
|
- List<OrderCalcDO> brothersOrderCalcDOS = sharePathService.selectBrothers(k.getUserId(), userId);
|
|
|
|
|
|
+ List<OrderCalcDO> brothersOrderCalcDOS = sharePathService.selectBrothers(k.getUserId(), userId, user);
|
|
if (brothersOrderCalcDOS.isEmpty()) {
|
|
if (brothersOrderCalcDOS.isEmpty()) {
|
|
// 插入空数据
|
|
// 插入空数据
|
|
brotherBuilder = addBrotherEmpty(brotherBuilder, k);
|
|
brotherBuilder = addBrotherEmpty(brotherBuilder, k);
|
|
@@ -293,59 +303,84 @@ public class PartitionCrashServiceImpl implements PartitionCrashService {
|
|
integralDO.setAccumulatedQuota(integralDO.getAccumulatedQuota() + amount);
|
|
integralDO.setAccumulatedQuota(integralDO.getAccumulatedQuota() + amount);
|
|
// 碰撞后的额度添加到日志中 增加日志模块
|
|
// 碰撞后的额度添加到日志中 增加日志模块
|
|
integralService.updateIntegral(BeanUtils.toBean(integralDO, IntegralSaveReqVO.class));
|
|
integralService.updateIntegral(BeanUtils.toBean(integralDO, IntegralSaveReqVO.class));
|
|
- Long logId = ptProfitLogService.addMessageFreeze(integralDO.getUserId(),integralDO.getUserId(), CaclEnum.SMALL_QUOTA_CRASH, amount,
|
|
|
|
|
|
+ Long logId = ptProfitLogService.addMessageFreeze(integralDO.getUserId(), integralDO.getUserId(), CaclEnum.SMALL_QUOTA_CRASH, amount,
|
|
integralDO.getFreezeQuota(), JsonUtils.toJsonString(orderPercentageDO), ptReplenish, -amount, highQuota - amount);
|
|
integralDO.getFreezeQuota(), JsonUtils.toJsonString(orderPercentageDO), ptReplenish, -amount, highQuota - amount);
|
|
|
|
|
|
//记录每日用户有合赢将的记录,后面用来结算的
|
|
//记录每日用户有合赢将的记录,后面用来结算的
|
|
- dailyAwardRecordsService.addDailyAwardRecords(integralDO.getUserId(),integralDO.getUserId(),amount, logId,ptReplenish);
|
|
|
|
|
|
+ dailyAwardRecordsService.addDailyAwardRecords(integralDO.getUserId(), integralDO.getUserId(), amount, logId, ptReplenish);
|
|
|
|
+ }
|
|
|
|
+ if (!ptReplenish.equals(0L)) {
|
|
|
|
+ calcIntegral(ptReplenish, integralDO.getUserId(), JsonUtils.toJsonString(orderPercentageDO));
|
|
}
|
|
}
|
|
|
|
|
|
- //直推人的上级的本次添加积分
|
|
|
|
- Long parentAmount = 0L;
|
|
|
|
- //平台需要补回的收益(也可以理解为用户溢出)
|
|
|
|
- Long parentPtReplenish = multiply.longValue();
|
|
|
|
- //直推人的父级
|
|
|
|
- if (multiply.longValue() != 0) {
|
|
|
|
- if (parentHighQuota.compareTo(0L) > 0) {
|
|
|
|
- if (parentHighQuota.compareTo(multiply.longValue()) > 0) {
|
|
|
|
- parentAmount = multiply.longValue();
|
|
|
|
- parentPtReplenish = 0L;
|
|
|
|
- } else {
|
|
|
|
- parentAmount = highQuota;
|
|
|
|
- parentPtReplenish = multiply.longValue() - highQuota;
|
|
|
|
|
|
+ // 获取计算后积分, Long为userId, Integer为碰撞后额度
|
|
|
|
+ HashMap<Long, Long> map = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ // 当用户为游客的时候上级不参与合赢奖
|
|
|
|
+ if (!user.getVisitor()) {
|
|
|
|
+ //直推人的上级的本次添加积分
|
|
|
|
+ Long parentAmount = 0L;
|
|
|
|
+ //平台需要补回的收益(也可以理解为用户溢出)
|
|
|
|
+ Long parentPtReplenish = multiply.longValue();
|
|
|
|
+ //直推人的父级
|
|
|
|
+ if (multiply.longValue() != 0) {
|
|
|
|
+ if (parentHighQuota.compareTo(0L) > 0) {
|
|
|
|
+ if (parentHighQuota.compareTo(multiply.longValue()) > 0) {
|
|
|
|
+ parentAmount = multiply.longValue();
|
|
|
|
+ parentPtReplenish = 0L;
|
|
|
|
+ } else {
|
|
|
|
+ parentAmount = highQuota;
|
|
|
|
+ parentPtReplenish = multiply.longValue() - highQuota;
|
|
|
|
+ }
|
|
|
|
+ addHighQuota(userHighQuotaMap, parentIntegralDo.getUserId(), parentAmount);
|
|
}
|
|
}
|
|
- addHighQuota(userHighQuotaMap, parentIntegralDo.getUserId(), parentAmount);
|
|
|
|
|
|
+ // 减去最高额度
|
|
|
|
+ parentIntegralDo.setHighQuota(parentIntegralDo.getHighQuota() - parentAmount);
|
|
|
|
+ parentIntegralDo.setFreezeQuota(parentIntegralDo.getFreezeQuota() + parentAmount);
|
|
|
|
+
|
|
|
|
+ parentIntegralDo.setAccumulatedQuota(parentIntegralDo.getAccumulatedQuota() + parentAmount);
|
|
|
|
+ // 碰撞后的额度添加到日志中 增加日志模块
|
|
|
|
+ integralService.updateIntegral(BeanUtils.toBean(parentIntegralDo, IntegralSaveReqVO.class));
|
|
|
|
+ Long logId = ptProfitLogService.addMessageFreeze(parentIntegralDo.getUserId(), integralDO.getUserId(), CaclEnum.SMALL_QUOTA_CRASH, parentAmount,
|
|
|
|
+ parentIntegralDo.getFreezeQuota(), JsonUtils.toJsonString(orderPercentageDO), parentPtReplenish, -parentAmount, parentHighQuota - parentAmount);
|
|
|
|
+
|
|
|
|
+ //记录每日用户有合赢将的记录,后面用来结算的
|
|
|
|
+ dailyAwardRecordsService.addDailyAwardRecords(parentIntegralDo.getUserId(), integralDO.getUserId(), parentAmount, logId, parentPtReplenish);
|
|
}
|
|
}
|
|
- // 减去最高额度
|
|
|
|
- parentIntegralDo.setHighQuota(parentIntegralDo.getHighQuota() - parentAmount);
|
|
|
|
- parentIntegralDo.setFreezeQuota(parentIntegralDo.getFreezeQuota() + parentAmount);
|
|
|
|
-
|
|
|
|
- parentIntegralDo.setAccumulatedQuota(parentIntegralDo.getAccumulatedQuota() + parentAmount);
|
|
|
|
- // 碰撞后的额度添加到日志中 增加日志模块
|
|
|
|
- integralService.updateIntegral(BeanUtils.toBean(parentIntegralDo, IntegralSaveReqVO.class));
|
|
|
|
- Long logId = ptProfitLogService.addMessageFreeze(parentIntegralDo.getUserId(),integralDO.getUserId(), CaclEnum.SMALL_QUOTA_CRASH, parentAmount,
|
|
|
|
- parentIntegralDo.getFreezeQuota(), JsonUtils.toJsonString(orderPercentageDO), parentPtReplenish, -parentAmount, parentHighQuota - parentAmount);
|
|
|
|
|
|
|
|
- //记录每日用户有合赢将的记录,后面用来结算的
|
|
|
|
- dailyAwardRecordsService.addDailyAwardRecords(parentIntegralDo.getUserId(),integralDO.getUserId(),parentAmount,logId,parentPtReplenish);
|
|
|
|
- }
|
|
|
|
|
|
+ if (!parentPtReplenish.equals(0L)) {
|
|
|
|
+ calcIntegral(parentPtReplenish, parentIntegralDo.getUserId(), JsonUtils.toJsonString(orderPercentageDO));
|
|
|
|
+ }
|
|
|
|
|
|
- if (!ptReplenish.equals(0L)) {
|
|
|
|
- calcIntegral(ptReplenish, integralDO.getUserId(), JsonUtils.toJsonString(orderPercentageDO));
|
|
|
|
- }
|
|
|
|
- if (!parentPtReplenish.equals(0L)) {
|
|
|
|
- calcIntegral(parentPtReplenish, parentIntegralDo.getUserId(), JsonUtils.toJsonString(orderPercentageDO));
|
|
|
|
|
|
+ if (!parentIntegralDo.getUserId().equals(PT_ID)) {
|
|
|
|
+ map.put(parentIntegralDo.getUserId(), parentAmount);
|
|
|
|
+ }
|
|
|
|
+ } else if (multiply.longValue() != 0) {
|
|
|
|
+ // 如果当前用户是游客,将上级推荐将加入到游客收益中,不算入到翁总的合赢奖
|
|
|
|
+ Long visitorEarnings = multiply.longValue(); //单笔收益
|
|
|
|
+
|
|
|
|
+ // 获取平台的游客收益
|
|
|
|
+ PtProfitDO ptProfit = ptProfitService.getPtProfit();
|
|
|
|
+ ptProfit.setVisitorEarnings(ptProfit.getVisitorEarnings() + visitorEarnings);
|
|
|
|
+ ptProfit.setPtGrossAdd(ptProfit.getPtGrossAdd() - visitorEarnings);
|
|
|
|
+ ptProfitService.updatePtProfit(BeanUtils.toBean(ptProfit, PtProfitSaveReqVO.class));
|
|
|
|
+ ptIntegralDO.setCurrentQuota(ptIntegralDO.getCurrentQuota() - visitorEarnings);
|
|
|
|
+
|
|
|
|
+ ptProfitLogService.addMessage(parent, CaclEnum.AFTER_CRASH_CALC_PT_TOTAL_QUOTA
|
|
|
|
+ , -visitorEarnings, ptProfit.getPtTotalAdd() - visitorEarnings, JsonUtils.toJsonString(orderPercentageDO), null, null, null);
|
|
|
|
+ ptProfitLogService.addMessage(parent, CaclEnum.AFTER_CRASH_CALC_PT_TOTAL_GROSS_QUOTA
|
|
|
|
+ , -visitorEarnings, ptProfit.getPtGrossAdd(), JsonUtils.toJsonString(orderPercentageDO), null, null, null);
|
|
|
|
+
|
|
|
|
+ // 记录平台游客收益log
|
|
|
|
+ ptProfitLogService.addMessage(k.getUserId(), null ,CaclEnum.SMALL_QUOTA_CRASH_SETTLE, visitorEarnings, ptProfit.getVisitorEarnings()
|
|
|
|
+ , null, null, JsonUtils.toJsonString(orderPercentageDO),null, null);
|
|
}
|
|
}
|
|
|
|
|
|
- // 获取计算后积分, Long为userId, Integer为碰撞后额度
|
|
|
|
- HashMap<Long, Long> map = new HashMap<>();
|
|
|
|
// 如果为当前用户为平台,则不需要存入这个地方
|
|
// 如果为当前用户为平台,则不需要存入这个地方
|
|
if (!k.getUserId().equals(PT_ID)) {
|
|
if (!k.getUserId().equals(PT_ID)) {
|
|
map.put(k.getUserId(), amount);
|
|
map.put(k.getUserId(), amount);
|
|
}
|
|
}
|
|
- if (!parentIntegralDo.getUserId().equals(PT_ID)) {
|
|
|
|
- map.put(parentIntegralDo.getUserId(), parentAmount);
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
afterCrashMap.add(map);
|
|
afterCrashMap.add(map);
|
|
|
|
|
|
log.info(k.getNickName() + "用户合赢奖已经计算: 该用户合赢奖为: \t" +
|
|
log.info(k.getNickName() + "用户合赢奖已经计算: 该用户合赢奖为: \t" +
|
|
@@ -368,7 +403,7 @@ public class PartitionCrashServiceImpl implements PartitionCrashService {
|
|
// 计算平台积分
|
|
// 计算平台积分
|
|
// 获取当前平台的额度
|
|
// 获取当前平台的额度
|
|
PtProfitDO ptProfit = ptProfitService.getPtProfit();
|
|
PtProfitDO ptProfit = ptProfitService.getPtProfit();
|
|
- IntegralDO ptIntegralDO = integralService.selectByUser(PT_ID);
|
|
|
|
|
|
+
|
|
// 遍历hashMap
|
|
// 遍历hashMap
|
|
for (HashMap<Long, Long> longIntegerHashMap : afterCrashMap) {
|
|
for (HashMap<Long, Long> longIntegerHashMap : afterCrashMap) {
|
|
for (Map.Entry<Long, Long> entry : longIntegerHashMap.entrySet()) {
|
|
for (Map.Entry<Long, Long> entry : longIntegerHashMap.entrySet()) {
|
|
@@ -538,7 +573,7 @@ public class PartitionCrashServiceImpl implements PartitionCrashService {
|
|
}
|
|
}
|
|
|
|
|
|
// 获取昨天的编号
|
|
// 获取昨天的编号
|
|
- public PartitionCrashDO crashYesterdayNo(Long userId,Integer yesterday) {
|
|
|
|
|
|
+ public PartitionCrashDO crashYesterdayNo(Long userId, Integer yesterday) {
|
|
LocalDateTime todayStart = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT); // 今天的开始时间,即午夜12点
|
|
LocalDateTime todayStart = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT); // 今天的开始时间,即午夜12点
|
|
LocalDateTime localDateTime = todayStart.minusDays(yesterday);
|
|
LocalDateTime localDateTime = todayStart.minusDays(yesterday);
|
|
String yesterdayString = "CRASH:" + userId + ":" + localDateTime;
|
|
String yesterdayString = "CRASH:" + userId + ":" + localDateTime;
|
|
@@ -549,8 +584,8 @@ public class PartitionCrashServiceImpl implements PartitionCrashService {
|
|
.apply("date(create_time) < date(now())")
|
|
.apply("date(create_time) < date(now())")
|
|
);
|
|
);
|
|
//判断这个用户不是第一次碰撞并且没有查询到昨天的碰撞记录,有可能是昨天或者更早定时任务没有启动导致的,所以再往前查几天
|
|
//判断这个用户不是第一次碰撞并且没有查询到昨天的碰撞记录,有可能是昨天或者更早定时任务没有启动导致的,所以再往前查几天
|
|
- if(!partitionCrashDOS.isEmpty() && partitionCrashDO == null){
|
|
|
|
- return crashYesterdayNo(userId,++yesterday);
|
|
|
|
|
|
+ if (!partitionCrashDOS.isEmpty() && partitionCrashDO == null) {
|
|
|
|
+ return crashYesterdayNo(userId, ++yesterday);
|
|
}
|
|
}
|
|
// return "CRASH:" + userId + ":" + "2024-06-20T00:00";
|
|
// return "CRASH:" + userId + ":" + "2024-06-20T00:00";
|
|
return partitionCrashDO;
|
|
return partitionCrashDO;
|