feat: add rewards statistic in dashboard page

This commit is contained in:
RockYang
2023-08-03 10:19:37 +08:00
parent d7b278f2f7
commit 0c8157dbc0
2 changed files with 34 additions and 8 deletions

View File

@@ -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)
}