vipmgr_system.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package vip
  2. import (
  3. "encoding/json"
  4. "os"
  5. "time"
  6. "bet24.com/log"
  7. coreClient "bet24.com/servers/coreservice/client"
  8. "bet24.com/servers/coreservice/shop"
  9. platformconfig "bet24.com/servers/micros/platformconfig/proto"
  10. )
  11. const config_key = "newvip_config"
  12. // 加载配置信息
  13. func (this *vipmgr) loadConfig() {
  14. this.loadRedisConfig()
  15. this.loadProductItem()
  16. go time.AfterFunc(5*time.Minute, this.loadConfig)
  17. }
  18. // 加载redis配置
  19. func (this *vipmgr) loadRedisConfig() {
  20. // if data := platformconfig.GetConfig(config_key); data != "" {
  21. // if err := json.Unmarshal([]byte(data), &this); err == nil {
  22. // return
  23. // }
  24. // return
  25. // }
  26. data, err := os.ReadFile("serviceconf/newvip_config.json")
  27. if err != nil {
  28. log.Release("read config failed serviceconf/newvip_config.json %v", err)
  29. }
  30. if err = json.Unmarshal(data, &this); err == nil {
  31. platformconfig.SetConfig(config_key, string(data))
  32. return
  33. }
  34. log.Release("Unmarshal config [%s] err:%v", string(data), err)
  35. }
  36. // 加载对应产品的道具
  37. func (this *vipmgr) loadProductItem() {
  38. for key, value := range this.PurchasePackages {
  39. respProduct := coreClient.GetProduct(0, 0, value.ProductId)
  40. if respProduct.RetCode != 1 {
  41. continue
  42. }
  43. var item shop.Shop_Item
  44. if err := json.Unmarshal([]byte(respProduct.Data), &item); err != nil {
  45. log.Error("%s GetProduct json unmarshal err %v", "vipmgr.loadProductItem", err)
  46. continue
  47. }
  48. this.PurchasePackages[key].Price = item.Price
  49. this.PurchasePackages[key].Items = item.Extra
  50. }
  51. }