|
|
@@ -237,7 +237,7 @@ public class CfReferralService {
|
|
|
for (Map.Entry<Long, Integer> e : minLevel.entrySet()) {
|
|
|
int w = 11 - e.getValue(); // L1→10(100%), L10→1(10%), L11→0
|
|
|
if (w <= 0) continue;
|
|
|
- long pp = sumAnnualPpointsAsOf(Collections.singletonList(e.getKey()), since, end);
|
|
|
+ long pp = sumAnnualPaidYuan(Collections.singletonList(e.getKey()), since, new Date(end.getTime() + 1));
|
|
|
total += (int) Math.round(pp * w / 10.0);
|
|
|
}
|
|
|
return total;
|
|
|
@@ -247,7 +247,7 @@ public class CfReferralService {
|
|
|
public int getSelfAnnualPpointsAt(Long referrerUserId, Date asOf) {
|
|
|
if (referrerUserId == null) return 0;
|
|
|
Date end = asOf != null ? asOf : new Date();
|
|
|
- return sumAnnualPpointsAsOf(Collections.singletonList(referrerUserId), rollingYearAgo(end), end);
|
|
|
+ return sumAnnualPaidYuan(Collections.singletonList(referrerUserId), rollingYearAgo(end), new Date(end.getTime() + 1));
|
|
|
}
|
|
|
|
|
|
/** F03a 档位业绩 = 本人100% + 团队加权(self 只加一次,团队遍历不含本人)。 */
|
|
|
@@ -255,7 +255,7 @@ public class CfReferralService {
|
|
|
if (referrerUserId == null) return 0;
|
|
|
Date end = asOf != null ? asOf : new Date();
|
|
|
Date since = rollingYearAgo(end);
|
|
|
- int self = sumAnnualPpointsAsOf(Collections.singletonList(referrerUserId), since, end);
|
|
|
+ int self = sumAnnualPaidYuan(Collections.singletonList(referrerUserId), since, new Date(end.getTime() + 1));
|
|
|
return self + getWeightedTeamAnnualPpoints(referrerUserId, asOf);
|
|
|
}
|
|
|
|
|
|
@@ -270,7 +270,7 @@ public class CfReferralService {
|
|
|
if (referrerUserId == null || orderPaidAt == null) return 0;
|
|
|
Date since = rollingYearAgo(orderPaidAt);
|
|
|
// self(按 paid_at,排除自身)
|
|
|
- int self = ppointConsumptionLogMapper.sumPpointsByPaidAt(
|
|
|
+ int self = ppointConsumptionLogMapper.sumPaidAmountYuan(
|
|
|
Collections.singletonList(referrerUserId), since, orderPaidAt);
|
|
|
// 团队逐层权重(按 paid_at 归属,排除自身)
|
|
|
LambdaQueryWrapper<ReferralTree> qw = new LambdaQueryWrapper<ReferralTree>()
|
|
|
@@ -291,7 +291,7 @@ public class CfReferralService {
|
|
|
for (Map.Entry<Long, Integer> e : minLevel.entrySet()) {
|
|
|
int w = 11 - e.getValue();
|
|
|
if (w <= 0) continue;
|
|
|
- long pp = ppointConsumptionLogMapper.sumPpointsByPaidAt(
|
|
|
+ long pp = ppointConsumptionLogMapper.sumPaidAmountYuan(
|
|
|
Collections.singletonList(e.getKey()), since, orderPaidAt);
|
|
|
teamWeighted += (int) Math.round(pp * w / 10.0);
|
|
|
}
|
|
|
@@ -302,7 +302,7 @@ public class CfReferralService {
|
|
|
/** F03b 自身业绩(重算专用,按 paid_at 归属、排除自身)。 */
|
|
|
public int getSelfPpointsForRecalc(Long referrerUserId, Date orderPaidAt) {
|
|
|
if (referrerUserId == null || orderPaidAt == null) return 0;
|
|
|
- return ppointConsumptionLogMapper.sumPpointsByPaidAt(
|
|
|
+ return ppointConsumptionLogMapper.sumPaidAmountYuan(
|
|
|
Collections.singletonList(referrerUserId), rollingYearAgo(orderPaidAt), orderPaidAt);
|
|
|
}
|
|
|
|
|
|
@@ -354,23 +354,23 @@ public class CfReferralService {
|
|
|
|
|
|
/** 按用户集合分批求和滚动一年 P 点(IN 分批避免超长 SQL) */
|
|
|
private int sumAnnualPpoints(List<Long> userIds) {
|
|
|
- if (userIds == null || userIds.isEmpty()) {
|
|
|
- return 0;
|
|
|
+ if (userIds == null || userIds.isEmpty()) return 0;
|
|
|
+ // F03c 冻结口径专用:保持旧 P 点等权求和(不改为元),供 legacy 快照匹配
|
|
|
+ int total = 0;
|
|
|
+ for (int i = 0; i < userIds.size(); i += USER_ID_BATCH_SIZE) {
|
|
|
+ List<Long> batch = userIds.subList(i, Math.min(i + USER_ID_BATCH_SIZE, userIds.size()));
|
|
|
+ total += ppointConsumptionLogMapper.sumPpointsSince(batch, rollingYearAgo());
|
|
|
}
|
|
|
- return sumAnnualPpointsAsOf(userIds, rollingYearAgo(), null);
|
|
|
+ return total;
|
|
|
}
|
|
|
|
|
|
- /** 按用户集合分批求和 [since, until] 窗口 P 点(until=null 表示无上界) */
|
|
|
- private int sumAnnualPpointsAsOf(List<Long> userIds, Date since, Date until) {
|
|
|
- if (userIds == null || userIds.isEmpty()) {
|
|
|
- return 0;
|
|
|
- }
|
|
|
+ /** 按用户集合分批求和 [since, until) 窗口实付金额(元)。 */
|
|
|
+ private int sumAnnualPaidYuan(List<Long> userIds, Date since, Date until) {
|
|
|
+ if (userIds == null || userIds.isEmpty()) return 0;
|
|
|
int total = 0;
|
|
|
for (int i = 0; i < userIds.size(); i += USER_ID_BATCH_SIZE) {
|
|
|
List<Long> batch = userIds.subList(i, Math.min(i + USER_ID_BATCH_SIZE, userIds.size()));
|
|
|
- total += until == null
|
|
|
- ? ppointConsumptionLogMapper.sumPpointsSince(batch, since)
|
|
|
- : ppointConsumptionLogMapper.sumPpointsSinceUntil(batch, since, until);
|
|
|
+ total += ppointConsumptionLogMapper.sumPaidAmountYuan(batch, since, until);
|
|
|
}
|
|
|
return total;
|
|
|
}
|