shop.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package shop
  2. import (
  3. "encoding/json"
  4. "bet24.com/log"
  5. coreClient "bet24.com/servers/coreservice/client"
  6. item "bet24.com/servers/micros/item_inventory/proto"
  7. )
  8. type Shop_Item struct {
  9. ProductId string // 产品ID
  10. ProductName string // 产品名称
  11. Price float64 // 基础价格(充值时是美元)
  12. PayType int // 支付类型(1=RMB 0=钻石 2=金币)
  13. ShopType int // 产品类型(1=金币 2=钻石 3=炮台 4=礼包)
  14. IsHot int // 是否热销 1=热销
  15. Bonus int // 额外赠送(多送百分比)
  16. Extra []item.ItemPack // 扩展信息
  17. Status int // 状态(1=正常 2=不可用或没有购买次数)
  18. Rate int // 比率
  19. }
  20. func GetProduct(productId string) *Shop_Item {
  21. var item *Shop_Item
  22. respProduct := coreClient.GetProduct(0, 0, productId)
  23. if respProduct.RetCode != 1 {
  24. log.Error("%s GenOrder client ==> %+v", "GetProduct.GetProduct", respProduct)
  25. return item
  26. }
  27. if err := json.Unmarshal([]byte(respProduct.Data), &item); err != nil {
  28. log.Error("%s GenOrder json unmarshal err %v", "GetProduct.GetProduct", err)
  29. return item
  30. }
  31. return item
  32. }
  33. // 汇率
  34. type exchangeRate struct {
  35. Currency string // 币种
  36. CountryName string // 国家名称
  37. CountryCode string // 国家编码
  38. Rate float64 // 汇率
  39. }
  40. func GetExchangeRate(currency string) *exchangeRate {
  41. var list []*exchangeRate
  42. respExchange := coreClient.GetExchangeRateList()
  43. if respExchange.RetCode != 1 {
  44. log.Error("%s PayRequest client ==> %+v", "GetExchangeRate.GetExchangeRateList", respExchange)
  45. return nil
  46. }
  47. if err := json.Unmarshal([]byte(respExchange.Data), &list); err != nil {
  48. log.Error("%s PayRequest json unmarshal err %v", "GetExchangeRate.GetExchangeRateList", err)
  49. return nil
  50. }
  51. var info *exchangeRate
  52. for _, v := range list {
  53. info = v
  54. if info.Currency == currency {
  55. return info
  56. }
  57. }
  58. return info
  59. }