Browse Source

fix(f03): 层级权重改为11-level(L1直推自购100%/L10为10%/L11为0), 修正李志清自购90%误算

Xiaogang Liao 5 hours ago
parent
commit
6f78b22f45

+ 3 - 3
cfc-backend/src/main/java/com/etotem/cfc/service/CfReferralService.java

@@ -46,7 +46,7 @@ public class CfReferralService {
     public static final int DEFAULT_TEAM_DEPTH = 8;
     public static final int DEFAULT_TEAM_DEPTH = 8;
 
 
     /** F03a 业绩权重最大层级(新规则:第1层90%递减至第10层0%) */
     /** F03a 业绩权重最大层级(新规则:第1层90%递减至第10层0%) */
-    public static final int F03A_WEIGHT_DEPTH = 10;
+    public static final int F03A_WEIGHT_DEPTH = 11; // L1=100%…L10=10%, L11=0%
 
 
     /** 滚动一年窗口天数(§4.1/§4.4:按消费时间滚动一年) */
     /** 滚动一年窗口天数(§4.1/§4.4:按消费时间滚动一年) */
     private static final int ROLLING_YEAR_DAYS = 365;
     private static final int ROLLING_YEAR_DAYS = 365;
@@ -235,7 +235,7 @@ public class CfReferralService {
         }
         }
         int total = 0;
         int total = 0;
         for (Map.Entry<Long, Integer> e : minLevel.entrySet()) {
         for (Map.Entry<Long, Integer> e : minLevel.entrySet()) {
-            int w = 10 - e.getValue(); // L1→9(90%), L9→1(10%), L10→0
+            int w = 11 - e.getValue(); // L1→10(100%), L10→1(10%), L11→0
             if (w <= 0) continue;
             if (w <= 0) continue;
             long pp = sumAnnualPpointsAsOf(Collections.singletonList(e.getKey()), since, end);
             long pp = sumAnnualPpointsAsOf(Collections.singletonList(e.getKey()), since, end);
             total += (int) Math.round(pp * w / 10.0);
             total += (int) Math.round(pp * w / 10.0);
@@ -289,7 +289,7 @@ public class CfReferralService {
                 if (prev == null || lv < prev) minLevel.put(mid, lv);
                 if (prev == null || lv < prev) minLevel.put(mid, lv);
             }
             }
             for (Map.Entry<Long, Integer> e : minLevel.entrySet()) {
             for (Map.Entry<Long, Integer> e : minLevel.entrySet()) {
-                int w = 10 - e.getValue();
+                int w = 11 - e.getValue();
                 if (w <= 0) continue;
                 if (w <= 0) continue;
                 long pp = ppointConsumptionLogMapper.sumPpointsByPaidAt(
                 long pp = ppointConsumptionLogMapper.sumPpointsByPaidAt(
                         Collections.singletonList(e.getKey()), since, orderPaidAt);
                         Collections.singletonList(e.getKey()), since, orderPaidAt);

+ 17 - 5
cfc-backend/src/test/java/com/etotem/cfc/service/CfReferralWeightedPpointsTest.java

@@ -57,8 +57,8 @@ class CfReferralWeightedPpointsTest {
                     if (ids.contains(110L)) sum += 50000;
                     if (ids.contains(110L)) sum += 50000;
                     return sum;
                     return sum;
                 });
                 });
-        // 期望 = 10000*0.9 + 20000*0.8 + 50000*0.0 = 9000 + 16000 + 0 = 25000
-        assertEquals(25000, service.getWeightedTeamAnnualPpoints(1L, asOf));
+        // 新权重 L1=100%,L2=90%,L10=10% → 10000*1.0 + 20000*0.9 + 50000*0.1 = 33000
+        assertEquals(33000, service.getWeightedTeamAnnualPpoints(1L, asOf));
     }
     }
 
 
     @Test
     @Test
@@ -68,12 +68,12 @@ class CfReferralWeightedPpointsTest {
                 tree(1L, 103L, 1), tree(1L, 103L, 2), tree(1L, 1L, 1)));
                 tree(1L, 103L, 1), tree(1L, 103L, 2), tree(1L, 1L, 1)));
         when(ppointConsumptionLogMapper.sumPpointsSinceUntil(anyCollection(), any(Date.class), any(Date.class)))
         when(ppointConsumptionLogMapper.sumPpointsSinceUntil(anyCollection(), any(Date.class), any(Date.class)))
                 .thenReturn(10000);
                 .thenReturn(10000);
