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

201 lines
5.6 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. "fmt"
  10. "github.com/gin-gonic/gin"
  11. "strings"
  12. )
  13. func List(c *gin.Context) {
  14. var req *md.AdvertisingListReq
  15. if err := c.ShouldBindJSON(&req); err != nil {
  16. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  17. return
  18. }
  19. var resp md.AdvertisingListResp
  20. noticeList := make([]md.AdvertisingList, 0)
  21. resp.AdvData = []map[string]string{
  22. {"name": "开屏广告", "value": "1"},
  23. {"name": "插屏广告", "value": "2"},
  24. {"name": "激励视频", "value": "3"},
  25. {"name": "信息流广告", "value": "4"},
  26. {"name": "全屏视频", "value": "5"},
  27. }
  28. resp.SelectData = md.AdvertisingPlatform
  29. NewJpushNoticeDb := implement.NewAdvertisingSpaceDb(db.Db)
  30. notice, total, _ := NewJpushNoticeDb.FindUserFeedbackCateAndTotal(req.Page, req.Limit, req.Name, req.Kind)
  31. resp.Total = total
  32. if notice != nil {
  33. for _, v := range *notice {
  34. tmp := md.AdvertisingList{
  35. Id: utils.IntToStr(v.Id),
  36. CountingDown: utils.IntToStr(v.CountingDown),
  37. Kind: utils.IntToStr(v.Kind),
  38. Info: v.Info,
  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 VisitList(c *gin.Context) {
  49. var req *md.AdvertisingVisitListReq
  50. if err := c.ShouldBindJSON(&req); err != nil {
  51. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  52. return
  53. }
  54. var resp md.AdvertisingVisitListResp
  55. noticeList := make([]md.AdvertisingVisitList, 0)
  56. resp.TypeData = md.AdvertisingType
  57. resp.PlatformData = md.AdvertisingPlatform
  58. uid := req.Uid
  59. if req.Phone != "" {
  60. userDb := implement.NewUserDb(db.Db)
  61. user, err := userDb.UserGetOneByParams(map[string]interface{}{
  62. "key": "phone",
  63. "value": req.Phone,
  64. })
  65. if err != nil {
  66. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  67. return
  68. }
  69. if user != nil {
  70. uid = utils.Int64ToStr(user.Id)
  71. }
  72. }
  73. req.Platform = strings.ReplaceAll(req.Platform, " ", "")
  74. req.Type = strings.ReplaceAll(req.Type, " ", "")
  75. notice := FindAdvertisingCallback(req.Page, req.Limit, req.Amount, uid, req.StartTime, req.EndTime, req.Platform, req.Type)
  76. resp.Total = FindAdvertisingCallbackAndTotal(req.Page, req.Limit, req.Amount, uid, req.StartTime, req.EndTime, req.Platform, req.Type)
  77. if notice != nil {
  78. for _, v := range notice {
  79. userDb := implement.NewUserDb(db.Db)
  80. users, _ := userDb.UserGetOneByParams(map[string]interface{}{
  81. "key": "id",
  82. "value": v["uid"],
  83. })
  84. phone := ""
  85. if users != nil {
  86. phone = users.Phone
  87. }
  88. tmp := md.AdvertisingVisitList{
  89. Id: v["id"],
  90. Uid: v["uid"],
  91. Phone: phone,
  92. Ecpm: v["amount"],
  93. CustomEcpm: v["custom_ecpm"],
  94. Integral: v["integral"],
  95. Platform: v["platform"],
  96. PhonePlatform: v["phone_platform"],
  97. Type: v["type"],
  98. Time: v["create_at"],
  99. }
  100. noticeList = append(noticeList, tmp)
  101. }
  102. }
  103. resp.List = noticeList
  104. e.OutSuc(c, resp, nil)
  105. return
  106. }
  107. func FindAdvertisingCallback(page, limit, amount, uid, startTime, endTime, platform, types string) []map[string]string {
  108. sql := `SELECT * FROM advertising_callback where %s order by id desc %s`
  109. where := "1=1"
  110. if amount != "" {
  111. where += " and CONVERT(amount, FLOAT)<=" + amount
  112. }
  113. if uid != "" {
  114. where += " and uid=" + uid
  115. }
  116. if platform != "" {
  117. where += " and platform='" + platform + "'"
  118. }
  119. if types != "" {
  120. where += " and type='" + types + "'"
  121. }
  122. if startTime != "" {
  123. where += " and create_at>='" + startTime + "'"
  124. }
  125. if endTime != "" {
  126. where += " and create_at<='" + endTime + "'"
  127. }
  128. start := (utils.StrToInt(page) - 1) * utils.StrToInt(limit)
  129. limits := " limit " + utils.IntToStr(start) + "," + limit
  130. sql = fmt.Sprintf(sql, where, limits)
  131. nativeString, _ := db.QueryNativeString(db.Db, sql)
  132. return nativeString
  133. }
  134. func FindAdvertisingCallbackAndTotal(page, limit, amount, uid, startTime, endTime, platform, types string) int64 {
  135. sql := `SELECT COUNT(*) as count FROM advertising_callback where %s`
  136. where := "1=1"
  137. if amount != "" {
  138. where += " and CONVERT(amount, FLOAT)<=" + amount
  139. }
  140. if uid != "" {
  141. where += " and uid=" + uid
  142. }
  143. if platform != "" {
  144. where += " and platform='" + platform + "'"
  145. }
  146. if types != "" {
  147. where += " and type='" + types + "'"
  148. }
  149. if startTime != "" {
  150. where += " and create_at>='" + startTime + "'"
  151. }
  152. if endTime != "" {
  153. where += " and create_at<='" + endTime + "'"
  154. }
  155. sql = fmt.Sprintf(sql, where)
  156. nativeString, _ := db.QueryNativeString(db.Db, sql)
  157. count := "0"
  158. if len(nativeString) > 0 {
  159. count = nativeString[0]["count"]
  160. }
  161. return utils.StrToInt64(count)
  162. }
  163. func Del(c *gin.Context) {
  164. var req *md.ArticleCateDelReq
  165. if err := c.ShouldBindJSON(&req); err != nil {
  166. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  167. return
  168. }
  169. db.Db.In("id", req.Id).Delete(&model.AdvertisingSpace{})
  170. e.OutSuc(c, "success", nil)
  171. return
  172. }
  173. func Save(c *gin.Context) {
  174. var req *md.AdvertisingSaveReq
  175. if err := c.ShouldBindJSON(&req); err != nil {
  176. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  177. return
  178. }
  179. var data = new(model.AdvertisingSpace)
  180. if utils.StrToInt(req.Id) > 0 {
  181. NewAdvertisingSpaceDb := implement.NewAdvertisingSpaceDb(db.Db)
  182. space, _ := NewAdvertisingSpaceDb.GetAdvertisingSpace(req.Id)
  183. if space == nil {
  184. e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
  185. return
  186. }
  187. data = space
  188. } else {
  189. db.Db.Insert(data)
  190. }
  191. data.Name = req.Name
  192. data.Info = req.Info
  193. data.Kind = utils.StrToInt(req.Kind)
  194. data.CountingDown = utils.StrToInt(req.CountingDown)
  195. db.Db.Where("id=?", data.Id).Update(data)
  196. e.OutSuc(c, "success", nil)
  197. return
  198. }