Ver a proveniência

add - 央厨公告是否弹出

tmp
DengBiao há 10 meses
ascendente
cometimento
bbf7c6f68a
4 ficheiros alterados com 66 adições e 7 eliminações
  1. +45
    -0
      app/admin/hdl/hdl_notice.go
  2. +12
    -0
      app/db/db_notice.go
  3. +7
    -6
      app/db/model/notice.go
  4. +2
    -1
      app/router/admin_router.go

+ 45
- 0
app/admin/hdl/hdl_notice.go Ver ficheiro

@@ -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)


+ 12
- 0
app/db/db_notice.go Ver ficheiro

@@ -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 {


+ 7
- 6
app/db/model/notice.go Ver ficheiro

@@ -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"`
}

+ 2
- 1
app/router/admin_router.go Ver ficheiro

@@ -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) {


Carregando…
Cancelar
Guardar