123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- /*
- * @Descripttion:
- * @version:
- * @Author: Neo,Huang
- * @Date: 2023-11-18 22:52:59
- * @LastEditors: Neo,Huang
- * @LastEditTime: 2023-11-19 16:04:30
- */
- package models
- import (
- "github.com/astaxie/beego"
- "github.com/bitly/go-simplejson"
- "box-gm/utils"
- )
- type ItemConfig struct {
- Id int
- Name string
- Type int
- }
- type ItemConfigs []*ItemConfig
- var itemConfigMap map[int]*ItemConfig
- var itemConfigs ItemConfigs
- func init() {
- itemConfigMap = make(map[int]*ItemConfig)
- itemConfigMap[101] = &ItemConfig{
- Id: 101,
- Name: "金币",
- Type: 1,
- }
- itemConfigMap[102] = &ItemConfig{
- Id: 102,
- Name: "绑金",
- Type: 1,
- }
- itemConfigMap[103] = &ItemConfig{
- Id: 103,
- Name: "N1",
- Type: 1,
- }
- itemConfigs = append(itemConfigs, itemConfigMap[101])
- itemConfigs = append(itemConfigs, itemConfigMap[102])
- itemConfigs = append(itemConfigs, itemConfigMap[103])
- }
- func InitItemConfig() (int, int) {
- body := "{\"name\":\"user_query_item_config\"}"
- host := utils.GetKeyConf("gameservers", "login")
- sign := utils.Strtomd5(body + utils.GetKeyConf("app", "gameKey"))
- url := "http://" + host + "/json?sign=" + sign
- buff, err := utils.SendAndRecvHTTP("POST", url, body)
- if err != nil {
- return 0, 0
- }
- j, err := simplejson.NewJson(buff)
- if err != nil {
- return 0, 0
- }
- code, _ := j.Get("code").Int()
- if code != 200 {
- return 0, 0
- }
- arr, err1 := j.Get("config").Array()
- if err1 != nil {
- return 0, 0
- }
- oldCount := len(itemConfigs)
- for i := 0; i < len(arr); i++ {
- itype, _ := j.Get("config").GetIndex(i).Get("type").Int()
- id, _ := j.Get("config").GetIndex(i).Get("id").Int()
- //话费卡和红包不允许后台发放
- // if realItem == "0" && (itype == 100 || itype == 73) {
- // continue
- // }
- item := &ItemConfig{}
- item.Id = id
- item.Type = itype
- item.Name, _ = j.Get("config").GetIndex(i).Get("name").String()
- if itemConfigMap[item.Id] == nil {
- itemConfigMap[item.Id] = item
- itemConfigs = append(itemConfigs, item)
- }
- }
- beego.Info("load item config, oldCount: ", oldCount, "newCount", len(itemConfigs))
- return oldCount, len(itemConfigs)
- }
- func GetItemName(id int) string {
- item, ok := itemConfigMap[id]
- if !ok {
- return ""
- }
- return item.Name
- }
- // 获取物品列表
- func GetItemInfoList() ItemConfigs {
- // InitItemConfig()
- return itemConfigs
- }
|