388 lines
9.7 KiB
Go
388 lines
9.7 KiB
Go
package main
|
|
|
|
import (
|
|
"f5"
|
|
"q5"
|
|
)
|
|
|
|
// loadGuildFromDB 加载公会
|
|
func (gm *GuildMgr) loadGuildFromDB() {
|
|
fields := []string{
|
|
"idx",
|
|
"guild_id",
|
|
"name",
|
|
"leader_account_id",
|
|
"avatar",
|
|
"notice",
|
|
"join_cond",
|
|
"join_cond_value",
|
|
"total_stars",
|
|
"total_kills",
|
|
"chicken_dinners",
|
|
"max_members",
|
|
}
|
|
where := [][]string{
|
|
{"is_deleted", "0"},
|
|
}
|
|
f5.GetJsStyleDb().Select(
|
|
FRIEND_DB,
|
|
"t_guild",
|
|
fields,
|
|
where,
|
|
gm.loadGuildFromDBResult,
|
|
)
|
|
}
|
|
func (gm *GuildMgr) loadGuildFromDBResult(err error, rows *f5.DataSet) {
|
|
if err != nil {
|
|
f5.GetSysLog().Info("loadGuildFromDBResult err:%v \n", err)
|
|
return
|
|
}
|
|
for rows.Next() {
|
|
guildId := q5.ToInt64(*rows.GetByIndex(1))
|
|
// put to gm.guilds
|
|
gm.guilds[guildId] = &Guild{
|
|
AutoId: q5.ToInt64(*rows.GetByIndex(0)),
|
|
GuildId: q5.ToInt64(*rows.GetByIndex(1)),
|
|
Name: q5.ToString(*rows.GetByIndex(2)),
|
|
LeaderId: q5.ToString(*rows.GetByIndex(3)),
|
|
Avatar: q5.ToInt32(*rows.GetByIndex(4)),
|
|
Notice: q5.ToString(*rows.GetByIndex(5)),
|
|
JoinCond: q5.ToInt32(*rows.GetByIndex(6)),
|
|
JoinCondValue: q5.ToInt32(*rows.GetByIndex(7)),
|
|
TotalStars: q5.ToInt32(*rows.GetByIndex(8)),
|
|
TotalKills: q5.ToInt32(*rows.GetByIndex(9)),
|
|
ChickenDinners: q5.ToInt32(*rows.GetByIndex(10)),
|
|
MaxMembers: q5.ToInt32(*rows.GetByIndex(11)),
|
|
}
|
|
// init pendingReqs
|
|
gm.pendingReqs[guildId] = make(map[string]bool)
|
|
}
|
|
q5.UnSetBitFlag(&gm.loadedFlags, LoadGuildFlag)
|
|
}
|
|
|
|
// loadGuildMemberFromDB 加载公会成员
|
|
func (gm *GuildMgr) loadGuildMemberFromDB() {
|
|
fields := []string{"guild_id", "account_id", "level"}
|
|
where := [][]string{
|
|
{"is_leave_guild", "0"},
|
|
}
|
|
f5.GetJsStyleDb().Select(
|
|
FRIEND_DB,
|
|
"t_guild_members",
|
|
fields,
|
|
where,
|
|
gm.loadGuildMemberFromDBResult,
|
|
)
|
|
}
|
|
func (gm *GuildMgr) loadGuildMemberFromDBResult(err error, rows *f5.DataSet) {
|
|
if err != nil {
|
|
f5.GetSysLog().Info("loadGuildMemberFromDBResult err:%v \n", err)
|
|
return
|
|
}
|
|
for rows.Next() {
|
|
var (
|
|
guildId int64
|
|
accountId string
|
|
level int
|
|
)
|
|
guildId = q5.ToInt64(*rows.GetByIndex(0))
|
|
accountId = q5.ToString(*rows.GetByIndex(1))
|
|
level = int(q5.ToInt32(*rows.GetByIndex(2)))
|
|
|
|
guildMember := &GuildMember{
|
|
AccountId: accountId,
|
|
Level: level,
|
|
}
|
|
if guild, ok := gm.guilds[guildId]; ok {
|
|
err := guild.AddMember(guildMember)
|
|
if err != nil {
|
|
f5.GetSysLog().Info("Guild:%d member is full\n", guildId)
|
|
}
|
|
}
|
|
}
|
|
q5.UnSetBitFlag(&gm.loadedFlags, LoadGuildMemberFlag)
|
|
}
|
|
|
|
// loadPendingReqsFromDB 加载公会申请者列表
|
|
func (gm *GuildMgr) loadPendingReqsFromDB() {
|
|
fields := []string{"guild_id", "account_id"}
|
|
where := [][]string{
|
|
{"is_join_guild", q5.ToString(PendingReqIsJoinGuildStatusDefault)},
|
|
}
|
|
f5.GetJsStyleDb().Select(
|
|
FRIEND_DB,
|
|
"t_guild_pending_request",
|
|
fields,
|
|
where,
|
|
gm.loadPendingReqsFromDBResult,
|
|
)
|
|
}
|
|
func (gm *GuildMgr) loadPendingReqsFromDBResult(err error, rows *f5.DataSet) {
|
|
if err != nil {
|
|
f5.GetSysLog().Info("loadPendingReqsFromDBResult err:%v \n", err)
|
|
return
|
|
}
|
|
for rows.Next() {
|
|
var (
|
|
guildId int64
|
|
accountId string
|
|
)
|
|
guildId = q5.ToInt64(*rows.GetByIndex(0))
|
|
accountId = q5.ToString(*rows.GetByIndex(1))
|
|
gm.pendingReqs[guildId][accountId] = true
|
|
}
|
|
q5.UnSetBitFlag(&gm.loadedFlags, LoadGuildReqFlag)
|
|
}
|
|
|
|
// loadGuildLogsFromDB 加载公会日志
|
|
func (gm *GuildMgr) loadGuildLogsFromDB() {
|
|
var perPage int32 = 10
|
|
var page int32 = 1
|
|
sql := "SELECT `guild_id`, `account_id`, `log_type`, `content` FROM `t_guild_logs`"
|
|
var params []string
|
|
var filter f5.DbQueryFilter
|
|
orderBy := "ORDER BY `createtime` DESC"
|
|
f5.GetJsStyleDb().PageQuery(
|
|
FRIEND_DB,
|
|
perPage,
|
|
page,
|
|
sql,
|
|
params,
|
|
filter,
|
|
orderBy,
|
|
gm.loadGuildLogsFromDBResult,
|
|
)
|
|
}
|
|
func (gm *GuildMgr) loadGuildLogsFromDBResult(err error, pagination *f5.Pagination) {
|
|
if err != nil {
|
|
//panic(err)
|
|
return
|
|
}
|
|
//total := pagination.Total
|
|
var (
|
|
guildId int64
|
|
accountId string
|
|
logType int32
|
|
content string
|
|
)
|
|
gm.guildLogs[guildId] = make([]*GuildLog, DefaultLogs)
|
|
|
|
for pagination.Rows.Next() {
|
|
guildId = q5.ToInt64(*pagination.Rows.GetByIndex(0))
|
|
accountId = q5.ToString(*pagination.Rows.GetByIndex(1))
|
|
logType = q5.ToInt32(*pagination.Rows.GetByIndex(2))
|
|
content = q5.ToString(*pagination.Rows.GetByIndex(3))
|
|
|
|
guildLog := &GuildLog{
|
|
GuildId: guildId,
|
|
AccountId: accountId,
|
|
LogType: logType,
|
|
Content: content,
|
|
}
|
|
gm.guildLogs[guildId] = append(gm.guildLogs[guildId], guildLog)
|
|
}
|
|
q5.UnSetBitFlag(&gm.loadedFlags, LoadGuildLogFlag)
|
|
}
|
|
|
|
// createGuildDB 创建公会
|
|
func (gm *GuildMgr) createGuildDB(g *Guild) {
|
|
fields := [][]string{
|
|
{"guild_id", q5.ToString(g.GuildId)},
|
|
{"name", g.Name},
|
|
{"leader_account_id", g.LeaderId},
|
|
{"max_members", q5.ToString(g.MaxMembers)},
|
|
}
|
|
f5.GetJsStyleDb().Insert(
|
|
FRIEND_DB,
|
|
"t_guild",
|
|
fields,
|
|
func(err error, lastInsertId int64, rowsAffected int64) {
|
|
if err != nil || rowsAffected != 1 {
|
|
f5.GetSysLog().Info("createGuildDB:%v\n", err)
|
|
}
|
|
f5.GetSysLog().Info("lastInsertId:%d\n", lastInsertId)
|
|
f5.GetSysLog().Info("rowsAffected:%d\n", rowsAffected)
|
|
},
|
|
)
|
|
}
|
|
|
|
// updateGuild 更新公会信息
|
|
func (gm *GuildMgr) updateGuild(g *Guild, fields [][]string) {
|
|
where := [][]string{
|
|
{"guild_id", q5.ToString(g.GuildId)},
|
|
}
|
|
f5.GetJsStyleDb().Update(
|
|
FRIEND_DB,
|
|
"t_guild",
|
|
fields,
|
|
where,
|
|
func(error, int64, int64) {},
|
|
)
|
|
}
|
|
|
|
// insertPendingReqs 添加申请加入公会记录, 存在则更新记录
|
|
func (gm *GuildMgr) upsertPendingReqs(guildId int64, accountId string, isJoinGuild int) {
|
|
where := [][]string{
|
|
{"guild_id", q5.ToString(guildId)},
|
|
{"account_id", accountId},
|
|
}
|
|
insertKv := [][]string{
|
|
{"guild_id", q5.ToString(guildId)},
|
|
{"account_id", accountId},
|
|
{"is_join_guild", q5.ToString(isJoinGuild)},
|
|
}
|
|
updateKv := [][]string{
|
|
{"is_join_guild", q5.ToString(isJoinGuild)},
|
|
}
|
|
f5.GetJsStyleDb().Upsert(
|
|
FRIEND_DB,
|
|
"t_guild_pending_request",
|
|
where,
|
|
updateKv,
|
|
insertKv,
|
|
func(err error, lastInsertId int64, rowsAffected int64) {
|
|
if err != nil {
|
|
f5.GetSysLog().Info("error:%v\n", err)
|
|
}
|
|
f5.GetSysLog().Info("lastInsertId:%d\n", lastInsertId)
|
|
f5.GetSysLog().Info("rowsAffected:%d\n", rowsAffected)
|
|
})
|
|
}
|
|
|
|
// updatePendingReqs 更新所有申请加入公会记录
|
|
func (gm *GuildMgr) updateAllPendingReqs(guildId int64, isJoinGuild int) {
|
|
fields := [][]string{
|
|
{"is_join_guild", q5.ToString(isJoinGuild)},
|
|
}
|
|
where := [][]string{
|
|
{"guild_id", q5.ToString(guildId)},
|
|
}
|
|
f5.GetJsStyleDb().Update(
|
|
FRIEND_DB,
|
|
"t_guild_pending_request",
|
|
fields,
|
|
where,
|
|
func(err error, lastInsertId int64, rowsAffected int64) {
|
|
if err != nil {
|
|
f5.GetSysLog().Info("error:%v\n", err)
|
|
}
|
|
f5.GetSysLog().Info("lastInsertId:%d\n", lastInsertId)
|
|
f5.GetSysLog().Info("rowsAffected:%d\n", rowsAffected)
|
|
},
|
|
)
|
|
}
|
|
|
|
// updatePendingReqs 更新申请加入公会记录
|
|
func (gm *GuildMgr) updatePendingReqs(guildId int64, accountId string, isJoinGuild int) {
|
|
fields := [][]string{
|
|
{"is_join_guild", q5.ToString(isJoinGuild)},
|
|
}
|
|
where := [][]string{
|
|
{"guild_id", q5.ToString(guildId)},
|
|
{"account_id", accountId},
|
|
}
|
|
f5.GetJsStyleDb().Update(
|
|
FRIEND_DB,
|
|
"t_guild_pending_request",
|
|
fields,
|
|
where,
|
|
func(err error, lastInsertId int64, rowsAffected int64) {
|
|
if err != nil {
|
|
f5.GetSysLog().Info("error:%v\n", err)
|
|
}
|
|
f5.GetSysLog().Info("lastInsertId:%d\n", lastInsertId)
|
|
f5.GetSysLog().Info("rowsAffected:%d\n", rowsAffected)
|
|
},
|
|
)
|
|
}
|
|
|
|
// insertPendingReqs 添加公会成员
|
|
func (gm *GuildMgr) upsertGuildMember(guildId int64, member *GuildMember) {
|
|
where := [][]string{
|
|
{"guild_id", q5.ToString(guildId)},
|
|
{"account_id", member.AccountId},
|
|
}
|
|
insertKv := [][]string{
|
|
{"guild_id", q5.ToString(guildId)},
|
|
{"account_id", member.AccountId},
|
|
{"level", q5.ToString(member.Level)},
|
|
{"is_leave_guild", "0"},
|
|
}
|
|
updateKv := insertKv
|
|
f5.GetJsStyleDb().Upsert(
|
|
FRIEND_DB,
|
|
"t_guild_members",
|
|
where,
|
|
updateKv,
|
|
insertKv,
|
|
func(err error, lastInsertId int64, rowsAffected int64) {
|
|
if err != nil {
|
|
f5.GetSysLog().Info("error:%v\n", err)
|
|
}
|
|
f5.GetSysLog().Info("lastInsertId:%d\n", lastInsertId)
|
|
f5.GetSysLog().Info("rowsAffected:%d\n", rowsAffected)
|
|
},
|
|
)
|
|
}
|
|
|
|
func (gm *GuildMgr) updateGuildMembers(g *Guild, fields [][]string) {
|
|
where := [][]string{
|
|
{"guild_id", q5.ToString(g.GuildId)},
|
|
}
|
|
f5.GetJsStyleDb().Update(
|
|
FRIEND_DB,
|
|
"t_guild_members",
|
|
fields,
|
|
where,
|
|
func(err error, lastInsertId int64, rowsAffected int64) {
|
|
if err != nil {
|
|
f5.GetSysLog().Info("error:%v\n", err)
|
|
}
|
|
f5.GetSysLog().Info("lastInsertId:%d\n", lastInsertId)
|
|
f5.GetSysLog().Info("rowsAffected:%d\n", rowsAffected)
|
|
},
|
|
)
|
|
}
|
|
|
|
// updateGuildMember 更新成员信息
|
|
func (gm *GuildMgr) updateGuildMember(g *Guild, accountId string, fields [][]string) {
|
|
where := [][]string{
|
|
{"guild_id", q5.ToString(g.GuildId)},
|
|
{"account_id", accountId},
|
|
}
|
|
|
|
f5.GetJsStyleDb().Update(
|
|
FRIEND_DB,
|
|
"t_guild_members",
|
|
fields,
|
|
where,
|
|
func(err error, lastInsertId int64, rowsAffected int64) {
|
|
if err != nil {
|
|
f5.GetSysLog().Info("error:%v\n", err)
|
|
}
|
|
f5.GetSysLog().Info("lastInsertId:%d\n", lastInsertId)
|
|
f5.GetSysLog().Info("rowsAffected:%d\n", rowsAffected)
|
|
},
|
|
)
|
|
}
|
|
|
|
// insertGuildLog 添加公会日志
|
|
func (gm *GuildMgr) insertGuildLog(log *GuildLog) {
|
|
fields := [][]string{
|
|
{"guild_id", q5.ToString(log.GuildId)},
|
|
{"account_id", log.AccountId},
|
|
{"log_type", q5.ToString(int(log.LogType))},
|
|
{"content", log.Content}}
|
|
f5.GetJsStyleDb().Insert(
|
|
FRIEND_DB,
|
|
"t_guild_logs",
|
|
fields,
|
|
func(err error, lastInsertId int64, rowsAffected int64) {
|
|
if err != nil {
|
|
f5.GetSysLog().Info("error:%v\n", err)
|
|
}
|
|
f5.GetSysLog().Info("lastInsertId:%d\n", lastInsertId)
|
|
f5.GetSysLog().Info("rowsAffected:%d\n", rowsAffected)
|
|
})
|
|
}
|