refactor: 金币默认值改为数据库层面设置

- UserInfo实体类coins字段添加默认值DEFAULT 3
- 移除前后端硬编码的金币默认值
- 新增consumeCoins API接口用于金币消耗
- coinUtils.js改为从服务器获取金币数据
- 所有测算页面checkCoinsAndConsume改为异步调用
- VIP用户测算不消耗金币
This commit is contained in:
H1d3rOne committed 2026-03-10 03:19:40 +08:00
1 parent b9a4a9150e
commit f5f214a100
14 files changed
+141 -38

No files matched your search

@@ -266,4 +266,31 @@ public class UserController {
}
return result;
}
@PostMapping("/consumeCoins")
public Map<String, Object> consumeCoins(@RequestBody Map<String, Object> params) {
Map<String, Object> result = new HashMap<>();
try {
String userId = params.get("userId").toString();
Integer amount = params.get("amount") != null ? Integer.parseInt(params.get("amount").toString()) : 1;
String type = params.get("type") != null ? params.get("type").toString() : "unknown";
String description = params.get("description") != null ? params.get("description").toString() : "金币消耗";
String relatedId = params.get("relatedId") != null ? params.get("relatedId").toString() : null;
UserInfo user = userInfoService.consumeCoins(userId, amount, type, description, relatedId);
if (user != null) {
Map<String, Object> data = new HashMap<>();
data.put("coins", user.getCoins());
result.put("success", true);
result.put("data", data);
} else {
result.put("success", false);
result.put("error", "用户不存在或金币不足");
}
} catch (Exception e) {
result.put("success", false);
result.put("error", e.getMessage());
}
return result;
}
}