Explorar o código

fix(cf): 修复非商品订单销售奖P点基数单位(分/元100倍bug)

根因:git c22aca4966(2026-10-30)把calcOrderPpoints入参从amountYuan改为amountCent、
商品分支改为按分核算、档位表迁移431由元改分(100→10000),但非商品分支漏改,
仍 amountCent/100 当元再算 → 100元订单P点算成10(应10000),低于档位最低10000,
导致会员/套餐/订阅/测评订单的F03a/F03b销售奖永不触发。

修复:非商品分支改为 baseCent * serviceRateBps / 10000(直接用分),与商品分支和档位分口径一致。

TDD:
- RED 新增 CfCommissionPpointUnitTest(反射调private calcOrderPpoints),
  初始失败 expected 1000 but was 10,精准捕获100倍bug
- GREEN 修复后 1/1 绿
- 更新固化bug的旧断言 CfCommissionServiceSettleTest:492 (10→1000)及注释
- 相关3个CF测试类17例全绿;全项目test-compile EXIT0

验证:生产部署后 API cart/traffic/contact 200、ERROR0、双前端200。

说明:本次仅修金额单位bug;全量mvn test因集成测试需真实MySQL连接超时(环境依赖,非本改动)。
Xiaogang Liao hai 3 horas
pai
achega
fa9698d382

+ 4 - 2
cfc-backend/src/main/java/com/etotem/cfc/service/CfCommissionService.java

@@ -895,10 +895,12 @@ public class CfCommissionService {
                 return 0;
                 return 0;
             }
             }
         }
         }
-        int amountYuan = (amountCent != null ? amountCent : 0) / 100;
+        // P 点单位:分(与商品分支、cf_direct_sales_tier.min_annual_ppoints 分口径一致)。
+        // 历史 bug:此处先把分 /100 当元再算,导致非商品订单 P 点缩小 100 倍、销售奖档位永不触发。
+        int baseCent = amountCent != null ? amountCent : 0;
         int serviceRateBps = configService.getIntConfig(CfConfigKeys.COMMISSION_SERVICE_RATE, 1000);
         int serviceRateBps = configService.getIntConfig(CfConfigKeys.COMMISSION_SERVICE_RATE, 1000);
         if (serviceRateBps <= 0) return 0;
         if (serviceRateBps <= 0) return 0;
-        return amountYuan * serviceRateBps / 10000;
+        return baseCent * serviceRateBps / 10000;
     }
     }
 
 
 
 

+ 55 - 0
cfc-backend/src/test/java/com/etotem/cfc/service/CfCommissionPpointUnitTest.java

@@ -0,0 +1,55 @@
+package com.etotem.cfc.service;
+
+import com.etotem.cfc.config.ConfigService;
+import com.etotem.cfc.constant.CfConfigKeys;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import java.lang.reflect.Method;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+
+/**
+ * 非商品订单销售奖 P 点基数单位回归(金额按分)。
+ *
+ * 口径:calcOrderPpoints 声明"单位:分"。非商品订单(会员/套餐/订阅/测评)
+ * 的 P 点必须按分计算:base = amountCent × serviceRateBps / 10000。
+ * 100 元订单 = 10000 分,服务费率 1000bps(10%) → base = 1000 分。
+ * 历史 bug:先把分除以100当元再算 → base=10(缩小100倍),导致销售奖档位永不触发。
+ */
+class CfCommissionPpointUnitTest {
+
+    @Mock
+    private ConfigService configService;
+
+    @InjectMocks
+    private CfCommissionService cfCommissionService;
+
+    private Method calcOrderPpoints;
+
+    @BeforeEach
+    void setUp() throws Exception {
+        MockitoAnnotations.openMocks(this);
+        calcOrderPpoints = CfCommissionService.class.getDeclaredMethod(
+                "calcOrderPpoints", Long.class, String.class, Integer.class,
+                Integer.class, Long.class);
+        calcOrderPpoints.setAccessible(true);
+        when(configService.getIntConfig(eq(CfConfigKeys.COMMISSION_SERVICE_RATE), anyInt()))
+                .thenReturn(1000); // 1000 bps = 10%
+    }
+
+    @Test
+    void nonProductOrder_pPoints_calculatedInCents() throws Exception {
+        // 100元会员订单 = 10000分,费率10% → P点应为1000分(不是10)
+        int ppoints = (Integer) calcOrderPpoints.invoke(
+                cfCommissionService, 1L, "membership", 10000, 10000, null);
+        assertEquals(1000, ppoints);
+    }
+}

+ 3 - 2
cfc-backend/src/test/java/com/etotem/cfc/service/CfCommissionServiceSettleTest.java

@@ -486,10 +486,11 @@ class CfCommissionServiceSettleTest {
 
 
         // N6:会员/订阅订单当前消费人也返 F02(按实付金额)
         // N6:会员/订阅订单当前消费人也返 F02(按实付金额)
         verify(cfEarnDispatchService).earnConsumeCf(eq(BUYER_ID), eq("membership"), eq(ORDER_ID), eq(10000));
         verify(cfEarnDispatchService).earnConsumeCf(eq(BUYER_ID), eq("membership"), eq(ORDER_ID), eq(10000));
-        // 推荐人 F03a:非商品基数 = 100 元 × 1000bps / 10000 = 10 P 点
+        // 推荐人 F03a:非商品基数按分计 = 10000 分 × 1000bps / 10000 = 1000 P 点
+        // (P 点单位为分,与商品分支、cf_direct_sales_tier 分口径一致;历史 bug 曾把分/100当元算出10)
         ArgumentCaptor<Map<String, Object>> captor = ArgumentCaptor.forClass(Map.class);
         ArgumentCaptor<Map<String, Object>> captor = ArgumentCaptor.forClass(Map.class);
         verify(cfBalanceService).earnByRule(eq(memberIdOf(10L)), eq("F03a"), eq(ORDER_ID), captor.capture());
         verify(cfBalanceService).earnByRule(eq(memberIdOf(10L)), eq("F03a"), eq(ORDER_ID), captor.capture());
-        assertEquals(10, captor.getValue().get("base_ppoints"));
+        assertEquals(1000, captor.getValue().get("base_ppoints"));
     }
     }
 
 
     @Test
     @Test