Преглед изворни кода

feat: 购买商品发放CF值并激活推荐人分润

Xiaogang Liao пре 1 месец
родитељ
комит
46d699cc3b

+ 17 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/CommissionDistService.java

@@ -42,6 +42,9 @@ public class CommissionDistService {
     @Resource
     private PpointConfigService ppointConfigService;
 
+    @Resource
+    private PlatformPointsService platformPointsService;
+
     @Resource
     private ProductMapper productMapper;
 
@@ -138,6 +141,20 @@ public class CommissionDistService {
         logRecord.setCreatedAt(new Date());
         commissionDistLogMapper.insert(logRecord);
 
+        // 给推荐人写 CF 值余额
+        try {
+            if (level1UserId != null && level1Ppoint > 0) {
+                platformPointsService.earn(level1UserId, level1Ppoint,
+                        "referral_dist", orderId, "一级推荐人分润");
+            }
+            if (level2UserId != null && level2Ppoint > 0) {
+                platformPointsService.earn(level2UserId, level2Ppoint,
+                        "referral_dist", orderId, "二级推荐人分润");
+            }
+        } catch (Exception e) {
+            log.error("推荐人CF值写入失败: buyerId={}, error={}", buyerId, e.getMessage());
+        }
+
         log.info("P点分润完成: buyerId={}, productId={}, sourcePpoint={}, level1={}/{}pp, level2={}/{}pp",
                 buyerId, productId, sourcePpoint,
                 level1UserId, level1Ppoint, level2UserId, level2Ppoint);

+ 44 - 2
cfc-backend/src/main/java/com/etotem/cfc/service/ProductOrderService.java

@@ -108,6 +108,18 @@ public class ProductOrderService {
     @Resource
     private SupplySystemMemberMapper supplySystemMemberMapper;
 
+    @Resource
+    private PpointConfigService ppointConfigService;
+
+    @Resource
+    private CommissionDistService commissionDistService;
+
+    @Resource
+    private PlatformPointsService platformPointsService;
+
+    @Resource
+    private SysConfigService sysConfigService;
+
     @Resource
     private SupplyHierarchyService supplyHierarchyService;
 
@@ -587,8 +599,38 @@ public class ProductOrderService {
         order.setPaidAt(new Date());
         order.setUpdatedAt(new Date());
         orderMapper.updateById(order);
-        commissionService.settle(order.getId(), "product", order.getBuyerId(),
-                order.getTotalAmount(), order.getProductId());
+
+        // CF值:购买者本人按分润公式获得
+        try {
+            Product p = productMapper.selectById(order.getProductId());
+            if (p != null) {
+                int effectivePpoint = ppointConfigService.getEffectivePpoint(p.getId(), p.getCategoryId());
+                if (effectivePpoint > 0) {
+                    String shareStr = sysConfigService.getValue("product_platform_points_share");
+                    int shareBps = shareStr != null && !shareStr.isEmpty()
+                            ? Integer.parseInt(shareStr) : 1000;
+                    int cfValue = order.getTotalAmount() * effectivePpoint / 100 * shareBps / 10000;
+                    if (cfValue > 0) {
+                        platformPointsService.earn(order.getBuyerId(), cfValue,
+                                "product_order", order.getId(),
+                                "购买商品: " + order.getProductName());
+                    }
+                }
+            }
+        } catch (Exception e) {
+            log.error("购买者CF值发放失败: orderId={}, error={}", order.getId(), e.getMessage());
+        }
+
+        // CF值:推荐人按推荐链分润
+        try {
+            commissionDistService.distribute(order.getBuyerId(), order.getId(), order.getProductId());
+        } catch (Exception e) {
+            log.error("推荐人分润失败: orderId={}, error={}", order.getId(), e.getMessage());
+        }
+
+        // 原佣金结算标记为废弃,保留兼容
+        // commissionService.settle(order.getId(), "product", order.getBuyerId(),
+        //        order.getTotalAmount(), order.getProductId());
         try {
             if (order.getSupplySystemId() != null) {
                 User buyer = userMapper.selectById(order.getBuyerId());