ingame annc
This commit is contained in:
parent
cc2921c5c6
commit
ead104b8fd
@ -108,3 +108,121 @@ func (this *AnncApi) UpdateAnnc(c *gin.Context) {
|
|||||||
"message": "success",
|
"message": "success",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *AnncApi) IngameAnncList(c *gin.Context) {
|
||||||
|
anncList := []system.IngameAnnc{}
|
||||||
|
err := f5.GetApp().GetOrmDb(constant.CONF_DB).Find(&anncList).Error
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 1,
|
||||||
|
"message": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 0,
|
||||||
|
"message": "success",
|
||||||
|
"data": anncList,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *AnncApi) AddIngameAnnc(c *gin.Context) {
|
||||||
|
annc := system.IngameAnnc{}
|
||||||
|
if err := c.ShouldBindJSON(&annc); err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 1,
|
||||||
|
"message": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !this.CheckIngameAnnu(annc, c) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
annc.Uniid = uint64(f5.GetApp().NewNodeUuid())
|
||||||
|
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
|
||||||
|
annc.CreateTime = nowDaySeconds
|
||||||
|
annc.ModifyTime = nowDaySeconds
|
||||||
|
err := f5.GetApp().GetOrmDb(constant.CONF_DB).Create(&annc).Error
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 1,
|
||||||
|
"message": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 0,
|
||||||
|
"message": "success",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *AnncApi) UpdateIngameAnnc(c *gin.Context) {
|
||||||
|
idx, _ := strconv.ParseUint(c.Param("idx"), 10, 64)
|
||||||
|
annc := system.IngameAnnc{}
|
||||||
|
if err := c.ShouldBindJSON(&annc); err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 1,
|
||||||
|
"message": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !this.CheckIngameAnnu(annc, c) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var count int64
|
||||||
|
db := f5.GetApp().GetOrmDb(constant.CONF_DB)
|
||||||
|
db.Table(annc.TableName()).Where("idx = ?", idx).Count(&count)
|
||||||
|
if count < 1 {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 1,
|
||||||
|
"message": "不存在的公告",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
annc.ModifyTime = int32(f5.GetApp().GetRealSeconds())
|
||||||
|
err := db.Select("*").Omit("idx", "uniid", "createtime").Where("idx = ?", idx).Updates(&annc).Error
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 1,
|
||||||
|
"message": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 0,
|
||||||
|
"message": "success",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *AnncApi) CheckIngameAnnu(annc system.IngameAnnc, c *gin.Context) bool {
|
||||||
|
if len(annc.Title) > 0xFF {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 2,
|
||||||
|
"message": "标题过长",
|
||||||
|
})
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(annc.Content) > 0xFF {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 2,
|
||||||
|
"message": "内容过长",
|
||||||
|
})
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if annc.EndTime < annc.BeginTime || annc.EndTime < int32(f5.GetApp().GetRealSeconds()) {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 2,
|
||||||
|
"message": "发送时间不对",
|
||||||
|
})
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
@ -13,3 +13,19 @@ type Annc struct {
|
|||||||
func (this Annc) TableName() string {
|
func (this Annc) TableName() string {
|
||||||
return "t_login_annc"
|
return "t_login_annc"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type IngameAnnc struct {
|
||||||
|
Idx uint64 `json:"idx"`
|
||||||
|
Uniid uint64 `json:"uniid"`
|
||||||
|
Title string `json:"title" binding:"required"`
|
||||||
|
Content string `json:"content" binding:"required"`
|
||||||
|
BeginTime int32 `json:"begin_time" binding:"required"`
|
||||||
|
EndTime int32 `json:"end_time" binding:"required"`
|
||||||
|
IsOpen uint `json:"is_open"`
|
||||||
|
CreateTime int32 `gorm:"column:createtime" json:"-"`
|
||||||
|
ModifyTime int32 `gorm:"column:modifytime" json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this IngameAnnc) TableName() string {
|
||||||
|
return "t_game_annc"
|
||||||
|
}
|
||||||
|
@ -16,5 +16,9 @@ func (this *AnncRouter) InitAnncRouter(priRouter *gin.RouterGroup) {
|
|||||||
priUserRouter.GET("anncList", middleware.Permission("api/v1/annc/anncList", anncApi.AnncList))
|
priUserRouter.GET("anncList", middleware.Permission("api/v1/annc/anncList", anncApi.AnncList))
|
||||||
priUserRouter.POST("addAnnc", middleware.Permission("api/v1/annc/addAnnc", anncApi.AddAnnc))
|
priUserRouter.POST("addAnnc", middleware.Permission("api/v1/annc/addAnnc", anncApi.AddAnnc))
|
||||||
priUserRouter.PUT("updateAnnc/:idx", middleware.Permission("api/v1/annc/updateAnnc", anncApi.UpdateAnnc))
|
priUserRouter.PUT("updateAnnc/:idx", middleware.Permission("api/v1/annc/updateAnnc", anncApi.UpdateAnnc))
|
||||||
|
|
||||||
|
priUserRouter.GET("anncIngameList", middleware.Permission("api/v1/annc/anncIngameList", anncApi.IngameAnncList))
|
||||||
|
priUserRouter.POST("addIngameAnnc", middleware.Permission("api/v1/annc/addIngameAnnc", anncApi.AddIngameAnnc))
|
||||||
|
priUserRouter.PUT("updateIngameAnnc/:idx", middleware.Permission("api/v1/annc/updateIngameAnnc", anncApi.UpdateIngameAnnc))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user