shop.go 874 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package controller
  2. import (
  3. "bet24.com/log"
  4. "bet24.com/servers/coreservice/client"
  5. "encoding/json"
  6. )
  7. // 汇率
  8. type exchangeRate struct {
  9. Currency string // 币种
  10. CountryName string // 国家名称
  11. CountryCode string // 国家编码
  12. Rate float64 // 汇率
  13. }
  14. func GetExchangeRate(currency string) *exchangeRate {
  15. var list []*exchangeRate
  16. respExchange := client.GetExchangeRateList()
  17. if respExchange.RetCode != 1 {
  18. log.Error("%s PayRequest client ==> %+v", "GetExchangeRate.GetExchangeRateList", respExchange)
  19. return nil
  20. }
  21. if err := json.Unmarshal([]byte(respExchange.Data), &list); err != nil {
  22. log.Error("%s PayRequest json unmarshal err %v", "GetExchangeRate.GetExchangeRateList", err)
  23. return nil
  24. }
  25. var info *exchangeRate
  26. for _, v := range list {
  27. info = v
  28. if info.Currency == currency {
  29. return info
  30. }
  31. }
  32. return info
  33. }