feat(custom): CNY native billing, daily check-in button, subscription plans page, usage docs and promo banner
Based on QuantumNous/new-api v1.0.0-rc.36 (shallow history squashed). - CNY quota display mode: RMB-denominated top-up and crediting across Epay/Waffo channels - New CheckinButton in both authenticated and public headers (Turnstile supported) - New /subscribe page with public plan snapshot, Alipay/balance payment, auto group upgrade/reset - New /docs 12-section beginner guide with anchor navigation - New home PromoBanner linking to /docs; i18n synced (en/zh/zh-TW/fr/ja/ru/vi) - README: document custom features, live demo https://ai.88531.cn
This commit is contained in:
commit
14a9acd368
2368 files changed
+551035
No files matched your search
@@ -0,0 +1,120 @@
|
||||
package ratio_setting
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/QuantumNous/new-api/common"
|
||||
"github.com/QuantumNous/new-api/setting/config"
|
||||
"github.com/QuantumNous/new-api/types"
|
||||
)
|
||||
|
||||
var defaultGroupRatio = map[string]float64{
|
||||
"default": 1,
|
||||
"vip": 1,
|
||||
"svip": 1,
|
||||
}
|
||||
|
||||
var groupRatioMap = types.NewRWMap[string, float64]()
|
||||
|
||||
var defaultGroupGroupRatio = map[string]map[string]float64{
|
||||
"vip": {
|
||||
"edit_this": 0.9,
|
||||
},
|
||||
}
|
||||
|
||||
var groupGroupRatioMap = types.NewRWMap[string, map[string]float64]()
|
||||
|
||||
var defaultGroupSpecialUsableGroup = map[string]map[string]string{}
|
||||
|
||||
type GroupRatioSetting struct {
|
||||
GroupRatio *types.RWMap[string, float64] `json:"group_ratio"`
|
||||
GroupGroupRatio *types.RWMap[string, map[string]float64] `json:"group_group_ratio"`
|
||||
GroupSpecialUsableGroup *types.RWMap[string, map[string]string] `json:"group_special_usable_group"`
|
||||
}
|
||||
|
||||
var groupRatioSetting GroupRatioSetting
|
||||
|
||||
func init() {
|
||||
groupSpecialUsableGroup := types.NewRWMap[string, map[string]string]()
|
||||
groupSpecialUsableGroup.AddAll(defaultGroupSpecialUsableGroup)
|
||||
|
||||
groupRatioMap.AddAll(defaultGroupRatio)
|
||||
groupGroupRatioMap.AddAll(defaultGroupGroupRatio)
|
||||
|
||||
groupRatioSetting = GroupRatioSetting{
|
||||
GroupSpecialUsableGroup: groupSpecialUsableGroup,
|
||||
GroupRatio: groupRatioMap,
|
||||
GroupGroupRatio: groupGroupRatioMap,
|
||||
}
|
||||
|
||||
config.GlobalConfig.Register("group_ratio_setting", &groupRatioSetting)
|
||||
}
|
||||
|
||||
func GetGroupRatioSetting() *GroupRatioSetting {
|
||||
if groupRatioSetting.GroupSpecialUsableGroup == nil {
|
||||
groupRatioSetting.GroupSpecialUsableGroup = types.NewRWMap[string, map[string]string]()
|
||||
groupRatioSetting.GroupSpecialUsableGroup.AddAll(defaultGroupSpecialUsableGroup)
|
||||
}
|
||||
return &groupRatioSetting
|
||||
}
|
||||
|
||||
func GetGroupRatioCopy() map[string]float64 {
|
||||
return groupRatioMap.ReadAll()
|
||||
}
|
||||
|
||||
func ContainsGroupRatio(name string) bool {
|
||||
_, ok := groupRatioMap.Get(name)
|
||||
return ok
|
||||
}
|
||||
|
||||
func GroupRatio2JSONString() string {
|
||||
return groupRatioMap.MarshalJSONString()
|
||||
}
|
||||
|
||||
func UpdateGroupRatioByJSONString(jsonStr string) error {
|
||||
return types.LoadFromJsonString(groupRatioMap, jsonStr)
|
||||
}
|
||||
|
||||
func GetGroupRatio(name string) float64 {
|
||||
ratio, ok := groupRatioMap.Get(name)
|
||||
if !ok {
|
||||
common.SysLog("group ratio not found: " + name)
|
||||
return 1
|
||||
}
|
||||
return ratio
|
||||
}
|
||||
|
||||
func GetGroupGroupRatio(userGroup, usingGroup string) (float64, bool) {
|
||||
gp, ok := groupGroupRatioMap.Get(userGroup)
|
||||
if !ok {
|
||||
return -1, false
|
||||
}
|
||||
ratio, ok := gp[usingGroup]
|
||||
if !ok {
|
||||
return -1, false
|
||||
}
|
||||
return ratio, true
|
||||
}
|
||||
|
||||
func GroupGroupRatio2JSONString() string {
|
||||
return groupGroupRatioMap.MarshalJSONString()
|
||||
}
|
||||
|
||||
func UpdateGroupGroupRatioByJSONString(jsonStr string) error {
|
||||
return types.LoadFromJsonString(groupGroupRatioMap, jsonStr)
|
||||
}
|
||||
|
||||
func CheckGroupRatio(jsonStr string) error {
|
||||
checkGroupRatio := make(map[string]float64)
|
||||
err := json.Unmarshal([]byte(jsonStr), &checkGroupRatio)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for name, ratio := range checkGroupRatio {
|
||||
if ratio < 0 {
|
||||
return errors.New("group ratio must be not less than 0: " + name)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user