蛋蛋星球 后台端
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 

86 righe
2.2 KiB

  1. package article
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. "applet/app/md"
  6. "applet/app/utils"
  7. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  8. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  9. "github.com/gin-gonic/gin"
  10. )
  11. func CateList(c *gin.Context) {
  12. var req *md.ArticleCateListReq
  13. if err := c.ShouldBindJSON(&req); err != nil {
  14. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  15. return
  16. }
  17. var resp md.ArticleCateListResp
  18. noticeList := make([]md.ArticleCateList, 0)
  19. NewJpushNoticeDb := implement.NewArticleCateDb(db.Db)
  20. notice, total, _ := NewJpushNoticeDb.FindArticleCateAndTotalPid(req.Page, req.Limit)
  21. resp.Total = total
  22. resp.SelectData = []map[string]string{}
  23. pid, _ := NewJpushNoticeDb.FindArticleCate("1", "100", "0")
  24. if pid != nil {
  25. for _, v := range *pid {
  26. tmp := map[string]string{
  27. "name": v.Name, "value": utils.IntToStr(v.Id),
  28. }
  29. resp.SelectData = append(resp.SelectData, tmp)
  30. }
  31. }
  32. if notice != nil {
  33. for _, v := range *notice {
  34. tmp := md.ArticleCateList{
  35. Id: utils.IntToStr(v.Id),
  36. Sort: utils.IntToStr(v.Sort),
  37. IsShow: utils.IntToStr(v.IsShow),
  38. Pid: utils.IntToStr(v.Pid),
  39. Name: v.Name,
  40. }
  41. noticeList = append(noticeList, tmp)
  42. }
  43. }
  44. resp.List = noticeList
  45. e.OutSuc(c, resp, nil)
  46. return
  47. }
  48. func CateSave(c *gin.Context) {
  49. var req *md.ArticleCateSaveReq
  50. if err := c.ShouldBindJSON(&req); err != nil {
  51. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  52. return
  53. }
  54. var data = new(model.ArticleCate)
  55. if utils.StrToInt(req.Id) > 0 {
  56. NewArticleCateDb := implement.NewArticleCateDb(db.Db)
  57. notice, _ := NewArticleCateDb.GetArticleCate(req.Id)
  58. if notice == nil {
  59. e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
  60. return
  61. }
  62. data = notice
  63. } else {
  64. db.Db.Insert(data)
  65. }
  66. data.Name = req.Name
  67. data.Sort = utils.StrToInt(req.Sort)
  68. data.Pid = utils.StrToInt(req.Pid)
  69. data.IsShow = utils.StrToInt(req.IsShow)
  70. db.Db.Where("id=?", data.Id).Update(data)
  71. e.OutSuc(c, "success", nil)
  72. return
  73. }
  74. func CateDel(c *gin.Context) {
  75. var req *md.ArticleCateDelReq
  76. if err := c.ShouldBindJSON(&req); err != nil {
  77. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  78. return
  79. }
  80. db.Db.In("id", req.Id).Delete(&model.ArticleCate{})
  81. e.OutSuc(c, "success", nil)
  82. return
  83. }