diff --git a/api/v1/game/notice.go b/api/v1/game/notice.go index 5968f67..c8adb1f 100644 --- a/api/v1/game/notice.go +++ b/api/v1/game/notice.go @@ -131,6 +131,7 @@ type GetGameNoticeReq struct { g.Meta `path:"/gamenotice/get" tags:"公告" method:"get" summary:"维护公告"` Channel string `p:"channel"` NoticeType int `p:"noticeType"` + ServerId int `p:"serverId"` } type GetGameNoticeRes struct { diff --git a/internal/consts/consts.go b/internal/consts/consts.go index 27c8863..d311fdf 100644 --- a/internal/consts/consts.go +++ b/internal/consts/consts.go @@ -45,6 +45,14 @@ const ( Notice_Type_Maintenance = 3 ) +const ( + Notice_Pop_Normal = 1 + Notice_Pop_Login = 2 + Notice_Pop_Notice = 3 + Notice_Pop_Roll = 4 + Notice_Pop_Roll_Del = 5 +) + const ( Notice_Normal = 1 Notice_White_List = 2 diff --git a/internal/dao/game_recharge_white_list.go b/internal/dao/game_recharge_white_list.go new file mode 100644 index 0000000..505961a --- /dev/null +++ b/internal/dao/game_recharge_white_list.go @@ -0,0 +1,27 @@ +// ================================================================================= +// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. +// ================================================================================= + +package dao + +import ( + "tyj_admin/internal/dao/internal" +) + +// internalGameRechargeWhiteListDao is internal type for wrapping internal DAO implements. +type internalGameRechargeWhiteListDao = *internal.GameRechargeWhiteListDao + +// gameRechargeWhiteListDao is the data access object for table game_recharge_white_list. +// You can define custom methods on it to extend its functionality as you wish. +type gameRechargeWhiteListDao struct { + internalGameRechargeWhiteListDao +} + +var ( + // GameRechargeWhiteList is globally public accessible object for table game_recharge_white_list operations. + GameRechargeWhiteList = gameRechargeWhiteListDao{ + internal.NewGameRechargeWhiteListDao(), + } +) + +// Fill with you ideas below. diff --git a/internal/dao/internal/game_notice.go b/internal/dao/internal/game_notice.go index fa72849..b387a6e 100644 --- a/internal/dao/internal/game_notice.go +++ b/internal/dao/internal/game_notice.go @@ -26,6 +26,7 @@ type GameNoticeColumns struct { Content string // Status string // 1.正常,2.白名单,3.维护 CDate string // 公告创建时间 + ServerId string // } // gameNoticeColumns holds the columns for table game_notice. @@ -36,6 +37,7 @@ var gameNoticeColumns = GameNoticeColumns{ Content: "content", Status: "status", CDate: "c_date", + ServerId: "serverId", } // NewGameNoticeDao creates and returns a new DAO object for table data access. diff --git a/internal/dao/internal/game_recharge_white_list.go b/internal/dao/internal/game_recharge_white_list.go new file mode 100644 index 0000000..47335d0 --- /dev/null +++ b/internal/dao/internal/game_recharge_white_list.go @@ -0,0 +1,75 @@ +// ========================================================================== +// Code generated by GoFrame CLI tool. DO NOT EDIT. +// ========================================================================== + +package internal + +import ( + "context" + + "github.com/gogf/gf/v2/database/gdb" + "github.com/gogf/gf/v2/frame/g" +) + +// GameRechargeWhiteListDao is the data access object for table game_recharge_white_list. +type GameRechargeWhiteListDao struct { + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of current DAO. + columns GameRechargeWhiteListColumns // columns contains all the column names of Table for convenient usage. +} + +// GameRechargeWhiteListColumns defines and stores column names for table game_recharge_white_list. +type GameRechargeWhiteListColumns struct { + Id string // + Account string // +} + +// gameRechargeWhiteListColumns holds the columns for table game_recharge_white_list. +var gameRechargeWhiteListColumns = GameRechargeWhiteListColumns{ + Id: "id", + Account: "account", +} + +// NewGameRechargeWhiteListDao creates and returns a new DAO object for table data access. +func NewGameRechargeWhiteListDao() *GameRechargeWhiteListDao { + return &GameRechargeWhiteListDao{ + group: "default", + table: "game_recharge_white_list", + columns: gameRechargeWhiteListColumns, + } +} + +// DB retrieves and returns the underlying raw database management object of current DAO. +func (dao *GameRechargeWhiteListDao) DB() gdb.DB { + return g.DB(dao.group) +} + +// Table returns the table name of current dao. +func (dao *GameRechargeWhiteListDao) Table() string { + return dao.table +} + +// Columns returns all column names of current dao. +func (dao *GameRechargeWhiteListDao) Columns() GameRechargeWhiteListColumns { + return dao.columns +} + +// Group returns the configuration group name of database of current dao. +func (dao *GameRechargeWhiteListDao) Group() string { + return dao.group +} + +// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +func (dao *GameRechargeWhiteListDao) Ctx(ctx context.Context) *gdb.Model { + return dao.DB().Model(dao.table).Safe().Ctx(ctx) +} + +// Transaction wraps the transaction logic using function f. +// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It commits the transaction and returns nil if function f returns nil. +// +// Note that, you should not Commit or Rollback the transaction in function f +// as it is automatically handled by this function. +func (dao *GameRechargeWhiteListDao) Transaction(ctx context.Context, f func(ctx context.Context, tx *gdb.TX) error) (err error) { + return dao.Ctx(ctx).Transaction(ctx, f) +} \ No newline at end of file diff --git a/internal/model/do/game_notice.go b/internal/model/do/game_notice.go index 15a56c4..e17e941 100644 --- a/internal/model/do/game_notice.go +++ b/internal/model/do/game_notice.go @@ -17,4 +17,5 @@ type GameNotice struct { Content interface{} // Status interface{} // 1.正常,2.白名单,3.维护 CDate interface{} // 公告创建时间 + ServerId interface{} // } diff --git a/internal/model/do/game_recharge_white_list.go b/internal/model/do/game_recharge_white_list.go new file mode 100644 index 0000000..c06a50f --- /dev/null +++ b/internal/model/do/game_recharge_white_list.go @@ -0,0 +1,16 @@ +// ================================================================================= +// Code generated by GoFrame CLI tool. DO NOT EDIT. +// ================================================================================= + +package do + +import ( + "github.com/gogf/gf/v2/frame/g" +) + +// GameRechargeWhiteList is the golang structure of table game_recharge_white_list for DAO operations like Where/Data. +type GameRechargeWhiteList struct { + g.Meta `orm:"table:game_recharge_white_list, do:true"` + Id interface{} // + Account interface{} // +} diff --git a/internal/model/entity/game_notice.go b/internal/model/entity/game_notice.go index 7dd37ba..4e3583e 100644 --- a/internal/model/entity/game_notice.go +++ b/internal/model/entity/game_notice.go @@ -12,4 +12,5 @@ type GameNotice struct { Content string `json:"content" description:""` Status int `json:"status" description:"1.正常,2.白名单,3.维护"` CDate int64 `json:"cDate" description:"公告创建时间"` + ServerId int `json:"serverId" description:""` } diff --git a/internal/model/entity/game_recharge_white_list.go b/internal/model/entity/game_recharge_white_list.go new file mode 100644 index 0000000..5527336 --- /dev/null +++ b/internal/model/entity/game_recharge_white_list.go @@ -0,0 +1,11 @@ +// ================================================================================= +// Code generated by GoFrame CLI tool. DO NOT EDIT. +// ================================================================================= + +package entity + +// GameRechargeWhiteList is the golang structure for table game_recharge_white_list. +type GameRechargeWhiteList struct { + Id int `json:"id" description:""` + Account string `json:"account" description:""` +} diff --git a/internal/serviceGame/internal/dbinit.go b/internal/serviceGame/internal/dbinit.go index 1e177c9..1e93d53 100644 --- a/internal/serviceGame/internal/dbinit.go +++ b/internal/serviceGame/internal/dbinit.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "github.com/go-redis/redis/v8" + "github.com/gogf/gf/v2/encoding/gjson" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/os/gctx" "github.com/qiniu/qmgo" @@ -76,6 +77,8 @@ func MongoInit(ctx context.Context) { return } config := mongoCfg.Maps() + + fmt.Println("MongoInit: ", gjson.MustEncodeString(config)) MongoDatabaseList = map[string]*qmgo.Database{} MongoConfigs = map[string]MongoType{} for _, v := range config { diff --git a/internal/serviceGame/internal/notice.go b/internal/serviceGame/internal/notice.go index 06cdadf..f0cdde5 100644 --- a/internal/serviceGame/internal/notice.go +++ b/internal/serviceGame/internal/notice.go @@ -64,7 +64,7 @@ func BackStageMessage(ctx context.Context, serverId int, ownerId string, content tmp, _ := gcharset.ToUTF8(srcCharset, src) json, err1 := gjson.DecodeToJson(tmp) if err1 != nil { - return + return err1 } if json.Get("Error").Int() != 200 { return diff --git a/internal/serviceGame/notice.go b/internal/serviceGame/notice.go index bbe622f..bc7ac09 100644 --- a/internal/serviceGame/notice.go +++ b/internal/serviceGame/notice.go @@ -76,10 +76,7 @@ func (c *gameNoticeImpl) GetNoticeList(ctx context.Context, req *game.GetNoticeL if req.NoticeType != 0 { model = model.Where("notice_type=?", req.NoticeType) } - //if req.Channel != "0" { - // model = model.Where("channel=? ", req.Channel) - //} - err = model.Scan(&res.List) + err = model.Page(req.PageNum, req.PageSize).Scan(&res.List) res.Total, err = model.Count() return }) @@ -104,15 +101,22 @@ func (c *gameNoticeImpl) GetGameNotice(ctx context.Context, req *game.GetGameNot g.Log().Debugf(ctx, "ipList GetGameNotice ip: "+ip, "NoticeType: "+fmt.Sprint(req.NoticeType), "res: "+fmt.Sprint(res.Status)) return } - - model = model.Where("channel=? ", req.Channel) + if req.NoticeType == consts.Notice_Type_Pop { + model = model.Where("server=? ", req.ServerId) + } else { + model = model.Where("channel=? ", req.Channel) + } var noticeList []*entity.GameNotice var count int count, err = model.Count() if count == 0 { model = dao.GameNotice.Ctx(ctx) model = model.Where("notice_type = ?", req.NoticeType) - model = model.Where("channel=? ", "") + if req.NoticeType == consts.Notice_Type_Pop { + model = model.Where("server=? ", 0) + } else { + model = model.Where("channel=? ", "") + } } err = model.Scan(¬iceList) if len(noticeList) > 1 { @@ -133,21 +137,25 @@ func (c *gameNoticeImpl) GetGameNotice(ctx context.Context, req *game.GetGameNot res.Content = "" res.Status = consts.Notice_Normal } - //ip := libUtils.GetClientIp(ctx) - if res.Status == consts.Notice_White_List { - whiteIps, e := internal.GetWhiteList(ctx) - g.Log().Debugf(ctx, "GetGameNotice ip"+ip, len(whiteIps), e) - res.Status = consts.Notice_Maintenance - for _, v := range whiteIps { - if v.Ip == ip { - res.Status = consts.Notice_Normal - break + + if req.NoticeType == consts.Notice_Type_Pop { + + } else { + if res.Status == consts.Notice_White_List { + whiteIps, e := internal.GetWhiteList(ctx) + g.Log().Debugf(ctx, "GetGameNotice ip"+ip, len(whiteIps), e) + res.Status = consts.Notice_Maintenance + for _, v := range whiteIps { + if v.Ip == ip { + res.Status = consts.Notice_Normal + break + } } } - } - if req.NoticeType != consts.Notice_Type_Maintenance { - res.Status = consts.Notice_Normal + if req.NoticeType != consts.Notice_Type_Maintenance { + res.Status = consts.Notice_Normal + } } g.Log().Debugf(ctx, "GetGameNotice ip: "+ip, "NoticeType: "+fmt.Sprint(req.NoticeType), "res: "+fmt.Sprint(res.Status)) @@ -296,7 +304,7 @@ func (c *gameNoticeImpl) DelNoticeList(ctx context.Context, req *game.DelNoticeL func (c *gameNoticeImpl) PopNotice(ctx context.Context, req *game.PopReq) (res *game.PopRes, err error) { err = g.Try(ctx, func(ctx context.Context) { - if req.PopTo == 1 { + if req.PopTo == 1 || req.Type == consts.Notice_Pop_Roll || req.Type == consts.Notice_Pop_Roll_Del { req.Uids = "" } _, e := dao.GameNoticeLog.Ctx(ctx).Insert(&do.GameNoticeLog{ @@ -305,7 +313,7 @@ func (c *gameNoticeImpl) PopNotice(ctx context.Context, req *game.PopReq) (res * Uids: req.Uids, PopType: req.Type, Content: req.Content, - NoticeType: 1, + NoticeType: consts.Notice_Type_Pop, NoticeId: 0, Channel: "", SendTime: 0, @@ -315,6 +323,20 @@ func (c *gameNoticeImpl) PopNotice(ctx context.Context, req *game.PopReq) (res * return } err = internal.BackStageMessage(ctx, req.ServerId, req.Uids, req.Content, req.Type) + if err == nil && req.Type == consts.Notice_Pop_Roll { + dao.GameNotice.Ctx(ctx).Delete(do.GameNotice{NoticeType: consts.Notice_Type_Pop, ServerId: req.ServerId}) + dao.GameNotice.Ctx(ctx).Insert(&do.GameNotice{ + Status: 1, + Content: req.Content, + Channel: "", + NoticeType: consts.Notice_Type_Pop, + ServerId: req.ServerId, + CDate: time.Now().Unix(), + }) + } + if err == nil && req.Type == consts.Notice_Pop_Roll_Del { + dao.GameNotice.Ctx(ctx).Delete(do.GameNotice{NoticeType: consts.Notice_Type_Pop, ServerId: req.ServerId}) + } }) return