registry.go 1.89 KB
package configs

import (
	"apigame/service-common/svmysql"
	"apigame/service-common/svredis"
	"apigame/util/util-lx/lxalilog"
	"fmt"
)

// GetApiGameConfig 获取 api游戏配置
func GetApiGameConfig(gameId string) (conf *ApiGameConfig, err error) {
	conf = new(ApiGameConfig)
	has := svredis.LoadData(gameId, conf)
	if has {
		fmt.Println("dwjw GetApiGameConfig use cache")
		return
	}
	has, err = svmysql.First(conf, gameId)
	if err != nil {
		lxalilog.Errors(err, "configs.GetApiGameConfig error", gameId)
		return
	}
	if !has {
		return
	}
	fmt.Println("dwjw GetApiGameConfig save cache")
	svredis.SaveData(gameId, conf)

	return
}

// GetCardActivityConfig 获取 卡牌活动配置
func GetCardActivityConfig(gameId string) (conf *CardActivityConfig, has bool) {
	var err error
	conf = new(CardActivityConfig)
	has = svredis.LoadData(gameId, conf)
	if has {
		fmt.Println("dwjw GetCardActivityConfig use cache")
		return
	}
	confRaw := new(CardActivityConfigRaw)
	has, err = svmysql.First(confRaw, gameId)
	if err != nil {
		lxalilog.Errors(err, "configs.GetCardActivityConfig error", gameId)
		return
	}
	if !has {
		return
	}

	conf.Decode(gameId, confRaw)

	fmt.Println("dwjw GetCardActivityConfig save cache")
	svredis.SaveData(gameId, conf)

	return
}

// GetRoomRankConfig 获取 房间排行活动配置
func GetRoomRankConfig(gameId string) (conf *RoomRankConfig, has bool) {
	var err error
	conf = new(RoomRankConfig)
	has = svredis.LoadData(gameId, conf)
	if has {
		fmt.Println("dwjw GetRoomRankConfig use cache")
		return
	}
	confRaw := new(RoomRankConfigRaw)
	has, err = svmysql.First(confRaw, gameId)
	if err != nil {
		lxalilog.Errors(err, "configs.GetRoomRankConfig error", gameId)
		return
	}
	if !has {

		return
	}

	conf.Decode(gameId, confRaw)

	fmt.Println("dwjw GetRoomRankConfig save cache")
	fmt.Println("dwjw🐸", conf.Robot)
	fmt.Println("dwjw🐸", conf.Room)
	svredis.SaveData(gameId, conf)

	return
}