Просмотр исходного кода

feat(points): 新增心愿兑换积分检查和扣除方法

- PointsService: 新增checkAndGrantReward()和deductForWish()方法
- 用于心愿兑换时的积分原子性检查和扣除

Ultraworked with Sisyphus

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Xiaogang Liao 2 месяцев назад
Родитель
Сommit
dfcc285cf8
1 измененных файлов с 31 добавлено и 0 удалено
  1. 31 0
      cfc-backend/src/main/java/com/etotem/cfc/service/PointsService.java

+ 31 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/PointsService.java

@@ -176,4 +176,35 @@ public class PointsService implements PointsServiceInterface {
         wrapper.orderByDesc(PointsLog::getCreatedAt);
         return pointsLogMapper.selectPage(pageParam, wrapper);
     }
+
+    /**
+     * 检查并发放心愿兑换奖励
+     * @param childId 孩子ID
+     * @param amount 奖励积分
+     * @return 发放后系统积分余额,余额不足返回-1
+     */
+    @Transactional
+    public int checkAndGrantReward(Long childId, int amount) {
+        int currentBalance = getSystemPointsBalance(childId);
+        if (currentBalance < amount) {
+            return -1;
+        }
+        return awardSystemPoints(childId, amount, "心愿兑换奖励");
+    }
+
+    /**
+     * 扣除心愿兑换积分
+     * @param childId 孩子ID
+     * @param amount 扣除积分
+     * @return 扣除成功返回true,余额不足返回false
+     */
+    @Transactional
+    public boolean deductForWish(Long childId, int amount) {
+        int currentBalance = getSystemPointsBalance(childId);
+        if (currentBalance < amount) {
+            return false;
+        }
+        int result = deductSystemPoints(childId, amount, "心愿兑换扣除");
+        return result != -1;
+    }
 }