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

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