-        assertEquals(9000, service.getWeightedTeamAnnualPpoints(1L, asOf));
+        assertEquals(10000, service.getWeightedTeamAnnualPpoints(1L, asOf));
     }
     }
 
 
     @Test
     @Test
     void f03a_tier_ppoints_is_self_plus_weighted_once() {
     void f03a_tier_ppoints_is_self_plus_weighted_once() {
-        // self=10000(用户1本人),团队加权=9000(用户101 L1 ×0.9)
+        // self=10000(用户1本人),团队加权=10000(用户101 L1 ×100%)
         when(ppointConsumptionLogMapper.sumPpointsSinceUntil(anyCollection(), any(Date.class), any(Date.class)))
         when(ppointConsumptionLogMapper.sumPpointsSinceUntil(anyCollection(), any(Date.class), any(Date.class)))
                 .thenAnswer(inv -> {
                 .thenAnswer(inv -> {
                     Collection<Long> ids = inv.getArgument(0);
                     Collection<Long> ids = inv.getArgument(0);
@@ -82,7 +82,19 @@ class CfReferralWeightedPpointsTest {
                     return 0;
                     return 0;
                 });
                 });
         when(referralTreeMapper.selectList(any())).thenReturn(Collections.singletonList(tree(1L, 101L, 1)));
         when(referralTreeMapper.selectList(any())).thenReturn(Collections.singletonList(tree(1L, 101L, 1)));
-        assertEquals(19000, service.getF03aTierPpoints(1L, asOf)); // self10000 + 9000,self只加一次
+        assertEquals(20000, service.getF03aTierPpoints(1L, asOf)); // self10000 + 10000,self只加一次
+    }
+
+    @Test
+    void recalc_weight_L1_is_100_percent() {
+        // 重算专用:按 paid_at 归属,L1直推自购100%计入;李志清51,400×100%=51,400≥32,000→至富70%
+        when(ppointConsumptionLogMapper.sumPpointsByPaidAt(anyCollection(), any(Date.class), any(Date.class)))
+                .thenAnswer(inv -> {
+                    Collection<Long> ids = inv.getArgument(0);
+                    return ids.contains(101L) ? 51400 : 0;
+                });
+        when(referralTreeMapper.selectList(any())).thenReturn(Collections.singletonList(tree(1L, 101L, 1)));
+        assertEquals(51400, service.getF03aTierPpointsForRecalc(1L, asOf));
     }
     }
 
 
     @Test
     @Test

+ 1 - 1
cfc-backend/src/test/java/com/etotem/cfc/service/F03cSnapshotMatchTest.java

@@ -52,7 +52,7 @@ class F03cSnapshotMatchTest {
     @Test
     @Test
     void depth_constants_are_separated() {
     void depth_constants_are_separated() {
         assertEquals(8, CfReferralService.DEFAULT_TEAM_DEPTH);
         assertEquals(8, CfReferralService.DEFAULT_TEAM_DEPTH);
-        assertEquals(10, CfReferralService.F03A_WEIGHT_DEPTH);
+        assertEquals(11, CfReferralService.F03A_WEIGHT_DEPTH);
     }
     }
 
 
     private CfDirectSalesTier tier(String name, int min, int rate) {
     private CfDirectSalesTier tier(String name, int min, int rate) {

+ 7 - 0
cfc-backend/src/test/java/com/etotem/cfc/unit/AsOfPaidAtTest.java

@@ -27,6 +27,13 @@ class AsOfPaidAtTest {
                 "算订单X档位应排除订单X自身(严格早于下单时间)");
                 "算订单X档位应排除订单X自身(严格早于下单时间)");
     }
     }
 
 
+    @Test void weight_is_11_minus_level_L1_full() throws Exception {
+        String src = read("src/main/java/com/etotem/cfc/service/CfReferralService.java");
+        assertTrue(src.contains("11 - e.getValue()"),
+                "权重应为 11-level(L1直推自购100%、L10为10%),不是10-level");
+        assertTrue(src.contains("F03A_WEIGHT_DEPTH = 11"), "权重最大层级应为11");
+    }
+
     @Test void referral_has_paid_at_aggregation_method() throws Exception {
     @Test void referral_has_paid_at_aggregation_method() throws Exception {
         String src = read("src/main/java/com/etotem/cfc/service/CfReferralService.java");
         String src = read("src/main/java/com/etotem/cfc/service/CfReferralService.java");
         assertTrue(src.contains("PaidAt") || src.contains("paid_at"),
         assertTrue(src.contains("PaidAt") || src.contains("paid_at"),