You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
121 lines
2.4 KiB
121 lines
2.4 KiB
package notice |
|
|
|
import ( |
|
"server/call" |
|
"server/common" |
|
"server/db" |
|
"server/modules/backend/app" |
|
"server/modules/backend/values" |
|
"server/natsClient" |
|
"server/pb" |
|
"time" |
|
|
|
"github.com/gin-gonic/gin" |
|
"github.com/liangdas/mqant/log" |
|
) |
|
|
|
// 系统公告配置 |
|
func AddSystemNotice(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.AddSystemNoticeReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
|
|
if len(req.List) <= 0 { |
|
a.Code = values.CodeParam |
|
return |
|
} |
|
|
|
for i := 0; i < len(req.List); i++ { |
|
if req.List[i].ReleaseTime == 0 { |
|
req.List[i].ReleaseTime = time.Now().Unix() |
|
} |
|
} |
|
|
|
err := db.Mysql().C().Model(&common.SheetNoticeConfig{}).CreateInBatches(&req.List, len(req.List)).Error |
|
if err != nil { |
|
log.Error(err.Error()) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
|
|
err = call.Publish(natsClient.TopicReloadConfig, &pb.ReloadGameConfig{Type: common.ReloadNotice}) |
|
if err != nil { |
|
log.Error(err.Error()) |
|
} |
|
} |
|
|
|
// 系统公告配置 |
|
func GetSystemNotice(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.GetSystemNoticeReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
|
|
var SheetNoticeConfig []common.SheetNoticeConfig |
|
_, err := db.Mysql().QueryAll("", "", &common.SheetNoticeConfig{}, &SheetNoticeConfig) |
|
if err != nil { |
|
log.Error(err.Error()) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
|
|
a.Data = SheetNoticeConfig |
|
} |
|
|
|
// 编辑系统公告 |
|
func EditSystemNotice(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.EditSystemNoticeReq) |
|
if !a.S(req) { |
|
a.Code = values.CodeParam |
|
return |
|
} |
|
|
|
err := db.Mysql().C().Where("id = ?", req.Id).Save(req.Notice).Error |
|
if err != nil { |
|
log.Error(err.Error()) |
|
a.Code = values.CodeParam |
|
return |
|
} |
|
|
|
err = call.Publish(natsClient.TopicReloadConfig, &pb.ReloadGameConfig{Type: common.ReloadNotice}) |
|
if err != nil { |
|
log.Error(err.Error()) |
|
} |
|
} |
|
|
|
// 删除系统公告 |
|
func DeleteSystemNotice(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.DeleteSystemNoticeReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
|
|
err := db.Mysql().C().Where("id = ?", req.Id).Unscoped().Delete(&common.SheetNoticeConfig{}).Error |
|
if err != nil { |
|
log.Error(err.Error()) |
|
a.Code = values.CodeParam |
|
return |
|
} |
|
|
|
err = call.Publish(natsClient.TopicReloadConfig, &pb.ReloadGameConfig{Type: common.ReloadNotice}) |
|
if err != nil { |
|
log.Error(err.Error()) |
|
} |
|
}
|
|
|