Browse Source

notice

master
linquan 2 months ago
parent
commit
83ef8f8592
  1. 17
      api/v1/game/notice.go
  2. 2
      api/v1/game/serverConfig.go
  3. 8
      internal/cmd/cmd.go
  4. 1
      internal/consts/consts.go
  5. 5
      internal/controller/game_notice.go
  6. 8
      internal/dao/internal/game_notice.go
  7. 2
      internal/dao/internal/game_notice_log.go
  8. 7
      internal/model/do/game_notice.go
  9. 1
      internal/model/do/game_notice_log.go
  10. 7
      internal/model/entity/game_notice.go
  11. 1
      internal/model/entity/game_notice_log.go
  12. 2
      internal/serviceGame/cron.go
  13. 26
      internal/serviceGame/internal/dbinit.go
  14. 2
      internal/serviceGame/loginUrl.go
  15. 31
      internal/serviceGame/notice.go
  16. BIN
      pub_upload/icon.jpeg
  17. 1
      test/testMongo.go

17
api/v1/game/notice.go

@ -67,6 +67,7 @@ type AddNoticeReq struct {
NoticeType int `p:"noticeType"`
SendTime int64 `p:"sendTime"`
NoticeId int64 `p:"noticeId"`
IsShow int `p:"isShow"`
Id int64 `p:"id"`
}
@ -89,6 +90,15 @@ type DelNoticeListReq struct {
type DelNoticeListRes struct {
}
type NoticeShowReq struct {
g.Meta `path:"/notice/showOpen" tags:"公告" method:"post" summary:"公告列表删除"`
Id int64 `p:"id"`
IsShow int `p:"isShow"`
}
type NoticeShowRes struct {
}
type GetNoticeReq struct {
g.Meta `path:"/notice/get" tags:"公告" method:"get" summary:"维护公告"`
Channel string `p:"channel"`
@ -135,10 +145,8 @@ type GetGameNoticeReq struct {
}
type GetGameNoticeRes struct {
g.Meta `mime:"application/json"`
Status int `json:"status"`
Content string `json:"content"`
TimeStamp int32 `json:"timeStamp"`
g.Meta `mime:"application/json"`
Notice
}
type GetGameNoticeListReq struct {
@ -151,6 +159,7 @@ type Notice struct {
Status int `json:"status"`
Content string `json:"content"`
TimeStamp int32 `json:"timeStamp"`
IsShow int `json:"isShow"`
NoticeType int32 `json:"noticeType"`
}

2
api/v1/game/serverConfig.go

@ -34,6 +34,8 @@ type AddServerConfigGeneralReq struct {
RechargeWhiteListIps string `p:"rechargeWhiteListIps"`
SdkAddress string `p:"sdkAddress"`
UniqueAddress string `p:"uniqueAddress"`
ActivityDbUrl string `p:"activityDbUrl"`
ActivityDbName string `p:"activityDbName"`
}
type AddServerConfigGeneralRes struct {

8
internal/cmd/cmd.go

@ -6,6 +6,7 @@ import (
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/net/goai"
"github.com/gogf/gf/v2/os/gcmd"
"log"
"tyj_admin/internal/consts"
"tyj_admin/internal/router"
)
@ -22,8 +23,10 @@ var (
router.BindAnotherController(group)
})
s.BindHandler("/upload_file", func(r *ghttp.Request) {
r.Response.ServeFileDownload("./download/" + r.GetQuery("filename").String())
s.BindHandler("/pub_upload/*", func(r *ghttp.Request) {
r.Response.Header().Set("Access-Control-Allow-Origin", "*")
log.Println("r.RequestURI: ", r.RequestURI)
r.Response.ServeFile("."+r.RequestURI, false)
})
s.BindHandler("/download_file", func(r *ghttp.Request) {
@ -31,7 +34,6 @@ var (
r.Response.ServeFileDownload("./download/" + r.GetQuery("filename").String())
})
enhanceOpenAPIDoc(s)
//s.EnableHTTPS("server.crt", "server.key")
s.Run()
return nil
},

1
internal/consts/consts.go

@ -45,6 +45,7 @@ const (
Notice_Type_Maintenance = 3
Notice_Type_Customer = 4
Notice_Type_Preview = 5
Notice_Type_NewServer = 6
)
const (

5
internal/controller/game_notice.go

@ -61,3 +61,8 @@ func (c *noticeController) DelModel(ctx context.Context, req *game.DelNoticeMode
res, err = serviceGame.GameNotice().DelNoticeModel(ctx, req)
return
}
func (c *noticeController) NoticeShow(ctx context.Context, req *game.NoticeShowReq) (res *game.NoticeShowRes, err error) {
res, err = serviceGame.GameNotice().NoticeShow(ctx, req)
return
}

8
internal/dao/internal/game_notice.go

@ -20,13 +20,14 @@ type GameNoticeDao struct {
// GameNoticeColumns defines and stores column names for table game_notice.
type GameNoticeColumns struct {
Id string // 索引ID
NoticeType string // 公告类型:1表示弹窗公告,2表示登录公告,3表示维护公告
Id string // 维护公告1.正常,2.白名单,3.维护
NoticeType string // 公告类型:1表示弹窗公告,2表示登录公告,3表示维护公告, 4客服界面, 5预览, 6新服公告,
Channel string // 渠道号:第三方的登录渠道
Content string //
Status string // 1.正常,2.白名单,3.维护
Status string // 维护公告:1.正常,2.白名单,3.维护
CDate string // 公告创建时间
ServerId string //
IsShow string // 公告类型6:0-不显示, 1-显示
}
// gameNoticeColumns holds the columns for table game_notice.
@ -38,6 +39,7 @@ var gameNoticeColumns = GameNoticeColumns{
Status: "status",
CDate: "c_date",
ServerId: "serverId",
IsShow: "is_show",
}
// NewGameNoticeDao creates and returns a new DAO object for table data access.

2
internal/dao/internal/game_notice_log.go

@ -31,6 +31,7 @@ type GameNoticeLogColumns struct {
ServerId string //
Uids string //
PopType string // 1.强制退出,2.普通弹窗
IsShow string // 公告类型6:0-不显示, 1-显示
}
// gameNoticeLogColumns holds the columns for table game_notice_log.
@ -46,6 +47,7 @@ var gameNoticeLogColumns = GameNoticeLogColumns{
ServerId: "server_id",
Uids: "uids",
PopType: "pop_type",
IsShow: "is_show",
}
// NewGameNoticeLogDao creates and returns a new DAO object for table data access.

7
internal/model/do/game_notice.go

@ -11,11 +11,12 @@ import (
// GameNotice is the golang structure of table game_notice for DAO operations like Where/Data.
type GameNotice struct {
g.Meta `orm:"table:game_notice, do:true"`
Id interface{} // 索引ID
NoticeType interface{} // 公告类型:1表示弹窗公告,2表示登录公告,3表示维护公告
Id interface{} // 维护公告1.正常,2.白名单,3.维护
NoticeType interface{} // 公告类型:1表示弹窗公告,2表示登录公告,3表示维护公告, 4客服界面, 5预览, 6新服公告,
Channel interface{} // 渠道号:第三方的登录渠道
Content interface{} //
Status interface{} // 1.正常,2.白名单,3.维护
Status interface{} // 维护公告:1.正常,2.白名单,3.维护
CDate interface{} // 公告创建时间
ServerId interface{} //
IsShow interface{} // 公告类型6:0-不显示, 1-显示
}

1
internal/model/do/game_notice_log.go

@ -23,4 +23,5 @@ type GameNoticeLog struct {
ServerId interface{} //
Uids interface{} //
PopType interface{} // 1.强制退出,2.普通弹窗
IsShow interface{} // 公告类型6:0-不显示, 1-显示
}

7
internal/model/entity/game_notice.go

@ -6,11 +6,12 @@ package entity
// GameNotice is the golang structure for table game_notice.
type GameNotice struct {
Id int64 `json:"id" description:"索引ID"`
NoticeType int `json:"noticeType" description:"公告类型:1表示弹窗公告,2表示登录公告,3表示维护公告"`
Id int64 `json:"id" description:"维护公告1.正常,2.白名单,3.维护"`
NoticeType int `json:"noticeType" description:"公告类型:1表示弹窗公告,2表示登录公告,3表示维护公告, 4客服界面, 5预览, 6新服公告,"`
Channel string `json:"channel" description:"渠道号:第三方的登录渠道"`
Content string `json:"content" description:""`
Status int `json:"status" description:"1.正常,2.白名单,3.维护"`
Status int `json:"status" description:"维护公告:1.正常,2.白名单,3.维护"`
CDate int64 `json:"cDate" description:"公告创建时间"`
ServerId int `json:"serverId" description:""`
IsShow int `json:"isShow" description:"公告类型6:0-不显示, 1-显示"`
}

1
internal/model/entity/game_notice_log.go

@ -21,4 +21,5 @@ type GameNoticeLog struct {
ServerId int `json:"serverId" description:""`
Uids string `json:"uids" description:""`
PopType int `json:"popType" description:"1.强制退出,2.普通弹窗"`
IsShow int `json:"isShow" description:"公告类型6:0-不显示, 1-显示"`
}

2
internal/serviceGame/cron.go

@ -116,11 +116,13 @@ func (c *gameCronImpl) Cron(sTime int64) {
noticeModel.Where("notice_type=?", notice.NoticeType).Where("channel=?", notice.Channel).Scan(&noticeList)
if len(noticeList) > 0 {
_, _ = dao.GameNotice.Ctx(ctx).Where("id=", noticeList[0].Id).Data(&do.GameNotice{
IsShow: notice.IsShow,
Content: notice.Content,
CDate: time.Now().Unix(),
}).Update()
} else {
_, _ = dao.GameNotice.Ctx(ctx).Insert(&do.GameNotice{
IsShow: notice.IsShow,
Status: notice.Status,
Content: notice.Content,
NoticeType: notice.NoticeType,

26
internal/serviceGame/internal/dbinit.go

@ -28,6 +28,7 @@ type OceanengineMap struct {
}
var (
MongoClientList map[string]*qmgo.QmgoClient
MongoDatabaseList map[string]*qmgo.Database
MongoConfigs map[string]MongoType
RedisDbList []*redis.Client
@ -115,19 +116,36 @@ func MongoInit(ctx context.Context) {
}
config := mongoCfg.Maps()
v, err := g.Cfg().Get(ctx, "game.mongoConfig")
if err != nil {
return
}
m := v.MapStrVar()
var (
maxSize = m["maxSize"].Uint64()
minSize = m["minSize"].Uint64()
socketTimeoutMS = m["socketTimeoutMS"].Int64()
connectTimeoutMS = m["connectTimeoutMS"].Int64()
)
log.Println("MongoInit: ", gjson.MustEncodeString(config))
if len(MongoClientList) > 0 {
for _, v := range MongoClientList {
_ = v.Close(ctx)
}
}
MongoClientList = map[string]*qmgo.QmgoClient{}
MongoDatabaseList = map[string]*qmgo.Database{}
MongoConfigs = map[string]MongoType{}
for _, v := range config {
mongoclient, err := qmgo.NewClient(ctx, &qmgo.Config{Uri: v["link"].(string)})
mongoclient, err := qmgo.Open(ctx, &qmgo.Config{Uri: v["link"].(string), Database: v["name"].(string), Coll: "Account", MinPoolSize: &minSize, MaxPoolSize: &maxSize, SocketTimeoutMS: &socketTimeoutMS, ConnectTimeoutMS: &connectTimeoutMS})
if err != nil {
continue
}
db := mongoclient.Database(v["name"].(string))
MongoDatabaseList[v["id"].(string)] = db
MongoClientList[v["id"].(string)] = mongoclient
MongoDatabaseList[v["id"].(string)] = mongoclient.Database
MongoConfigs[v["id"].(string)] = MongoType{Link: v["link"].(string), Link1: v["link1"].(string), Id: v["id"].(string), Name: v["name"].(string), Auth: v["auth"].(string)}
}
}
func InitServer(ctx context.Context) {

2
internal/serviceGame/loginUrl.go

@ -78,6 +78,8 @@ func (c *gameLoginUrlImpl) AddServerConfigGeneral(ctx context.Context, req *game
dao.GameServerJsonGeneral.Columns().RechargeWhiteListIps: req.RechargeWhiteListIps,
dao.GameServerJsonGeneral.Columns().GmWhiteListUrl: req.GmWhiteListUrl,
dao.GameServerJsonGeneral.Columns().SdkAddress: req.SdkAddress,
dao.GameServerJsonGeneral.Columns().ActivityDbUrl: req.ActivityDbUrl,
dao.GameServerJsonGeneral.Columns().ActivityDbName: req.ActivityDbName,
})
liberr.ErrIsNil(ctx, err, "mysql err")
})

31
internal/serviceGame/notice.go

@ -30,6 +30,7 @@ type IGameNotice interface {
GetNoticeModel(ctx context.Context, req *game.GetNoticeModelReq) (res *game.GetNoticeModelRes, err error)
AddNoticeModel(ctx context.Context, req *game.AddNoticeModelReq) (res *game.AddNoticeModelRes, err error)
DelNoticeModel(ctx context.Context, req *game.DelNoticeModelReq) (res *game.DelNoticeModelRes, err error)
NoticeShow(ctx context.Context, req *game.NoticeShowReq) (res *game.NoticeShowRes, err error)
}
type gameNoticeImpl struct {
@ -96,6 +97,7 @@ func (c *gameNoticeImpl) GetGameNotice(ctx context.Context, req *game.GetGameNot
res.TimeStamp = int32(ipList[0].CDate)
res.Content = ipList[0].Content
res.Status = ipList[0].Status
res.IsShow = ipList[0].IsShow
g.Log().Debugf(ctx, "ipList GetGameNotice ip: "+ip, "NoticeType: "+fmt.Sprint(req.NoticeType), "res: "+fmt.Sprint(res.Status))
return
@ -124,6 +126,7 @@ func (c *gameNoticeImpl) GetGameNotice(ctx context.Context, req *game.GetGameNot
res.TimeStamp = int32(v.CDate)
res.Content = v.Content
res.Status = v.Status
res.IsShow = v.IsShow
break
}
}
@ -131,6 +134,7 @@ func (c *gameNoticeImpl) GetGameNotice(ctx context.Context, req *game.GetGameNot
res.TimeStamp = int32(noticeList[0].CDate)
res.Content = noticeList[0].Content
res.Status = noticeList[0].Status
res.IsShow = noticeList[0].IsShow
} else if len(noticeList) == 0 {
res.TimeStamp = 0
res.Content = ""
@ -173,7 +177,11 @@ func (c *gameNoticeImpl) GetGameNoticeList(ctx context.Context, req *game.GetGam
req1.Channel = req.Channel
res2, _ := c.GetGameNotice(ctx, req1)
res.List = append(res.List, game.Notice{Content: res2.Content, Status: res2.Status, TimeStamp: res2.TimeStamp, NoticeType: consts.Notice_Type_Preview})
//log.Printf("GetGameNotice res: %s", gjson.MustEncodeString(res.List))
req1.NoticeType = consts.Notice_Type_NewServer
req1.Channel = req.Channel
res3, _ := c.GetGameNotice(ctx, req1)
res.List = append(res.List, game.Notice{Content: res3.Content, Status: res3.Status, TimeStamp: res3.TimeStamp, IsShow: res3.IsShow, NoticeType: consts.Notice_Type_NewServer})
})
return
}
@ -214,10 +222,12 @@ func (c *gameNoticeImpl) AddNotice(ctx context.Context, req *game.AddNoticeReq)
NoticeType: req.NoticeType,
NoticeId: req.NoticeId,
Channel: req.Channel,
IsShow: req.IsShow,
SendTime: SendTime,
}
cron := entity.GameNoticeLog{
Id: req.Id,
IsShow: req.IsShow,
Status: req.Status,
Content: req.Content,
NoticeType: req.NoticeType,
@ -258,12 +268,14 @@ func (c *gameNoticeImpl) AddNotice(ctx context.Context, req *game.AddNoticeReq)
noticeModel.Where("notice_type=?", req.NoticeType).Where("channel=?", req.Channel).Scan(&noticeList)
if len(noticeList) > 0 {
_, e = noticeModel.Where("id=?", noticeList[0].Id).Data(&do.GameNotice{
IsShow: req.IsShow,
Status: req.Status,
Content: req.Content,
CDate: time.Now().Unix(),
}).Update()
} else {
_, e = noticeModel.Insert(&do.GameNotice{
IsShow: req.IsShow,
Status: req.Status,
Content: req.Content,
NoticeType: req.NoticeType,
@ -402,3 +414,20 @@ func (c *gameNoticeImpl) DelNoticeModel(ctx context.Context, req *game.DelNotice
}
return
}
func (c *gameNoticeImpl) NoticeShow(ctx context.Context, req *game.NoticeShowReq) (res *game.NoticeShowRes, err error) {
if req.Id == 0 {
err = errors.New("错误的id")
return
}
err = g.Try(ctx, func(ctx context.Context) {
_, e := dao.GameNotice.Ctx(ctx).Where("id=", req.Id).Data(&do.GameNotice{IsShow: req.IsShow}).Update()
if e != nil {
liberr.ErrIsNil(ctx, e, "修改公告失败")
return
}
})
return
}

BIN
pub_upload/icon.jpeg

Binary file not shown.

After

Width:  |  Height:  |  Size: 492 KiB

1
test/testMongo.go

@ -63,7 +63,6 @@ func selectStores(ctx context.Context, serverId string, query bson.M) {
break
}
}
}
log.Printf("服务器编号[%s] 结束!", serverId)
}

Loading…
Cancel
Save