mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-03-30 07:37:23 +00:00
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
|
|
}
|