chore: add more log types
This commit is contained in:
parent
74f508e847
commit
d29c273073
@ -2,6 +2,7 @@ package controller
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"github.com/gin-contrib/sessions"
|
"github.com/gin-contrib/sessions"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -351,6 +352,9 @@ func UpdateUser(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
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{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": true,
|
"success": true,
|
||||||
"message": "",
|
"message": "",
|
||||||
|
@ -17,6 +17,8 @@ const (
|
|||||||
LogTypeUnknown = iota
|
LogTypeUnknown = iota
|
||||||
LogTypeTopup
|
LogTypeTopup
|
||||||
LogTypeConsume
|
LogTypeConsume
|
||||||
|
LogTypeManage
|
||||||
|
LogTypeSystem
|
||||||
)
|
)
|
||||||
|
|
||||||
func RecordLog(userId int, logType int, content string) {
|
func RecordLog(userId int, logType int, content string) {
|
||||||
|
@ -2,6 +2,7 @@ package model
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"one-api/common"
|
"one-api/common"
|
||||||
"strings"
|
"strings"
|
||||||
@ -73,8 +74,14 @@ func (user *User) Insert() error {
|
|||||||
}
|
}
|
||||||
user.Quota = common.QuotaForNewUser
|
user.Quota = common.QuotaForNewUser
|
||||||
user.AccessToken = common.GetUUID()
|
user.AccessToken = common.GetUUID()
|
||||||
err = DB.Create(user).Error
|
result := DB.Create(user)
|
||||||
return err
|
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 {
|
func (user *User) Update(updatePassword bool) error {
|
||||||
|
@ -18,6 +18,10 @@ function renderType(type) {
|
|||||||
return <Label basic color='green'> 充值 </Label>;
|
return <Label basic color='green'> 充值 </Label>;
|
||||||
case 2:
|
case 2:
|
||||||
return <Label basic color='olive'> 消费 </Label>;
|
return <Label basic color='olive'> 消费 </Label>;
|
||||||
|
case 3:
|
||||||
|
return <Label basic color='orange'> 管理 </Label>;
|
||||||
|
case 4:
|
||||||
|
return <Label basic color='red'> 系统 </Label>;
|
||||||
default:
|
default:
|
||||||
return <Label basic color='black'> 未知 </Label>;
|
return <Label basic color='black'> 未知 </Label>;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user