|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- package hdl
-
- import (
- "applet/app/admin/lib/validate"
- "applet/app/admin/md"
- "applet/app/db"
- "applet/app/db/model"
- "applet/app/e"
- "applet/app/utils"
- "github.com/gin-gonic/gin"
- "time"
- )
-
- func NoticeList(c *gin.Context) {
- noticeDb := db.NoticeDb{}
- noticeDb.Set()
- notices, err := noticeDb.FindNotice(0, 0)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- 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
- }
-
- func NoticeSort(c *gin.Context) {
- var args struct {
- Ids []string `json:"ids" binding:"required"`
- }
- if err := c.ShouldBindJSON(&args); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- noticeDb := db.NoticeDb{}
- noticeDb.Set()
- notices, err := noticeDb.FindNoticeById(args.Ids)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- for k, v := range *notices {
- v.Sort = k
- _, err1 := noticeDb.NoticeUpdate(&v, "sort")
- if err1 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err1.Error())
- return
- }
- }
- e.OutSuc(c, "success", nil)
- }
-
- func NoticeAdd(c *gin.Context) {
- var req md.NoticeAddReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- noticeDb := db.NoticeDb{}
- noticeDb.Set()
- now := time.Now()
- notice := model.Notice{
- Name: req.Name,
- Content: req.Content,
- CreateAt: now.Format("2006-01-02 15:04:05"),
- UpdateAt: now.Format("2006-01-02 15:04:05"),
- }
- _, err = noticeDb.NoticeInsert(¬ice)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, "success", nil)
- 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
- }
- now := time.Now()
-
- if popToCentralKitchen != nil && utils.StrToInt(id) != popToCentralKitchen.Id {
- popToCentralKitchen.IsPopToCentralKitchen = 0
- popToCentralKitchen.UpdateAt = now.Format("2006-01-02 15:04:05")
- _, err = noticeDb.NoticeUpdate(popToCentralKitchen, "is_pop_to_central_kitchen", "update_at")
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- 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
- }
- 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)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- noticeDb := db.NoticeDb{}
- noticeDb.Set()
- notice, err := noticeDb.GetNotice(req.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.Name = req.Name
- notice.Content = req.Content
- notice.UpdateAt = now.Format("2006-01-02 15:04:05")
- _, err = noticeDb.NoticeUpdate(notice, "name", "content", "update_at")
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, "success", nil)
- return
- }
-
- func NoticeDelete(c *gin.Context) {
- id := c.Param("id")
- noticeDb := db.NoticeDb{}
- noticeDb.Set()
- company, err := noticeDb.GetNotice(utils.StrToInt(id))
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- if company == nil {
- e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
- return
- }
-
- _, err = noticeDb.NoticeDelete(id)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, "success", nil)
- return
- }
|