智慧食堂
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

hdl_notice.go 2.8 KiB

há 1 ano
há 1 ano
há 1 ano
há 1 ano
há 1 ano
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. }, nil)
  23. return
  24. }
  25. func NoticeSort(c *gin.Context) {
  26. var args struct {
  27. Ids []string `json:"ids" binding:"required"`
  28. }
  29. if err := c.ShouldBindJSON(&args); err != nil {
  30. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  31. return
  32. }
  33. noticeDb := db.NoticeDb{}
  34. noticeDb.Set()
  35. notices, err := noticeDb.FindNoticeById(args.Ids)
  36. if err != nil {
  37. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  38. return
  39. }
  40. for k, v := range *notices {
  41. v.Sort = k
  42. _, err1 := noticeDb.NoticeUpdate(&v, "sort")
  43. if err1 != nil {
  44. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  45. return
  46. }
  47. }
  48. e.OutSuc(c, "success", nil)
  49. }
  50. func NoticeAdd(c *gin.Context) {
  51. var req md.NoticeAddReq
  52. err := c.ShouldBindJSON(&req)
  53. if err != nil {
  54. err = validate.HandleValidateErr(err)
  55. err1 := err.(e.E)
  56. e.OutErr(c, err1.Code, err1.Error())
  57. return
  58. }
  59. noticeDb := db.NoticeDb{}
  60. noticeDb.Set()
  61. now := time.Now()
  62. notice := model.Notice{
  63. Name: req.Name,
  64. Content: req.Content,
  65. CreateAt: now.Format("2006-01-02 15:04:05"),
  66. UpdateAt: now.Format("2006-01-02 15:04:05"),
  67. }
  68. _, err = noticeDb.NoticeInsert(&notice)
  69. if err != nil {
  70. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  71. return
  72. }
  73. e.OutSuc(c, "success", nil)
  74. return
  75. }
  76. func NoticeUpdate(c *gin.Context) {
  77. var req md.NoticeUpdateReq
  78. err := c.ShouldBindJSON(&req)
  79. if err != nil {
  80. err = validate.HandleValidateErr(err)
  81. err1 := err.(e.E)
  82. e.OutErr(c, err1.Code, err1.Error())
  83. return
  84. }
  85. noticeDb := db.NoticeDb{}
  86. noticeDb.Set()
  87. notice, err := noticeDb.GetNotice(req.Id)
  88. if err != nil {
  89. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  90. return
  91. }
  92. if notice == nil {
  93. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  94. return
  95. }
  96. now := time.Now()
  97. notice.Name = req.Name
  98. notice.Content = req.Content
  99. notice.UpdateAt = now.Format("2006-01-02 15:04:05")
  100. _, err = noticeDb.NoticeUpdate(notice, "name", "content", "update_at")
  101. if err != nil {
  102. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  103. return
  104. }
  105. e.OutSuc(c, "success", nil)
  106. return
  107. }
  108. func NoticeDelete(c *gin.Context) {
  109. id := c.Param("id")
  110. noticeDb := db.NoticeDb{}
  111. noticeDb.Set()
  112. company, err := noticeDb.GetNotice(utils.StrToInt(id))
  113. if err != nil {
  114. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  115. return
  116. }
  117. if company == nil {
  118. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  119. return
  120. }
  121. _, err = noticeDb.NoticeDelete(id)
  122. if err != nil {
  123. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  124. return
  125. }
  126. e.OutSuc(c, "success", nil)
  127. return
  128. }