fix: 移除所有金币硬编码,改为API操作

- mine.vue: coins默认值改为0
- coins.vue: 添加API调用更新金币
- 新增addCoins API接口用于金币奖励
- 观看视频奖励通过API更新数据库
This commit is contained in:
H1d3rOne committed 2026-03-10 03:26:08 +08:00
1 parent f5f214a100
commit 1508898cbf
5 files changed
+60 -6

No files matched your search

@@ -293,4 +293,30 @@ public class UserController {
}
return result;
}
@PostMapping("/addCoins")
public Map<String, Object> addCoins(@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() : "金币奖励";
UserInfo user = userInfoService.addCoins(userId, amount, type, description);
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;
}
}