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

142 lines
4.0 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. "strings"
  11. )
  12. func List(c *gin.Context) {
  13. var req *md.AdvertisingListReq
  14. if err := c.ShouldBindJSON(&req); err != nil {
  15. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  16. return
  17. }
  18. var resp md.AdvertisingListResp
  19. noticeList := make([]md.AdvertisingList, 0)
  20. resp.AdvData = []map[string]string{
  21. {"name": "开屏广告", "value": "1"},
  22. {"name": "插屏广告", "value": "2"},
  23. {"name": "激励视频", "value": "3"},
  24. {"name": "信息流广告", "value": "4"},
  25. {"name": "全屏视频", "value": "5"},
  26. }
  27. resp.SelectData = md.AdvertisingPlatform
  28. NewJpushNoticeDb := implement.NewAdvertisingSpaceDb(db.Db)
  29. notice, total, _ := NewJpushNoticeDb.FindUserFeedbackCateAndTotal(req.Page, req.Limit, req.Name, req.Kind)
  30. resp.Total = total
  31. if notice != nil {
  32. for _, v := range *notice {
  33. tmp := md.AdvertisingList{
  34. Id: utils.IntToStr(v.Id),
  35. CountingDown: utils.IntToStr(v.CountingDown),
  36. Kind: utils.IntToStr(v.Kind),
  37. Info: v.Info,
  38. Name: v.Name,
  39. }
  40. noticeList = append(noticeList, tmp)
  41. }
  42. }
  43. resp.List = noticeList
  44. e.OutSuc(c, resp, nil)
  45. return
  46. }
  47. func VisitList(c *gin.Context) {
  48. var req *md.AdvertisingVisitListReq
  49. if err := c.ShouldBindJSON(&req); err != nil {
  50. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  51. return
  52. }
  53. var resp md.AdvertisingVisitListResp
  54. noticeList := make([]md.AdvertisingVisitList, 0)
  55. resp.TypeData = md.AdvertisingType
  56. resp.PlatformData = md.AdvertisingPlatform
  57. uid := req.Uid
  58. if req.Phone != "" {
  59. userDb := implement.NewUserDb(db.Db)
  60. user, err := userDb.UserGetOneByParams(map[string]interface{}{
  61. "key": "phone",
  62. "value": req.Phone,
  63. })
  64. if err != nil {
  65. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  66. return
  67. }
  68. uid = utils.Int64ToStr(user.Id)
  69. }
  70. req.Platform = strings.ReplaceAll(req.Platform, " ", "")
  71. req.Type = strings.ReplaceAll(req.Type, " ", "")
  72. NewAdvertisingCallbackDb := implement.NewAdvertisingCallbackDb(db.Db)
  73. notice, total, _ := NewAdvertisingCallbackDb.FindAdvertisingCallbackAndTotal(req.Page, req.Limit, req.Amount, uid, req.StartTime, req.EndTime, req.Platform, req.Type)
  74. resp.Total = total
  75. if notice != nil {
  76. for _, v := range *notice {
  77. userDb := implement.NewUserDb(db.Db)
  78. users, _ := userDb.UserGetOneByParams(map[string]interface{}{
  79. "key": "id",
  80. "value": v.Uid,
  81. })
  82. phone := ""
  83. if users != nil {
  84. phone = users.Phone
  85. }
  86. tmp := md.AdvertisingVisitList{
  87. Id: utils.IntToStr(v.Id),
  88. Uid: utils.IntToStr(v.Uid),
  89. Phone: phone,
  90. Ecpm: v.Amount,
  91. Integral: v.Integral,
  92. Platform: v.Platform,
  93. PhonePlatform: v.PhonePlatform,
  94. Type: v.Type,
  95. Time: v.CreateAt.Format("2006-01-02 15:04:05"),
  96. }
  97. noticeList = append(noticeList, tmp)
  98. }
  99. }
  100. resp.List = noticeList
  101. e.OutSuc(c, resp, nil)
  102. return
  103. }
  104. func Del(c *gin.Context) {
  105. var req *md.ArticleCateDelReq
  106. if err := c.ShouldBindJSON(&req); err != nil {
  107. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  108. return
  109. }
  110. db.Db.In("id", req.Id).Delete(&model.AdvertisingSpace{})
  111. e.OutSuc(c, "success", nil)
  112. return
  113. }
  114. func Save(c *gin.Context) {
  115. var req *md.AdvertisingSaveReq
  116. if err := c.ShouldBindJSON(&req); err != nil {
  117. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  118. return
  119. }
  120. var data = new(model.AdvertisingSpace)
  121. if utils.StrToInt(req.Id) > 0 {
  122. NewAdvertisingSpaceDb := implement.NewAdvertisingSpaceDb(db.Db)
  123. space, _ := NewAdvertisingSpaceDb.GetAdvertisingSpace(req.Id)
  124. if space == nil {
  125. e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
  126. return
  127. }
  128. data = space
  129. } else {
  130. db.Db.Insert(data)
  131. }
  132. data.Name = req.Name
  133. data.Info = req.Info
  134. data.Kind = utils.StrToInt(req.Kind)
  135. data.CountingDown = utils.StrToInt(req.CountingDown)
  136. db.Db.Where("id=?", data.Id).Update(data)
  137. e.OutSuc(c, "success", nil)
  138. return
  139. }