diff --git a/app/admin/hdl/hdl_notice.go b/app/admin/hdl/hdl_notice.go index fd884f0..447a806 100644 --- a/app/admin/hdl/hdl_notice.go +++ b/app/admin/hdl/hdl_notice.go @@ -21,6 +21,16 @@ func NoticeList(c *gin.Context) { } e.OutSuc(c, map[string]interface{}{ "list": notices, + "is_pop_to_central_kitchen_list": []map[string]interface{}{ + { + "name": "弹出", + "value": 1, + }, + { + "name": "不弹出", + "value": 0, + }, + }, }, nil) return } @@ -78,6 +88,41 @@ func NoticeAdd(c *gin.Context) { return } +func NoticeIsPopToCentralKitchen(c *gin.Context) { + id := c.DefaultQuery("id", "0") + isPopToCentralKitchen := c.DefaultQuery("is_pop_to_central_kitchen", "0") + noticeDb := db.NoticeDb{} + noticeDb.Set() + popToCentralKitchen, err := noticeDb.GetPopToCentralKitchen() + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + if popToCentralKitchen != nil && utils.StrToInt(id) != popToCentralKitchen.Id { + e.OutErr(c, e.ERR_NO_DATA, "当前已有弹出至央厨公告!") + return + } + + notice, err := noticeDb.GetNotice(utils.StrToInt(id)) + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + if notice == nil { + e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") + return + } + now := time.Now() + notice.IsPopToCentralKitchen = utils.StrToInt(isPopToCentralKitchen) + notice.UpdateAt = now.Format("2006-01-02 15:04:05") + _, err = noticeDb.NoticeUpdate(notice, "is_pop_to_central_kitchen", "update_at") + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + e.OutSuc(c, "success", nil) +} + func NoticeUpdate(c *gin.Context) { var req md.NoticeUpdateReq err := c.ShouldBindJSON(&req) diff --git a/app/db/db_notice.go b/app/db/db_notice.go index 8e9b08f..8a31564 100644 --- a/app/db/db_notice.go +++ b/app/db/db_notice.go @@ -27,6 +27,18 @@ func (noticeDb *NoticeDb) GetNotice(id int) (m *model.Notice, err error) { return m, nil } +func (noticeDb *NoticeDb) GetPopToCentralKitchen() (m *model.Notice, err error) { + m = new(model.Notice) + has, err := noticeDb.Db.Where("is_pop_to_central_kitchen =?", 1).Get(m) + if err != nil { + return nil, logx.Error(err) + } + if has == false { + return nil, nil + } + return m, nil +} + func (noticeDb *NoticeDb) FindNoticeById(ids interface{}) (*[]model.Notice, error) { var m []model.Notice if err := noticeDb.Db.In("id", ids).Desc("sort").Find(&m); err != nil { diff --git a/app/db/model/notice.go b/app/db/model/notice.go index 4092398..6956f63 100644 --- a/app/db/model/notice.go +++ b/app/db/model/notice.go @@ -1,10 +1,11 @@ package model type Notice struct { - Id int `json:"id" xorm:"not null pk autoincr INT(11)"` - Name string `json:"name" xorm:"not null default '' comment('名称') VARCHAR(255)"` - Content string `json:"content" xorm:"not null comment('内容(json存储)') TEXT"` - Sort int `json:"sort" xorm:"not null default 0 comment('排序') TINYINT(3)"` - CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` - UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` + Id int `json:"id" xorm:"not null pk autoincr INT(11)"` + Name string `json:"name" xorm:"not null default '' comment('名称') VARCHAR(255)"` + Content string `json:"content" xorm:"not null comment('内容(json存储)') TEXT"` + Sort int `json:"sort" xorm:"not null default 0 comment('排序') TINYINT(3)"` + IsPopToCentralKitchen int `json:"is_pop_to_central_kitchen" xorm:"not null default 0 comment('是否弹出至央厨') TINYINT(1)"` + CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` + UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` } diff --git a/app/router/admin_router.go b/app/router/admin_router.go index dd35387..f9da74b 100644 --- a/app/router/admin_router.go +++ b/app/router/admin_router.go @@ -54,10 +54,11 @@ func rHomePage(r *gin.RouterGroup) { func rNotice(r *gin.RouterGroup) { r.GET("/list", hdl2.NoticeList) + r.GET("/noticeIsPopToCentralKitchen", hdl2.NoticeIsPopToCentralKitchen) r.POST("/add", hdl2.NoticeAdd) r.POST("/sort", hdl2.NoticeSort) r.POST("/update", hdl2.NoticeUpdate) - r.DELETE("/delete/:id", hdl2.NoticeUpdate) + r.DELETE("/delete/:id", hdl2.NoticeDelete) } func rBanner(r *gin.RouterGroup) {