shop.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package shop
  2. import (
  3. "bet24.com/log"
  4. "bet24.com/servers/coreservice/client"
  5. item "bet24.com/servers/micros/item_inventory/proto"
  6. "encoding/json"
  7. "time"
  8. )
  9. var shopmgr *shopManager
  10. type shopManager struct {
  11. shop_list []*Shop_Item
  12. }
  13. type Shop_Item struct {
  14. ProductId string //产品ID
  15. ProductName string //产品名称
  16. Amount int //数量
  17. Price float64 //价格(分或钻石)
  18. PayType int //支付类型(1=金币 0=钻石)
  19. ShopType int //产品类型(1=金币 2=钻石 3=炮台 4=礼包)
  20. IsHot int //是否热销 1=热销
  21. Bonus int // 额外赠送(多送百分比)
  22. Extra []item.ItemPack // 扩展信息
  23. ProductDesc string // 产品描述
  24. }
  25. func getShopManager() *shopManager {
  26. if shopmgr == nil {
  27. shopmgr = new(shopManager)
  28. shopmgr.refreshData()
  29. }
  30. return shopmgr
  31. }
  32. func (this *shopManager) refreshData() {
  33. this.load()
  34. time.AfterFunc(1*time.Minute, this.refreshData)
  35. }
  36. func (this *shopManager) load() {
  37. //// 获取汇率
  38. //info := GetExchangeRate("")
  39. //if info == nil {
  40. // log.Error("%s 获取汇率失败 %+v", "getShopList", info)
  41. // return items
  42. //}
  43. resp := client.GetShopList(0, 0, "")
  44. if resp.RetCode != 1 {
  45. return
  46. }
  47. if resp.Data == "" {
  48. return
  49. }
  50. if err := json.Unmarshal([]byte(resp.Data), &this.shop_list); err != nil {
  51. log.Error("shop.load unmarshal fail %v", err)
  52. return
  53. }
  54. return
  55. }
  56. func (this *shopManager) getProduct(productId string) *Shop_Item {
  57. for _, v := range this.shop_list {
  58. if v.ProductId == productId {
  59. return v
  60. }
  61. }
  62. return nil
  63. }
  64. func (this *shopManager) getProductName(productId string) string {
  65. for _, v := range this.shop_list {
  66. if v.ProductId == productId {
  67. return v.ProductDesc
  68. }
  69. }
  70. return ""
  71. }