Пример #1
0
func GetPlayer(id string) (playerObj *player.Player, exists bool, err error) {
	command := "SELECT Name, UnionId, ExtraMsg, RegisterTime, LoginTime, IsForbidden, SilentEndTime FROM player WHERE Id = ?;"

	var name string
	var unionId string
	var extraMsg string
	var registerTime time.Time
	var loginTime time.Time
	var isForbidden bool
	var silentEndTime time.Time
	if err = dal.ChatDB().QueryRow(command, id).Scan(&name, &unionId, &extraMsg, &registerTime, &loginTime, &isForbidden, &silentEndTime); err != nil {
		if err == sql.ErrNoRows {
			// 重置err,使其为nil;因为这代表的是没有查找到数据,而不是真正的错误
			err = nil
			return
		} else {
			logUtil.Log(fmt.Sprintf("Scan失败,错误信息:%s,command:%s", err, command), logUtil.Error, true)
			return
		}
	}

	playerObj = player.NewPlayer(id, name, unionId, extraMsg, registerTime, loginTime, isForbidden, silentEndTime)
	exists = true

	return
}
Пример #2
0
func GetAppConfig(appId string) *config.AppConfig {
	command := "SELECT AppId, AppName, AppKey, MessageFolder, MaxFileSize FROM appconfig WHERE AppId = ?;"

	var appName string
	var appKey string
	var messageFolder string
	var maxFileSize int64
	if err := dal.ChatDB().QueryRow(command, appId).Scan(&appId, &appName, &appKey, &messageFolder, &maxFileSize); err != nil {
		if err == sql.ErrNoRows {
			panic(errors.New("未找到appconfig配置内容"))
		} else {
			panic(errors.New(fmt.Sprintf("QueryRow失败,错误信息:%s,command:%s", err, command)))
		}
	}

	return config.NewAppConfig(appId, appName, appKey, messageFolder, maxFileSize)
}
Пример #3
0
func UpdateForbiddenStatus(player *player.Player) error {
	command := "UPDATE player SET IsForbidden = ? WHERE Id = ?"
	stmt, err := dal.ChatDB().Prepare(command)
	if err != nil {
		logUtil.Log(fmt.Sprintf("Prepare失败,错误信息:%s,command:%s", err, command), logUtil.Error, true)
		return err
	}

	// 最后关闭
	defer stmt.Close()

	if _, err = stmt.Exec(player.IsForbidden, player.Id); err != nil {
		logUtil.Log(fmt.Sprintf("Exec失败,错误信息:%s,command:%s", err, command), logUtil.Error, true)
		return err
	}

	return nil
}
Пример #4
0
func UpdateInfo(player *player.Player) error {
	command := "UPDATE player SET Name = ?, UnionId = ?, ExtraMsg = ? WHERE Id = ?"
	stmt, err := dal.ChatDB().Prepare(command)
	if err != nil {
		logUtil.Log(fmt.Sprintf("Prepare失败,错误信息:%s,command:%s", err, command), logUtil.Error, true)
		return err
	}

	// 最后关闭
	defer stmt.Close()

	if _, err = stmt.Exec(player.Name, player.UnionId, player.ExtraMsg, player.Id); err != nil {
		logUtil.Log(fmt.Sprintf("Exec失败,错误信息:%s,command:%s", err, command), logUtil.Error, true)
		return err
	}

	return nil
}
Пример #5
0
func Insert(apiName, content string) error {
	command := "INSERT INTO request_log(APIName, ServerGroupId, Content, Crdate) VALUES(?, ?, ?, ?);"
	stmt, err := dal.ChatDB().Prepare(command)
	if err != nil {
		logUtil.Log(fmt.Sprintf("Prepare失败,错误信息:%s,command:%s", err, command), logUtil.Error, true)
		return err
	}

	// 最后关闭
	defer stmt.Close()

	if _, err = stmt.Exec(apiName, dal.ServerGroupId, content, time.Now()); err != nil {
		logUtil.Log(fmt.Sprintf("Exec失败,错误信息:%s,command:%s", err, command), logUtil.Error, true)
		return err
	}

	return nil
}
Пример #6
0
func Insert(player *player.Player) error {
	command := `INSERT INTO 
                player(Id, Name, UnionId, ExtraMsg, RegisterTime, LoginTime, IsForbidden, SilentEndTime)
            VALUES
                (?, ?, ?, ?, ?, ?, ?, ?);
    `
	stmt, err := dal.ChatDB().Prepare(command)
	if err != nil {
		logUtil.Log(fmt.Sprintf("Prepare失败,错误信息:%s,command:%s", err, command), logUtil.Error, true)
		return err
	}

	// 最后关闭
	defer stmt.Close()

	if _, err = stmt.Exec(player.Id, player.Name, player.UnionId, player.ExtraMsg, player.RegisterTime, player.LoginTime, player.IsForbidden, player.SilentEndTime); err != nil {
		logUtil.Log(fmt.Sprintf("Exec失败,错误信息:%s,command:%s", err, command), logUtil.Error, true)
		return err
	}

	return nil
}