Browse Source

feat(cf): PlatformPointsService.earn 增加 (ref_type, ref_id) 幂等去重

Sisyphus 2 weeks ago
parent
commit
36ed9ce100

+ 11 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/PlatformPointsService.java

@@ -74,6 +74,17 @@ public class PlatformPointsService {
         if (amount <= 0) {
             throw new IllegalArgumentException("CF值数量必须为正数");
         }
+        // 幂等:按 (userId, ref_type, ref_id) 去重
+        if (refId != null) {
+            Long existing = logMapper.selectCount(
+                    new LambdaQueryWrapper<PlatformBalanceLog>()
+                            .eq(PlatformBalanceLog::getUserId, userId)
+                            .eq(PlatformBalanceLog::getRefType, refType)
+                            .eq(PlatformBalanceLog::getRefId, refId));
+            if (existing != null && existing > 0) {
+                return;
+            }
+        }
         UserPlatformBalance b = getOrCreate(userId);
         b.setTotalEarned(safeInt(b.getTotalEarned()) + amount);
         b.setAvailable(safeInt(b.getAvailable()) + amount);