giftmanager_system.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package gift
  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. pb "bet24.com/servers/micros/giftservice/proto"
  10. platformconfig "bet24.com/servers/micros/platformconfig/proto"
  11. )
  12. const config_key = "giftservice_config"
  13. // 加载配置信息
  14. func (gm *giftmanager) loadConfig() {
  15. time.AfterFunc(5*time.Minute, gm.loadConfig)
  16. configString := platformconfig.GetConfig(config_key)
  17. if configString == "" {
  18. data, err := os.ReadFile("serviceconf/giftservice_config.json")
  19. if err != nil {
  20. log.Release("giftmanager.loadConfig.loadData read json failed")
  21. return
  22. }
  23. configString = string(data)
  24. platformconfig.SetConfig(config_key, configString)
  25. }
  26. if configString == gm.lastConfigString {
  27. return
  28. }
  29. gm.lastConfigString = configString
  30. err := json.Unmarshal([]byte(configString), &gm.giftlist)
  31. if err == nil {
  32. log.Release("giftmanager.loadConfig Unmarshal config [%s] err:%v", configString, err)
  33. return
  34. }
  35. for k, v := range gm.giftlist {
  36. // 根据用户ID转换货币
  37. if v.PayType == pb.PayType_RMB && v.ProductId != "" {
  38. respProduct := coreClient.GetProduct(0, 0, v.ProductId)
  39. if respProduct.RetCode != 1 {
  40. continue
  41. }
  42. var item shop.Shop_Item
  43. if err := json.Unmarshal([]byte(respProduct.Data), &item); err != nil {
  44. log.Error("%s GetProduct json unmarshal err %v", "giftmanager.loadProductItem", err)
  45. continue
  46. }
  47. gm.giftlist[k].Price = item.Price
  48. gm.giftlist[k].Items = item.Extra
  49. }
  50. }
  51. }