广告平台(媒体使用)
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.
 
 
 
 
 
 

119 lines
3.5 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.AdType, 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. AppName: v.AppletApplication.Name,
  33. Platform: v.Platform,
  34. Kind: v.Kind,
  35. Memo: v.AppletApplicationAdSpaceList.Memo,
  36. Logo: v.Logo,
  37. AppId: v.AppletApplicationAdSpaceList.AppId,
  38. AdId: v.AdId,
  39. State: utils.IntToStr(v.AppletApplicationAdSpaceList.State),
  40. CooperateState: utils.IntToStr(v.AppletApplicationAdSpaceList.State),
  41. }
  42. data = append(data, tmp)
  43. }
  44. }
  45. applicationDb := implement.NewAppletApplicationDb(engine)
  46. list, _, _ := applicationDb.FindAppletApplicationList("", req.Platform, []string{"2"}, user.MediumId, 0, 0)
  47. var application = make([]map[string]string, 0)
  48. for _, v := range list {
  49. tmp := map[string]string{
  50. "app_id": v.AppId,
  51. "logo": v.Logo,
  52. "name": v.Name,
  53. "state_str": "运行中",
  54. }
  55. application = append(application, tmp)
  56. }
  57. res := md.AppletApplicationAdSpaceListRes{
  58. List: data,
  59. Total: total,
  60. Application: application,
  61. AdType: enum.AdTypeList,
  62. Platform: []md.SelectData{
  63. {Name: "微信小程序", Value: "wx_applet"},
  64. },
  65. State: []md.SelectData{
  66. {Name: "待审核", Value: "0"},
  67. {Name: "审核通过", Value: "1"},
  68. {Name: "审核拒绝", Value: "2"},
  69. {Name: "封禁中", Value: "3"},
  70. },
  71. CooperateState: []md.SelectData{
  72. {Name: "未运行", Value: "0"},
  73. {Name: "运行中", Value: "1"},
  74. {Name: "审核拒绝", Value: "2"},
  75. {Name: "封禁中", Value: "3"},
  76. },
  77. }
  78. e.OutSuc(c, res, nil)
  79. return
  80. }
  81. func AppletApplicationAdSpaceSave(c *gin.Context) {
  82. var req md.AppletApplicationAdSpaceSaveReq
  83. err := c.ShouldBindJSON(&req)
  84. if err != nil {
  85. err = validate.HandleValidateErr(err)
  86. err1 := err.(e.E)
  87. e.OutErr(c, err1.Code, err1.Error())
  88. return
  89. }
  90. if req.AppId == "" {
  91. e.OutErr(c, 400, e.NewErr(400, "请填写小程序appid"))
  92. return
  93. }
  94. NewAppletApplicationDb := implement.NewAppletApplicationDb(MasterDb(c))
  95. app, _ := NewAppletApplicationDb.GetAppletApplicationListByAppid(req.AppId)
  96. if app == nil {
  97. e.OutErr(c, 400, e.NewErr(400, "应用不存在"))
  98. return
  99. }
  100. user := GetUser(c)
  101. engine := MasterDb(c)
  102. data := &model.AppletApplicationAdSpaceList{
  103. Name: req.Name,
  104. AppId: req.AppId,
  105. Kind: req.Kind,
  106. State: 0,
  107. MediumId: user.MediumId,
  108. CreateAt: time.Now(),
  109. UpdateAt: time.Now(),
  110. }
  111. engine.Insert(data)
  112. e.OutSuc(c, "success", nil)
  113. return
  114. }