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

82 lines
2.2 KiB

  1. package advertising
  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 List(c *gin.Context) {
  12. var req *md.AdvertisingListReq
  13. if err := c.ShouldBindJSON(&req); err != nil {
  14. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  15. return
  16. }
  17. var resp md.AdvertisingListResp
  18. noticeList := make([]md.AdvertisingList, 0)
  19. resp.SelectData = []map[string]string{
  20. {"name": "开屏广告", "value": "1"},
  21. {"name": "插屏广告", "value": "2"},
  22. {"name": "激励视频", "value": "3"},
  23. {"name": "信息流广告", "value": "4"},
  24. {"name": "全屏视频", "value": "5"},
  25. }
  26. NewJpushNoticeDb := implement.NewAdvertisingSpaceDb(db.Db)
  27. notice, total, _ := NewJpushNoticeDb.FindUserFeedbackCateAndTotal(req.Page, req.Limit, req.Name, req.Kind)
  28. resp.Total = total
  29. if notice != nil {
  30. for _, v := range *notice {
  31. tmp := md.AdvertisingList{
  32. Id: utils.IntToStr(v.Id),
  33. CountingDown: utils.IntToStr(v.CountingDown),
  34. Kind: utils.IntToStr(v.Kind),
  35. Info: v.Info,
  36. Name: v.Name,
  37. }
  38. noticeList = append(noticeList, tmp)
  39. }
  40. }
  41. resp.List = noticeList
  42. e.OutSuc(c, resp, nil)
  43. return
  44. }
  45. func Del(c *gin.Context) {
  46. var req *md.ArticleCateDelReq
  47. if err := c.ShouldBindJSON(&req); err != nil {
  48. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  49. return
  50. }
  51. db.Db.In("id", req.Id).Delete(&model.AdvertisingSpace{})
  52. e.OutSuc(c, "success", nil)
  53. return
  54. }
  55. func Save(c *gin.Context) {
  56. var req *md.AdvertisingSaveReq
  57. if err := c.ShouldBindJSON(&req); err != nil {
  58. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  59. return
  60. }
  61. var data = new(model.AdvertisingSpace)
  62. if utils.StrToInt(req.Id) > 0 {
  63. NewAdvertisingSpaceDb := implement.NewAdvertisingSpaceDb(db.Db)
  64. space, _ := NewAdvertisingSpaceDb.GetAdvertisingSpace(req.Id)
  65. if space == nil {
  66. e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
  67. return
  68. }
  69. data = space
  70. } else {
  71. db.Db.Insert(data)
  72. }
  73. data.Name = req.Name
  74. data.Info = req.Info
  75. data.CountingDown = utils.StrToInt(req.CountingDown)
  76. db.Db.Where("id=?", data.Id).Update(data)
  77. e.OutSuc(c, "success", nil)
  78. return
  79. }