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
42 lines
932 B
Go
42 lines
932 B
Go
package common
|
|
|
|
import (
|
|
"encoding/json"
|
|
"sync"
|
|
)
|
|
|
|
var topupGroupRatio = map[string]float64{
|
|
"default": 1,
|
|
"vip": 1,
|
|
"svip": 1,
|
|
}
|
|
var topupGroupRatioMutex sync.RWMutex
|
|
|
|
func TopupGroupRatio2JSONString() string {
|
|
topupGroupRatioMutex.RLock()
|
|
defer topupGroupRatioMutex.RUnlock()
|
|
jsonBytes, err := json.Marshal(topupGroupRatio)
|
|
if err != nil {
|
|
SysError("error marshalling topup group ratio: " + err.Error())
|
|
}
|
|
return string(jsonBytes)
|
|
}
|
|
|
|
func UpdateTopupGroupRatioByJSONString(jsonStr string) error {
|
|
topupGroupRatioMutex.Lock()
|
|
defer topupGroupRatioMutex.Unlock()
|
|
topupGroupRatio = make(map[string]float64)
|
|
return json.Unmarshal([]byte(jsonStr), &topupGroupRatio)
|
|
}
|
|
|
|
func GetTopupGroupRatio(name string) float64 {
|
|
topupGroupRatioMutex.RLock()
|
|
defer topupGroupRatioMutex.RUnlock()
|
|
ratio, ok := topupGroupRatio[name]
|
|
if !ok {
|
|
SysError("topup group ratio not found: " + name)
|
|
return 1
|
|
}
|
|
return ratio
|
|
}
|