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;
}
}
@@ -55,7 +55,7 @@ public class UserInfoService {
return null;
}
public UserInfo addCoins(String userId, Integer amount) {
public UserInfo addCoins(String userId, Integer amount, String type, String description) {
if (amount == null || amount <= 0) {
throw new IllegalArgumentException("金币数量必须大于0");
}
+20 -4
View File
@@ -100,10 +100,12 @@
</template>
<script>
import api from '@/utils/api.js'
export default {
data() {
return {
coins: 10,
coins: 0,
signedToday: false,
streakDays: 0,
weekDays: [],
@@ -247,13 +249,27 @@ export default {
uni.showLoading({ title: '加载视频中...' })
setTimeout(() => {
setTimeout(async () => {
uni.hideLoading()
this.videoCount--
this.coins += 3
uni.setStorageSync('userCoins', this.coins)
try {
const userInfoStr = uni.getStorageSync('userInfo')
if (userInfoStr) {
const userInfo = JSON.parse(userInfoStr)
const result = await api.userApi.addCoins(userInfo.userId, 3, 'video', '观看视频奖励')
if (result && result.success) {
this.coins = result.data.coins || 0
uni.setStorageSync('userCoins', this.coins)
}
}
} catch (e) {
console.error('添加金币失败:', e)
this.coins += 3
uni.setStorageSync('userCoins', this.coins)
}
uni.setStorageSync('videoCount', this.videoCount)
this.records.unshift({
+1 -1
View File
@@ -63,7 +63,7 @@ export default {
},
data() {
return {
coins: 3,
coins: 0,
vipLevel: 0,
username: '玄机用户',
avatar: '',
+12
View File
@@ -407,6 +407,18 @@ const userApi = {
relatedId: relatedId
}
})
},
addCoins: (userId, amount, type, description) => {
return request({
url: '/user/addCoins',
method: 'POST',
data: {
userId: userId,
amount: amount,
type: type,
description: description
}
})
}
}