蛋蛋星球 后台端
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.

svc_list.go 3.5 KiB

3 weeks ago
3 weeks ago
3 weeks ago
2 weeks ago
2 weeks ago
6 days ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package article
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. "applet/app/md"
  6. "applet/app/svc"
  7. "applet/app/utils"
  8. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  9. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  10. "fmt"
  11. "github.com/gin-gonic/gin"
  12. "time"
  13. )
  14. func List(c *gin.Context) {
  15. var req *md.ArticleListReq
  16. if err := c.ShouldBindJSON(&req); err != nil {
  17. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  18. return
  19. }
  20. var resp md.ArticleListResp
  21. noticeList := make([]md.ArticleList, 0)
  22. NewArticleDb := implement.NewArticleDb(db.Db)
  23. notice, total, _ := NewArticleDb.FindArticleAndTotal(req.Page, req.Limit, "", "")
  24. resp.Total = total
  25. resp.SelectData = make([]map[string]interface{}, 0)
  26. NewArticleCateDb := implement.NewArticleCateDb(db.Db)
  27. pid, _ := NewArticleCateDb.FindArticleCate("1", "100", "0")
  28. if pid != nil {
  29. for _, v := range *pid {
  30. list := make([]map[string]string, 0)
  31. tmp := map[string]interface{}{
  32. "name": v.Name, "value": utils.IntToStr(v.Id), "list": list,
  33. }
  34. cate, _ := NewArticleCateDb.FindArticleCate("1", "1000", utils.IntToStr(v.Id))
  35. if cate != nil {
  36. for _, v1 := range *cate {
  37. tmp1 := map[string]string{
  38. "name": v1.Name, "value": utils.IntToStr(v1.Id),
  39. }
  40. list = append(list, tmp1)
  41. }
  42. tmp["list"] = list
  43. }
  44. resp.SelectData = append(resp.SelectData, tmp)
  45. }
  46. }
  47. resp.CateData = make([]map[string]interface{}, 0)
  48. cate, _, _ := NewArticleCateDb.FindArticleCateAndTotalPid("1", "100")
  49. if cate != nil {
  50. for _, v := range *cate {
  51. list := make([]map[string]string, 0)
  52. tmp := map[string]interface{}{
  53. "name": v.Name, "value": utils.IntToStr(v.Id), "list": list,
  54. }
  55. resp.CateData = append(resp.CateData, tmp)
  56. }
  57. }
  58. if notice != nil {
  59. for _, v := range *notice {
  60. isHide := "1"
  61. if v.Pid == 4 {
  62. isHide = "0"
  63. }
  64. tmp := md.ArticleList{
  65. CateId: utils.IntToStr(v.CateId),
  66. Title: v.Title,
  67. Content: v.Content,
  68. Cover: v.Cover,
  69. CoverUrl: svc.GetOssUrl(v.Cover),
  70. Id: utils.IntToStr(v.Id),
  71. Sort: utils.IntToStr(v.Sort),
  72. IsShow: utils.IntToStr(v.IsShow),
  73. Pid: utils.IntToStr(v.Pid),
  74. Url: fmt.Sprintf("%s%s?id=%s&is_hide=%s", svc.GetSysCfgStr("wap_host"), "/#/pages/course-detail-page/course-detail-page", utils.AnyToString(v.Id), isHide),
  75. }
  76. noticeList = append(noticeList, tmp)
  77. }
  78. }
  79. resp.List = noticeList
  80. e.OutSuc(c, resp, nil)
  81. return
  82. }
  83. func Save(c *gin.Context) {
  84. var req *md.ArticleSaveReq
  85. if err := c.ShouldBindJSON(&req); err != nil {
  86. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  87. return
  88. }
  89. var data = new(model.Article)
  90. if utils.StrToInt(req.Id) > 0 {
  91. NewArticleDb := implement.NewArticleDb(db.Db)
  92. notice, _ := NewArticleDb.GetArticle(req.Id)
  93. if notice == nil {
  94. e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
  95. return
  96. }
  97. data = notice
  98. } else {
  99. data.CreatedAt = int(time.Now().Unix())
  100. db.Db.Insert(data)
  101. }
  102. data.UpdatedAt = int(time.Now().Unix())
  103. data.Title = req.Title
  104. data.Cover = req.Cover
  105. data.Content = req.Content
  106. data.TypeId = utils.StrToInt(req.Pid)
  107. data.CateId = utils.StrToInt(req.CateId)
  108. data.Sort = utils.StrToInt(req.Sort)
  109. data.Pid = utils.StrToInt(req.Pid)
  110. data.IsShow = utils.StrToInt(req.IsShow)
  111. db.Db.Where("id=?", data.Id).Update(data)
  112. e.OutSuc(c, "success", nil)
  113. return
  114. }
  115. func Del(c *gin.Context) {
  116. var req *md.ArticleDelReq
  117. if err := c.ShouldBindJSON(&req); err != nil {
  118. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  119. return
  120. }
  121. db.Db.In("id", req.Ids).Delete(&model.Article{})
  122. e.OutSuc(c, "success", nil)
  123. return
  124. }