|
@@ -5,7 +5,6 @@ import (
|
|
|
"encoding/json"
|
|
"encoding/json"
|
|
|
"errors"
|
|
"errors"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
- "github.com/gin-gonic/gin"
|
|
|
|
|
"io"
|
|
"io"
|
|
|
"net/http"
|
|
"net/http"
|
|
|
"one-api/common"
|
|
"one-api/common"
|
|
@@ -16,6 +15,8 @@ import (
|
|
|
relayconstant "one-api/relay/constant"
|
|
relayconstant "one-api/relay/constant"
|
|
|
"one-api/service"
|
|
"one-api/service"
|
|
|
"one-api/setting/ratio_setting"
|
|
"one-api/setting/ratio_setting"
|
|
|
|
|
+
|
|
|
|
|
+ "github.com/gin-gonic/gin"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -52,7 +53,13 @@ func RelayTaskSubmit(c *gin.Context, relayMode int) (taskErr *dto.TaskError) {
|
|
|
|
|
|
|
|
// 预扣
|
|
// 预扣
|
|
|
groupRatio := ratio_setting.GetGroupRatio(relayInfo.Group)
|
|
groupRatio := ratio_setting.GetGroupRatio(relayInfo.Group)
|
|
|
- ratio := modelPrice * groupRatio
|
|
|
|
|
|
|
+ var ratio float64
|
|
|
|
|
+ userGroupRatio, hasUserGroupRatio := ratio_setting.GetGroupGroupRatio(relayInfo.UserGroup, relayInfo.Group)
|
|
|
|
|
+ if hasUserGroupRatio {
|
|
|
|
|
+ ratio = modelPrice * userGroupRatio
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ratio = modelPrice * groupRatio
|
|
|
|
|
+ }
|
|
|
userQuota, err := model.GetUserQuota(relayInfo.UserId, false)
|
|
userQuota, err := model.GetUserQuota(relayInfo.UserId, false)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
taskErr = service.TaskErrorWrapper(err, "get_user_quota_failed", http.StatusInternalServerError)
|
|
taskErr = service.TaskErrorWrapper(err, "get_user_quota_failed", http.StatusInternalServerError)
|
|
@@ -121,10 +128,17 @@ func RelayTaskSubmit(c *gin.Context, relayMode int) (taskErr *dto.TaskError) {
|
|
|
}
|
|
}
|
|
|
if quota != 0 {
|
|
if quota != 0 {
|
|
|
tokenName := c.GetString("token_name")
|
|
tokenName := c.GetString("token_name")
|
|
|
- logContent := fmt.Sprintf("模型固定价格 %.2f,分组倍率 %.2f,操作 %s", modelPrice, groupRatio, relayInfo.Action)
|
|
|
|
|
|
|
+ gRatio := groupRatio
|
|
|
|
|
+ if hasUserGroupRatio {
|
|
|
|
|
+ gRatio = userGroupRatio
|
|
|
|
|
+ }
|
|
|
|
|
+ logContent := fmt.Sprintf("模型固定价格 %.2f,分组倍率 %.2f,操作 %s", modelPrice, gRatio, relayInfo.Action)
|
|
|
other := make(map[string]interface{})
|
|
other := make(map[string]interface{})
|
|
|
other["model_price"] = modelPrice
|
|
other["model_price"] = modelPrice
|
|
|
other["group_ratio"] = groupRatio
|
|
other["group_ratio"] = groupRatio
|
|
|
|
|
+ if hasUserGroupRatio {
|
|
|
|
|
+ other["user_group_ratio"] = userGroupRatio
|
|
|
|
|
+ }
|
|
|
model.RecordConsumeLog(c, relayInfo.UserId, relayInfo.ChannelId, 0, 0,
|
|
model.RecordConsumeLog(c, relayInfo.UserId, relayInfo.ChannelId, 0, 0,
|
|
|
modelName, tokenName, quota, logContent, relayInfo.TokenId, userQuota, 0, false, relayInfo.Group, other)
|
|
modelName, tokenName, quota, logContent, relayInfo.TokenId, userQuota, 0, false, relayInfo.Group, other)
|
|
|
model.UpdateUserUsedQuotaAndRequestCount(relayInfo.UserId, quota)
|
|
model.UpdateUserUsedQuotaAndRequestCount(relayInfo.UserId, quota)
|