广告平台(媒体使用)
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

124 satır
3.7 KiB

  1. package svc
  2. import (
  3. "applet/app/e"
  4. "applet/app/enum"
  5. "applet/app/lib/validate"
  6. "applet/app/md"
  7. "applet/app/utils"
  8. "code.fnuoos.com/zhimeng/model.git/src/implement"
  9. "code.fnuoos.com/zhimeng/model.git/src/model"
  10. "github.com/gin-gonic/gin"
  11. "time"
  12. )
  13. func AppletApplicationAdSpaceList(c *gin.Context) {
  14. var req md.AppletApplicationAdSpaceListReq
  15. err := c.ShouldBindJSON(&req)
  16. if err != nil {
  17. err = validate.HandleValidateErr(err)
  18. err1 := err.(e.E)
  19. e.OutErr(c, err1.Code, err1.Error())
  20. return
  21. }
  22. user := GetUser(c)
  23. engine := MasterDb(c)
  24. NewAppletApplicationDb := implement.NewAppletApplicationAdSpaceListDb(engine)
  25. appletApplicationList, total, _ := NewAppletApplicationDb.FindAppletApplicationAdSpaceList(req.Name, req.Platform, req.CooperateState, user.MediumId, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
  26. data := make([]md.AppletApplicationAdSpaceListData, 0)
  27. if len(appletApplicationList) > 0 {
  28. for _, v := range appletApplicationList {
  29. var tmp = md.AppletApplicationAdSpaceListData{
  30. Id: utils.IntToStr(v.AppletApplicationAdSpaceList.Id),
  31. Name: v.AppletApplicationAdSpaceList.Name,
  32. Platform: v.Platform,
  33. Kind: v.Kind,
  34. Memo: v.AppletApplicationAdSpaceList.Memo,
  35. Logo: v.Logo,
  36. AppId: v.AppletApplicationAdSpaceList.AppId,
  37. AdId: v.AdId,
  38. State: utils.IntToStr(v.AppletApplicationAdSpaceList.State),
  39. CooperateState: utils.IntToStr(v.AppletApplicationAdSpaceList.State),
  40. }
  41. data = append(data, tmp)
  42. }
  43. }
  44. applicationDb := implement.NewAppletApplicationDb(engine)
  45. list, _, _ := applicationDb.FindAppletApplicationList("", req.Platform, []string{"2"}, user.MediumId, 0, 0)
  46. var application = make([]map[string]string, 0)
  47. for _, v := range list {
  48. tmp := map[string]string{
  49. "app_id": v.AppId,
  50. "logo": v.Logo,
  51. "name": v.Name,
  52. "state_str": "运行中",
  53. }
  54. application = append(application, tmp)
  55. }
  56. res := md.AppletApplicationAdSpaceListRes{
  57. List: data,
  58. Total: total,
  59. Application: application,
  60. AdType: []md.SelectData{
  61. {Name: "banner", Value: enum.AdunitTypeForBanner},
  62. {Name: "激励视频", Value: enum.AdunitTypeForRewardVideo},
  63. {Name: "插屏广告", Value: enum.AdunitTypeForInterstitial},
  64. {Name: "视频广告", Value: enum.AdunitTypeForVideoFeeds},
  65. //{Name: "视频贴片广告", Value: "5"},
  66. },
  67. Platform: []md.SelectData{
  68. {Name: "微信小程序", Value: "wx_applet"},
  69. },
  70. State: []md.SelectData{
  71. {Name: "待审核", Value: "0"},
  72. {Name: "审核通过", Value: "1"},
  73. {Name: "审核拒绝", Value: "2"},
  74. {Name: "封禁中", Value: "3"},
  75. },
  76. CooperateState: []md.SelectData{
  77. {Name: "未运行", Value: "0"},
  78. {Name: "运行中", Value: "1"},
  79. {Name: "审核拒绝", Value: "2"},
  80. {Name: "封禁中", Value: "3"},
  81. },
  82. }
  83. e.OutSuc(c, res, nil)
  84. return
  85. }
  86. func AppletApplicationAdSpaceSave(c *gin.Context) {
  87. var req md.AppletApplicationAdSpaceSaveReq
  88. err := c.ShouldBindJSON(&req)
  89. if err != nil {
  90. err = validate.HandleValidateErr(err)
  91. err1 := err.(e.E)
  92. e.OutErr(c, err1.Code, err1.Error())
  93. return
  94. }
  95. if req.AppId == "" {
  96. e.OutErr(c, 400, e.NewErr(400, "请填写小程序appid"))
  97. return
  98. }
  99. NewAppletApplicationDb := implement.NewAppletApplicationDb(MasterDb(c))
  100. app, _ := NewAppletApplicationDb.GetAppletApplicationListByAppid(req.AppId)
  101. if app == nil {
  102. e.OutErr(c, 400, e.NewErr(400, "应用不存在"))
  103. return
  104. }
  105. user := GetUser(c)
  106. engine := MasterDb(c)
  107. data := &model.AppletApplicationAdSpaceList{
  108. Name: req.Name,
  109. AppId: req.AppId,
  110. Kind: req.Kind,
  111. State: 0,
  112. MediumId: user.MediumId,
  113. CreateAt: time.Now(),
  114. UpdateAt: time.Now(),
  115. }
  116. engine.Insert(data)
  117. e.OutSuc(c, "success", nil)
  118. return
  119. }