diff --git a/api/handler/admin/dashboard_handler.go b/api/handler/admin/dashboard_handler.go index b219ca39..9052304a 100644 --- a/api/handler/admin/dashboard_handler.go +++ b/api/handler/admin/dashboard_handler.go @@ -22,9 +22,10 @@ func NewDashboardHandler(app *core.AppServer, db *gorm.DB) *DashboardHandler { } type statsVo struct { - Users int64 `json:"users"` - Chats int64 `json:"chats"` - Tokens int64 `json:"tokens"` + Users int64 `json:"users"` + Chats int64 `json:"chats"` + Tokens int64 `json:"tokens"` + Rewards float64 `json:"rewards"` } func (h *DashboardHandler) Stats(c *gin.Context) { @@ -47,9 +48,16 @@ func (h *DashboardHandler) Stats(c *gin.Context) { // tokens took stats var tokenCount int64 - res = h.db.Model(&model.HistoryMessage{}).Select("sum(tokens) as tokens_total").Where("created_at > ?", zeroTime).Scan(&tokenCount) + res = h.db.Model(&model.HistoryMessage{}).Select("sum(tokens) as total").Where("created_at > ?", zeroTime).Scan(&tokenCount) if res.Error == nil { stats.Tokens = tokenCount } + + // reward revenue + var amount float64 + res = h.db.Model(&model.Reward{}).Select("sum(amount) as total").Where("created_at > ?", zeroTime).Scan(&amount) + if res.Error == nil { + stats.Rewards = amount + } resp.SUCCESS(c, stats) } diff --git a/web/src/views/admin/Dashboard.vue b/web/src/views/admin/Dashboard.vue index dc785a7f..998e2e53 100644 --- a/web/src/views/admin/Dashboard.vue +++ b/web/src/views/admin/Dashboard.vue @@ -1,7 +1,7 @@ @@ -50,12 +63,13 @@ import {ChatDotRound, TrendCharts, User} from "@element-plus/icons-vue"; import {httpGet} from "@/utils/http"; import {ElMessage} from "element-plus"; -const stats = ref({users: 0, chats: 0, tokens: 0}) +const stats = ref({users: 0, chats: 0, tokens: 0, rewards: 0}) httpGet('/api/admin/dashboard/stats').then((res) => { stats.value.users = res.data.users stats.value.chats = res.data.chats stats.value.tokens = res.data.tokens + stats.value.rewards = res.data.rewards }).catch((e) => { ElMessage.error("获取统计数据失败:" + e.message) }) @@ -89,6 +103,10 @@ httpGet('/api/admin/dashboard/stats').then((res) => { text-align: center; line-height: 100px; color: #fff; + + .iconfont { + font-size: 50px; + } } .grid-con-1 .grid-con-icon {