|
|
@@ -1,6 +1,7 @@
|
|
|
package controller
|
|
|
|
|
|
import (
|
|
|
+ "github.com/QuantumNous/new-api/common"
|
|
|
"github.com/QuantumNous/new-api/model"
|
|
|
"github.com/QuantumNous/new-api/service"
|
|
|
"github.com/QuantumNous/new-api/setting/ratio_setting"
|
|
|
@@ -8,6 +9,30 @@ import (
|
|
|
"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) {
|
|
|
pricing := model.GetPricing()
|
|
|
userId, exists := c.Get("id")
|
|
|
@@ -31,6 +56,7 @@ func GetPricing(c *gin.Context) {
|
|
|
}
|
|
|
|
|
|
usableGroup = service.GetUserUsableGroups(group)
|
|
|
+ pricing = filterPricingByUsableGroups(pricing, usableGroup)
|
|
|
// check groupRatio contains usableGroup
|
|
|
for group := range ratio_setting.GetGroupRatioCopy() {
|
|
|
if _, ok := usableGroup[group]; !ok {
|