This commit is contained in:
wood
2023-11-11 03:21:46 +08:00
parent 49ea44c65b
commit 96793c3e9c
7 changed files with 41 additions and 162 deletions

View File

@@ -435,14 +435,11 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
common.LogError(ctx, "error update user quota cache: "+err.Error())
}
if quota != 0 {
// 对modelRatio进行计算
modelRatio = modelRatio * 0.002
logContent := fmt.Sprintf("单价 $%.4f/1k tokens,补全与官方一致", modelRatio)
logContent := fmt.Sprintf("模型倍率 %.4f", modelRatio)
model.RecordConsumeLog(ctx, userId, channelId, promptTokens, completionTokens, textRequest.Model, tokenName, quota, logContent)
model.UpdateUserUsedQuotaAndRequestCount(userId, quota)
model.UpdateChannelUsedQuota(channelId, quota)
}
}
}()
}(c.Request.Context())

View File

@@ -557,124 +557,6 @@ type ManageRequest struct {
}
// ManageUser Only admin user can do this
// func ManageUser(c *gin.Context) {
// var req ManageRequest
// err := json.NewDecoder(c.Request.Body).Decode(&req)
// if err != nil {
// c.JSON(http.StatusOK, gin.H{
// "success": false,
// "message": "无效的参数",
// })
// return
// }
// user := model.User{
// Username: req.Username,
// }
// // Fill attributes
// model.DB.Where(&user).First(&user)
// if user.Id == 0 {
// c.JSON(http.StatusOK, gin.H{
// "success": false,
// "message": "用户不存在",
// })
// return
// }
// myRole := c.GetInt("role")
// if myRole <= user.Role && myRole != common.RoleRootUser {
// c.JSON(http.StatusOK, gin.H{
// "success": false,
// "message": "无权更新同权限等级或更高权限等级的用户信息",
// })
// return
// }
// switch req.Action {
// case "disable":
// user.Status = common.UserStatusDisabled
// if user.Role == common.RoleRootUser {
// c.JSON(http.StatusOK, gin.H{
// "success": false,
// "message": "无法禁用超级管理员用户",
// })
// return
// }
// case "enable":
// user.Status = common.UserStatusEnabled
// case "delete":
// if user.Role == common.RoleRootUser {
// c.JSON(http.StatusOK, gin.H{
// "success": false,
// "message": "无法删除超级管理员用户",
// })
// return
// }
// if err := user.Delete(); err != nil {
// c.JSON(http.StatusOK, gin.H{
// "success": false,
// "message": err.Error(),
// })
// return
// }
// case "promote":
// if myRole != common.RoleRootUser {
// c.JSON(http.StatusOK, gin.H{
// "success": false,
// "message": "普通管理员用户无法提升其他用户为管理员",
// })
// return
// }
// if user.Role >= common.RoleAdminUser {
// c.JSON(http.StatusOK, gin.H{
// "success": false,
// "message": "该用户已经是管理员",
// })
// return
// }
// user.Role = common.RoleAdminUser
// case "demote":
// if user.Role == common.RoleRootUser {
// c.JSON(http.StatusOK, gin.H{
// "success": false,
// "message": "无法降级超级管理员用户",
// })
// return
// }
// if user.Role == common.RoleCommonUser {
// c.JSON(http.StatusOK, gin.H{
// "success": false,
// "message": "该用户已经是普通用户",
// })
// return
// }
// user.Role = common.RoleCommonUser
// }
// if err := user.Update(false); err != nil {
// c.JSON(http.StatusOK, gin.H{
// "success": false,
// "message": err.Error(),
// })
// return
// }
// user.Group = req.NewGroup
// clearUser := model.User{
// Group: user.Group,
// Role: user.Role,
// Status: user.Status,
// }
// c.JSON(http.StatusOK, gin.H{
// "success": true,
// "message": "",
// "data": clearUser,
// })
// return
// }
func ManageUser(c *gin.Context) {
var req ManageRequest
err := json.NewDecoder(c.Request.Body).Decode(&req)
@@ -792,7 +674,7 @@ func TopUp(c *gin.Context) {
return
}
id := c.GetInt("id")
quota, err := model.Redeem(req.Key, id)
quota, upgradedToVIP, err := model.Redeem(req.Key, id) // 调用合并了升级逻辑的 Redeem
if err != nil {
c.JSON(http.StatusOK, gin.H{
"success": false,
@@ -804,6 +686,7 @@ func TopUp(c *gin.Context) {
"success": true,
"message": "",
"data": quota,
"upgradedToVIP": upgradedToVIP, // 返回升级信息
})
return
}