管理后台用户算力日志页面增加过滤查询功能

This commit is contained in:
RockYang
2025-01-08 10:19:35 +08:00
parent 8250e876a5
commit 80e27c40e9
7 changed files with 47 additions and 13 deletions

View File

@@ -31,6 +31,7 @@ func NewPowerLogHandler(app *core.AppServer, db *gorm.DB) *PowerLogHandler {
func (h *PowerLogHandler) List(c *gin.Context) {
var data struct {
Username string `json:"username"`
UserId uint `json:"userid"`
Type int `json:"type"`
Model string `json:"model"`
Date []string `json:"date"`
@@ -49,6 +50,12 @@ func (h *PowerLogHandler) List(c *gin.Context) {
if data.Type > 0 {
session = session.Where("type", data.Type)
}
if data.UserId > 0 {
session = session.Where("user_id", data.UserId)
}
if data.Username != "" {
session = session.Where("username", data.Username)
}
if len(data.Date) == 2 {
start := data.Date[0] + " 00:00:00"
end := data.Date[1] + " 00:00:00"

View File

@@ -17,9 +17,10 @@ import (
"geekai/store/vo"
"geekai/utils"
"geekai/utils/resp"
"github.com/go-redis/redis/v8"
"time"
"github.com/go-redis/redis/v8"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
@@ -39,6 +40,8 @@ func (h *UserHandler) List(c *gin.Context) {
page := h.GetInt(c, "page", 1)
pageSize := h.GetInt(c, "page_size", 20)
username := h.GetTrim(c, "username")
mobile := h.GetTrim(c, "mobile")
email := h.GetTrim(c, "email")
offset := (page - 1) * pageSize
var items []model.User
@@ -49,6 +52,12 @@ func (h *UserHandler) List(c *gin.Context) {
if username != "" {
session = session.Where("username LIKE ?", "%"+username+"%")
}
if mobile != "" {
session = session.Where("mobile LIKE ?", "%"+mobile+"%")
}
if email != "" {
session = session.Where("email LIKE ?", "%"+email+"%")
}
session.Model(&model.User{}).Count(&total)
res := session.Offset(offset).Limit(pageSize).Order("id DESC").Find(&items)

View File

@@ -146,6 +146,19 @@ func (h *RealtimeHandler) VoiceChat(c *gin.Context) {
return
}
// 检查用户是否还有算力
userId := h.GetLoginUserId(c)
var user model.User
if err := h.DB.Where("id", userId).First(&user).Error; err != nil {
resp.ERROR(c, fmt.Sprintf("error with fetch user%v", err))
return
}
if user.Power < h.App.SysConfig.AdvanceVoicePower {
resp.ERROR(c, "当前用户算力不足,无法使用该功能")
return
}
var response utils.OpenAIResponse
client := req.C()
if len(apiKey.ProxyURL) > 5 {
@@ -185,7 +198,6 @@ func (h *RealtimeHandler) VoiceChat(c *gin.Context) {
h.DB.Model(&apiKey).UpdateColumn("last_used_at", time.Now().Unix())
// 扣减算力
userId := h.GetLoginUserId(c)
err = h.userService.DecreasePower(int(userId), h.App.SysConfig.AdvanceVoicePower, model.PowerLog{
Type: types.PowerConsume,
Model: "advanced-voice",