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
2c20827a
authored
Jun 22, 2025
by
creamlike1024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: mj userGroupRatio
parent
d084083e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
15 deletions
+39
-15
relay/relay-mj.go
+39
-15
No files found.
relay/relay-mj.go
View file @
2c20827a
...
...
@@ -185,7 +185,13 @@ func RelaySwapFace(c *gin.Context) *dto.MidjourneyResponse {
}
}
groupRatio
:=
ratio_setting
.
GetGroupRatio
(
group
)
ratio
:=
modelPrice
*
groupRatio
var
ratio
float64
userGroupRatio
,
hasUserGroupRatio
:=
ratio_setting
.
GetGroupGroupRatio
(
relayInfo
.
UserGroup
,
group
)
if
hasUserGroupRatio
{
ratio
=
modelPrice
*
userGroupRatio
}
else
{
ratio
=
modelPrice
*
groupRatio
}
userQuota
,
err
:=
model
.
GetUserQuota
(
userId
,
false
)
if
err
!=
nil
{
return
&
dto
.
MidjourneyResponse
{
...
...
@@ -215,19 +221,20 @@ func RelaySwapFace(c *gin.Context) *dto.MidjourneyResponse {
common
.
SysError
(
"error consuming token remain quota: "
+
err
.
Error
())
}
//err = model.CacheUpdateUserQuota(userId)
if
err
!=
nil
{
common
.
SysError
(
"error update user quota cache: "
+
err
.
Error
())
}
//
if err != nil {
//
common.SysError("error update user quota cache: " + err.Error())
//
}
if
quota
!=
0
{
tokenName
:=
c
.
GetString
(
"token_name"
)
logContent
:=
fmt
.
Sprintf
(
"模型固定价格 %.2f,分组倍率 %.2f,操作 %s"
,
modelPrice
,
groupRatio
,
constant
.
MjActionSwapFace
)
other
:=
make
(
map
[
string
]
interface
{})
other
[
"model_price"
]
=
modelPrice
other
[
"group_ratio"
]
=
groupRatio
gRatio
:=
groupRatio
if
hasUserGroupRatio
{
gRatio
=
userGroupRatio
}
logContent
:=
fmt
.
Sprintf
(
"模型固定价格 %.2f,分组倍率 %.2f,操作 %s"
,
modelPrice
,
gRatio
,
constant
.
MjActionSwapFace
)
other
:=
genMjOtherInfo
(
modelPrice
,
groupRatio
,
userGroupRatio
,
hasUserGroupRatio
)
model
.
RecordConsumeLog
(
c
,
userId
,
channelId
,
0
,
0
,
modelName
,
tokenName
,
quota
,
logContent
,
tokenId
,
userQuota
,
0
,
false
,
group
,
other
)
model
.
UpdateUserUsedQuotaAndRequestCount
(
userId
,
quota
)
channelId
:=
c
.
GetInt
(
"channel_id"
)
model
.
UpdateChannelUsedQuota
(
channelId
,
quota
)
}
}
...
...
@@ -491,7 +498,13 @@ func RelayMidjourneySubmit(c *gin.Context, relayMode int) *dto.MidjourneyRespons
}
}
groupRatio
:=
ratio_setting
.
GetGroupRatio
(
group
)
ratio
:=
modelPrice
*
groupRatio
var
ratio
float64
userGroupRatio
,
hasUserGroupRatio
:=
ratio_setting
.
GetGroupGroupRatio
(
relayInfo
.
UserGroup
,
group
)
if
hasUserGroupRatio
{
ratio
=
modelPrice
*
userGroupRatio
}
else
{
ratio
=
modelPrice
*
groupRatio
}
userQuota
,
err
:=
model
.
GetUserQuota
(
userId
,
false
)
if
err
!=
nil
{
return
&
dto
.
MidjourneyResponse
{
...
...
@@ -522,14 +535,15 @@ func RelayMidjourneySubmit(c *gin.Context, relayMode int) *dto.MidjourneyRespons
}
if
quota
!=
0
{
tokenName
:=
c
.
GetString
(
"token_name"
)
logContent
:=
fmt
.
Sprintf
(
"模型固定价格 %.2f,分组倍率 %.2f,操作 %s,ID %s"
,
modelPrice
,
groupRatio
,
midjRequest
.
Action
,
midjResponse
.
Result
)
other
:=
make
(
map
[
string
]
interface
{})
other
[
"model_price"
]
=
modelPrice
other
[
"group_ratio"
]
=
groupRatio
gRatio
:=
groupRatio
if
hasUserGroupRatio
{
gRatio
=
userGroupRatio
}
logContent
:=
fmt
.
Sprintf
(
"模型固定价格 %.2f,分组倍率 %.2f,操作 %s,ID %s"
,
modelPrice
,
gRatio
,
midjRequest
.
Action
,
midjResponse
.
Result
)
other
:=
genMjOtherInfo
(
modelPrice
,
groupRatio
,
userGroupRatio
,
hasUserGroupRatio
)
model
.
RecordConsumeLog
(
c
,
userId
,
channelId
,
0
,
0
,
modelName
,
tokenName
,
quota
,
logContent
,
tokenId
,
userQuota
,
0
,
false
,
group
,
other
)
model
.
UpdateUserUsedQuotaAndRequestCount
(
userId
,
quota
)
channelId
:=
c
.
GetInt
(
"channel_id"
)
model
.
UpdateChannelUsedQuota
(
channelId
,
quota
)
}
}
...
...
@@ -659,3 +673,13 @@ func getMjRequestPath(path string) string {
}
return
requestURL
}
func
genMjOtherInfo
(
modelPrice
,
groupRatio
,
userGroupRatio
float64
,
hasUserGroupRatio
bool
)
map
[
string
]
interface
{}
{
other
:=
make
(
map
[
string
]
interface
{})
other
[
"model_price"
]
=
modelPrice
other
[
"group_ratio"
]
=
groupRatio
if
hasUserGroupRatio
&&
userGroupRatio
>
0
{
other
[
"user_group_ratio"
]
=
userGroupRatio
}
return
other
}
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