Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
0b237f36
authored
Jun 10, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: add more log types
parent
532b60f7
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
2 deletions
+19
-2
controller/user.go
+4
-0
model/log.go
+2
-0
model/user.go
+9
-2
web/src/components/LogsTable.js
+4
-0
No files found.
controller/user.go
View file @
0b237f36
...
...
@@ -2,6 +2,7 @@ package controller
import
(
"encoding/json"
"fmt"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
"net/http"
...
...
@@ -351,6 +352,9 @@ func UpdateUser(c *gin.Context) {
})
return
}
if
originUser
.
Quota
!=
updatedUser
.
Quota
{
model
.
RecordLog
(
originUser
.
Id
,
model
.
LogTypeManage
,
fmt
.
Sprintf
(
"管理员将用户额度从 %d 点修改为 %d 点"
,
originUser
.
Quota
,
updatedUser
.
Quota
))
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
true
,
"message"
:
""
,
...
...
model/log.go
View file @
0b237f36
...
...
@@ -17,6 +17,8 @@ const (
LogTypeUnknown
=
iota
LogTypeTopup
LogTypeConsume
LogTypeManage
LogTypeSystem
)
func
RecordLog
(
userId
int
,
logType
int
,
content
string
)
{
...
...
model/user.go
View file @
0b237f36
...
...
@@ -2,6 +2,7 @@ package model
import
(
"errors"
"fmt"
"gorm.io/gorm"
"one-api/common"
"strings"
...
...
@@ -73,8 +74,14 @@ func (user *User) Insert() error {
}
user
.
Quota
=
common
.
QuotaForNewUser
user
.
AccessToken
=
common
.
GetUUID
()
err
=
DB
.
Create
(
user
)
.
Error
return
err
result
:=
DB
.
Create
(
user
)
if
result
.
Error
!=
nil
{
return
result
.
Error
}
if
common
.
QuotaForNewUser
>
0
{
RecordLog
(
user
.
Id
,
LogTypeSystem
,
fmt
.
Sprintf
(
"新用户注册赠送 %d 点额度"
,
common
.
QuotaForNewUser
))
}
return
nil
}
func
(
user
*
User
)
Update
(
updatePassword
bool
)
error
{
...
...
web/src/components/LogsTable.js
View file @
0b237f36
...
...
@@ -18,6 +18,10 @@ function renderType(type) {
return
<
Label
basic
color
=
'green'
>
充值
<
/Label>
;
case
2
:
return
<
Label
basic
color
=
'olive'
>
消费
<
/Label>
;
case
3
:
return
<
Label
basic
color
=
'orange'
>
管理
<
/Label>
;
case
4
:
return
<
Label
basic
color
=
'red'
>
系统
<
/Label>
;
default
:
return
<
Label
basic
color
=
'black'
>
未知
<
/Label>
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment