item.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * @Descripttion:
  3. * @version:
  4. * @Author: Neo,Huang
  5. * @Date: 2023-11-18 22:52:59
  6. * @LastEditors: Neo,Huang
  7. * @LastEditTime: 2023-11-19 16:04:30
  8. */
  9. package models
  10. import (
  11. "github.com/astaxie/beego"
  12. "github.com/bitly/go-simplejson"
  13. "box-gm/utils"
  14. )
  15. type ItemConfig struct {
  16. Id int
  17. Name string
  18. Type int
  19. }
  20. type ItemConfigs []*ItemConfig
  21. var itemConfigMap map[int]*ItemConfig
  22. var itemConfigs ItemConfigs
  23. func init() {
  24. itemConfigMap = make(map[int]*ItemConfig)
  25. itemConfigMap[101] = &ItemConfig{
  26. Id: 101,
  27. Name: "金币",
  28. Type: 1,
  29. }
  30. itemConfigMap[102] = &ItemConfig{
  31. Id: 102,
  32. Name: "绑金",
  33. Type: 1,
  34. }
  35. itemConfigMap[103] = &ItemConfig{
  36. Id: 103,
  37. Name: "N1",
  38. Type: 1,
  39. }
  40. itemConfigs = append(itemConfigs, itemConfigMap[101])
  41. itemConfigs = append(itemConfigs, itemConfigMap[102])
  42. itemConfigs = append(itemConfigs, itemConfigMap[103])
  43. }
  44. func InitItemConfig() (int, int) {
  45. body := "{\"name\":\"user_query_item_config\"}"
  46. host := utils.GetKeyConf("gameservers", "login")
  47. sign := utils.Strtomd5(body + utils.GetKeyConf("app", "gameKey"))
  48. url := "http://" + host + "/json?sign=" + sign
  49. buff, err := utils.SendAndRecvHTTP("POST", url, body)
  50. if err != nil {
  51. return 0, 0
  52. }
  53. j, err := simplejson.NewJson(buff)
  54. if err != nil {
  55. return 0, 0
  56. }
  57. code, _ := j.Get("code").Int()
  58. if code != 200 {
  59. return 0, 0
  60. }
  61. arr, err1 := j.Get("config").Array()
  62. if err1 != nil {
  63. return 0, 0
  64. }
  65. oldCount := len(itemConfigs)
  66. for i := 0; i < len(arr); i++ {
  67. itype, _ := j.Get("config").GetIndex(i).Get("type").Int()
  68. id, _ := j.Get("config").GetIndex(i).Get("id").Int()
  69. //话费卡和红包不允许后台发放
  70. // if realItem == "0" && (itype == 100 || itype == 73) {
  71. // continue
  72. // }
  73. item := &ItemConfig{}
  74. item.Id = id
  75. item.Type = itype
  76. item.Name, _ = j.Get("config").GetIndex(i).Get("name").String()
  77. if itemConfigMap[item.Id] == nil {
  78. itemConfigMap[item.Id] = item
  79. itemConfigs = append(itemConfigs, item)
  80. }
  81. }
  82. beego.Info("load item config, oldCount: ", oldCount, "newCount", len(itemConfigs))
  83. return oldCount, len(itemConfigs)
  84. }
  85. func GetItemName(id int) string {
  86. item, ok := itemConfigMap[id]
  87. if !ok {
  88. return ""
  89. }
  90. return item.Name
  91. }
  92. // 获取物品列表
  93. func GetItemInfoList() ItemConfigs {
  94. // InitItemConfig()
  95. return itemConfigs
  96. }