智慧食堂
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.

hdl_notice.go 4.2 KiB

1 year ago
1 year ago
1 year ago
1 year ago
9 months ago
9 months ago
9 months ago
1 year ago
1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. package hdl
  2. import (
  3. "applet/app/admin/lib/validate"
  4. "applet/app/admin/md"
  5. "applet/app/db"
  6. "applet/app/db/model"
  7. "applet/app/e"
  8. "applet/app/utils"
  9. "github.com/gin-gonic/gin"
  10. "time"
  11. )
  12. func NoticeList(c *gin.Context) {
  13. noticeDb := db.NoticeDb{}
  14. noticeDb.Set()
  15. notices, err := noticeDb.FindNotice(0, 0)
  16. if err != nil {
  17. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  18. return
  19. }
  20. e.OutSuc(c, map[string]interface{}{
  21. "list": notices,
  22. "is_pop_to_central_kitchen_list": []map[string]interface{}{
  23. {
  24. "name": "弹出",
  25. "value": 1,
  26. },
  27. {
  28. "name": "不弹出",
  29. "value": 0,
  30. },
  31. },
  32. }, nil)
  33. return
  34. }
  35. func NoticeSort(c *gin.Context) {
  36. var args struct {
  37. Ids []string `json:"ids" binding:"required"`
  38. }
  39. if err := c.ShouldBindJSON(&args); err != nil {
  40. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  41. return
  42. }
  43. noticeDb := db.NoticeDb{}
  44. noticeDb.Set()
  45. notices, err := noticeDb.FindNoticeById(args.Ids)
  46. if err != nil {
  47. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  48. return
  49. }
  50. for k, v := range *notices {
  51. v.Sort = k
  52. _, err1 := noticeDb.NoticeUpdate(&v, "sort")
  53. if err1 != nil {
  54. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  55. return
  56. }
  57. }
  58. e.OutSuc(c, "success", nil)
  59. }
  60. func NoticeAdd(c *gin.Context) {
  61. var req md.NoticeAddReq
  62. err := c.ShouldBindJSON(&req)
  63. if err != nil {
  64. err = validate.HandleValidateErr(err)
  65. err1 := err.(e.E)
  66. e.OutErr(c, err1.Code, err1.Error())
  67. return
  68. }
  69. noticeDb := db.NoticeDb{}
  70. noticeDb.Set()
  71. now := time.Now()
  72. notice := model.Notice{
  73. Name: req.Name,
  74. Content: req.Content,
  75. CreateAt: now.Format("2006-01-02 15:04:05"),
  76. UpdateAt: now.Format("2006-01-02 15:04:05"),
  77. }
  78. _, err = noticeDb.NoticeInsert(&notice)
  79. if err != nil {
  80. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  81. return
  82. }
  83. e.OutSuc(c, "success", nil)
  84. return
  85. }
  86. func NoticeIsPopToCentralKitchen(c *gin.Context) {
  87. id := c.DefaultQuery("id", "0")
  88. isPopToCentralKitchen := c.DefaultQuery("is_pop_to_central_kitchen", "0")
  89. noticeDb := db.NoticeDb{}
  90. noticeDb.Set()
  91. popToCentralKitchen, err := noticeDb.GetPopToCentralKitchen()
  92. if err != nil {
  93. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  94. return
  95. }
  96. now := time.Now()
  97. if popToCentralKitchen != nil && utils.StrToInt(id) != popToCentralKitchen.Id {
  98. popToCentralKitchen.IsPopToCentralKitchen = 0
  99. popToCentralKitchen.UpdateAt = now.Format("2006-01-02 15:04:05")
  100. _, err = noticeDb.NoticeUpdate(popToCentralKitchen, "is_pop_to_central_kitchen", "update_at")
  101. if err != nil {
  102. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  103. return
  104. }
  105. }
  106. notice, err := noticeDb.GetNotice(utils.StrToInt(id))
  107. if err != nil {
  108. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  109. return
  110. }
  111. if notice == nil {
  112. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  113. return
  114. }
  115. notice.IsPopToCentralKitchen = utils.StrToInt(isPopToCentralKitchen)
  116. notice.UpdateAt = now.Format("2006-01-02 15:04:05")
  117. _, err = noticeDb.NoticeUpdate(notice, "is_pop_to_central_kitchen", "update_at")
  118. if err != nil {
  119. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  120. return
  121. }
  122. e.OutSuc(c, "success", nil)
  123. }
  124. func NoticeUpdate(c *gin.Context) {
  125. var req md.NoticeUpdateReq
  126. err := c.ShouldBindJSON(&req)
  127. if err != nil {
  128. err = validate.HandleValidateErr(err)
  129. err1 := err.(e.E)
  130. e.OutErr(c, err1.Code, err1.Error())
  131. return
  132. }
  133. noticeDb := db.NoticeDb{}
  134. noticeDb.Set()
  135. notice, err := noticeDb.GetNotice(req.Id)
  136. if err != nil {
  137. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  138. return
  139. }
  140. if notice == nil {
  141. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  142. return
  143. }
  144. now := time.Now()
  145. notice.Name = req.Name
  146. notice.Content = req.Content
  147. notice.UpdateAt = now.Format("2006-01-02 15:04:05")
  148. _, err = noticeDb.NoticeUpdate(notice, "name", "content", "update_at")
  149. if err != nil {
  150. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  151. return
  152. }
  153. e.OutSuc(c, "success", nil)
  154. return
  155. }
  156. func NoticeDelete(c *gin.Context) {
  157. id := c.Param("id")
  158. noticeDb := db.NoticeDb{}
  159. noticeDb.Set()
  160. company, err := noticeDb.GetNotice(utils.StrToInt(id))
  161. if err != nil {
  162. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  163. return
  164. }
  165. if company == nil {
  166. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  167. return
  168. }
  169. _, err = noticeDb.NoticeDelete(id)
  170. if err != nil {
  171. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  172. return
  173. }
  174. e.OutSuc(c, "success", nil)
  175. return
  176. }