Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

42 lignes
932 B

  1. package common
  2. import (
  3. "encoding/json"
  4. "sync"
  5. )
  6. var topupGroupRatio = map[string]float64{
  7. "default": 1,
  8. "vip": 1,
  9. "svip": 1,
  10. }
  11. var topupGroupRatioMutex sync.RWMutex
  12. func TopupGroupRatio2JSONString() string {
  13. topupGroupRatioMutex.RLock()
  14. defer topupGroupRatioMutex.RUnlock()
  15. jsonBytes, err := json.Marshal(topupGroupRatio)
  16. if err != nil {
  17. SysError("error marshalling topup group ratio: " + err.Error())
  18. }
  19. return string(jsonBytes)
  20. }
  21. func UpdateTopupGroupRatioByJSONString(jsonStr string) error {
  22. topupGroupRatioMutex.Lock()
  23. defer topupGroupRatioMutex.Unlock()
  24. topupGroupRatio = make(map[string]float64)
  25. return json.Unmarshal([]byte(jsonStr), &topupGroupRatio)
  26. }
  27. func GetTopupGroupRatio(name string) float64 {
  28. topupGroupRatioMutex.RLock()
  29. defer topupGroupRatioMutex.RUnlock()
  30. ratio, ok := topupGroupRatio[name]
  31. if !ok {
  32. SysError("topup group ratio not found: " + name)
  33. return 1
  34. }
  35. return ratio
  36. }