configs.go 1.56 KB
package ht_cardholder

import (
	"apigame/api-util/umysql"
	"apigame/lx-util/lxalilog"
	"apigame/service/constd"
	"fmt"
	"github.com/astaxie/beego/logs"
)

// Init 初始化
func Init() {

	NewConfigs()

	TryUpdateConfigs()

	//DumpConfigs()
}

// TryUpdateConfigs 尝试更新配置表
func TryUpdateConfigs() {
	LoadConfigs()
}

// LoadConfigs 读取mysql配置
func LoadConfigs() {
	configTableName := new(CardActivityConfig).TableName()
	// 找到当前开放的活动
	configOpen := CardActivityUpdateConfig{Id: 0}
	{
		conf := make([]CardActivityUpdateConfig, 0)
		sql := fmt.Sprintf("select id,status,update_time from %s", configTableName)
		err := umysql.FindSql(constd.MYSQL_MERGECONFIG, sql, &conf)
		if err != nil {
			lxalilog.Errors(err, sql, constd.GAME_ID_HT)
			return
		}
		for _, config := range conf {
			if config.Status != 0 {
				configOpen = config
				continue
			}
		}
		fmt.Println(configOpen)
	}
	// 没有开放的活动
	if configOpen.Id == 0 {
		return
	}
	// 更新数据
	if configOpen.Id != Config.Raw.Id || configOpen.UpdateTime != Config.Raw.UpdateTime {
		logs.Debug("__________________尝试更新活动条目ID:", configOpen.Id)
		confNew := CardActivityConfigRaw{}
		sql := fmt.Sprintf("select * from %s where id=%d limit 1", configTableName, configOpen.Id)
		err := umysql.FindOneSql(constd.MYSQL_MERGECONFIG, sql, &confNew)
		if err != nil {
			lxalilog.Errors(err, sql, constd.GAME_ID_HT, configOpen.Id)
			return
		}
		logs.Debug("__________________更新活动条目ID:", confNew.Id)
		ConfigRaws = confNew
		ConfigDecode()
	}
}

func DumpConfigs() {

}