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

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

View File

@@ -5,6 +5,9 @@
- 功能优化:优化系统配置,移除已废弃的配置项
- 功能优化GPT-O1 模型支持流式输出
- 功能优化:优化代码引用快样式,支持主题切换
- 功能优化:登录,注册页面允许替换用户自己的 Logo 和 Title
- Bug 修复:修复 OpenAI 实时语音通话没有检测用户算力不足的 Bug
- 功能新增:管理后台增加算力日志查询功能,支持按用户,按模型,按日期,按类型查询算力日志
## v4.1.8

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",

View File

@@ -1,4 +1,4 @@
VUE_APP_API_HOST=http:/localhost:5678
VUE_APP_API_HOST=http://localhost:5678
VUE_APP_WS_HOST=ws://localhost:5678
VUE_APP_USER=18888888888
VUE_APP_PASS=12345678

View File

@@ -1,7 +1,9 @@
<template>
<div class="container power-log" v-loading="loading">
<div class="handle-box">
<el-input v-model="query.model" placeholder="模型" class="handle-input mr10" clearable></el-input>
<el-input v-model="query.model" placeholder="模型" class="handle-input mr10" clearable style="--el-input-height: 32px" />
<el-input v-model="query.username" placeholder="用户名" class="handle-input mr10" clearable style="--el-input-height: 32px" />
<el-input v-model.number="query.userid" placeholder="用户ID" class="handle-input mr10" clearable style="--el-input-height: 32px" />
<el-select v-model="query.type" placeholder="类别" style="width: 100px">
<el-option label="全部" :value="0" />
<el-option label="充值" :value="1" />
@@ -17,7 +19,7 @@
end-placeholder="结束日期"
format="YYYY-MM-DD"
value-format="YYYY-MM-DD"
style="margin: 0 10px; width: 200px; position: relative; top: 3px"
style="margin: 0 10px; width: 200px; --el-input-height: 32px"
/>
<el-button type="primary" :icon="Search" @click="search">搜索</el-button>
@@ -84,6 +86,8 @@ const query = ref({
model: "",
date: [],
type: 0,
page: 1,
page_size: 20,
});
const totalPower = ref(0);
@@ -110,13 +114,9 @@ const search = () => {
// 获取数据
const fetchData = () => {
loading.value = true;
httpPost("/api/admin/powerLog/list", {
model: query.value.model,
date: query.value.date,
type: query.value.type,
page: page.value,
page_size: pageSize.value,
})
query.value.page = page.value;
query.value.page_size = pageSize.value;
httpPost("/api/admin/powerLog/list", query.value)
.then((res) => {
const data = res.data.data;
if (data) {
@@ -138,9 +138,10 @@ const fetchData = () => {
<style lang="stylus" scoped>
.power-log {
.handle-box {
--el-input-height: 32px;
margin-bottom 20px
.handle-input {
max-width 150px;
max-width 120px;
margin-right 10px;
}
}

View File

@@ -2,6 +2,8 @@
<div class="container user-list" v-loading="loading">
<div class="handle-box">
<el-input v-model="query.username" placeholder="账号" class="handle-input mr10"></el-input>
<el-input v-model="query.mobile" placeholder="手机" class="handle-input mr10"></el-input>
<el-input v-model="query.email" placeholder="邮箱" class="handle-input mr10"></el-input>
<el-button type="primary" :icon="Search" @click="handleSearch">搜索</el-button>
<el-button type="success" :icon="Plus" @click="addUser">新增用户</el-button>
<el-button type="danger" :icon="Delete" @click="multipleDelete">删除</el-button>