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
07843d78
authored
Apr 07, 2026
by
bbbugg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(pricing): add filtering for pricing based on usable groups
parent
960bf9c4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
0 deletions
+26
-0
controller/pricing.go
+26
-0
No files found.
controller/pricing.go
View file @
07843d78
package
controller
package
controller
import
(
import
(
"github.com/QuantumNous/new-api/common"
"github.com/QuantumNous/new-api/model"
"github.com/QuantumNous/new-api/model"
"github.com/QuantumNous/new-api/service"
"github.com/QuantumNous/new-api/service"
"github.com/QuantumNous/new-api/setting/ratio_setting"
"github.com/QuantumNous/new-api/setting/ratio_setting"
...
@@ -8,6 +9,30 @@ import (
...
@@ -8,6 +9,30 @@ import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
)
)
func
filterPricingByUsableGroups
(
pricing
[]
model
.
Pricing
,
usableGroup
map
[
string
]
string
)
[]
model
.
Pricing
{
if
len
(
pricing
)
==
0
{
return
pricing
}
if
len
(
usableGroup
)
==
0
{
return
[]
model
.
Pricing
{}
}
filtered
:=
make
([]
model
.
Pricing
,
0
,
len
(
pricing
))
for
_
,
item
:=
range
pricing
{
if
common
.
StringsContains
(
item
.
EnableGroup
,
"all"
)
{
filtered
=
append
(
filtered
,
item
)
continue
}
for
_
,
group
:=
range
item
.
EnableGroup
{
if
_
,
ok
:=
usableGroup
[
group
];
ok
{
filtered
=
append
(
filtered
,
item
)
break
}
}
}
return
filtered
}
func
GetPricing
(
c
*
gin
.
Context
)
{
func
GetPricing
(
c
*
gin
.
Context
)
{
pricing
:=
model
.
GetPricing
()
pricing
:=
model
.
GetPricing
()
userId
,
exists
:=
c
.
Get
(
"id"
)
userId
,
exists
:=
c
.
Get
(
"id"
)
...
@@ -31,6 +56,7 @@ func GetPricing(c *gin.Context) {
...
@@ -31,6 +56,7 @@ func GetPricing(c *gin.Context) {
}
}
usableGroup
=
service
.
GetUserUsableGroups
(
group
)
usableGroup
=
service
.
GetUserUsableGroups
(
group
)
pricing
=
filterPricingByUsableGroups
(
pricing
,
usableGroup
)
// check groupRatio contains usableGroup
// check groupRatio contains usableGroup
for
group
:=
range
ratio_setting
.
GetGroupRatioCopy
()
{
for
group
:=
range
ratio_setting
.
GetGroupRatioCopy
()
{
if
_
,
ok
:=
usableGroup
[
group
];
!
ok
{
if
_
,
ok
:=
usableGroup
[
group
];
!
ok
{
...
...
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