广告平台(站长使用)
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 

218 rindas
6.3 KiB

  1. package svc
  2. import (
  3. "applet/app/e"
  4. "applet/app/lib/validate"
  5. "applet/app/lib/wechat"
  6. "applet/app/lib/wechat/enum"
  7. "applet/app/md"
  8. "applet/app/utils"
  9. db "code.fnuoos.com/zhimeng/model.git/src"
  10. "code.fnuoos.com/zhimeng/model.git/src/implement"
  11. "code.fnuoos.com/zhimeng/model.git/src/model"
  12. implement2 "code.fnuoos.com/zhimeng/model.git/src/super/implement"
  13. "github.com/gin-gonic/gin"
  14. "strings"
  15. )
  16. func AppletApplicationAdSpaceMediumList(c *gin.Context) {
  17. var req md.AppletApplicationAdSpaceMediumListReq
  18. err := c.ShouldBindJSON(&req)
  19. if err != nil {
  20. err = validate.HandleValidateErr(err)
  21. err1 := err.(e.E)
  22. e.OutErr(c, err1.Code, err1.Error())
  23. return
  24. }
  25. engine := MasterDb(c)
  26. NewMediumDb := implement.NewMediumDb(engine)
  27. list, total, _ := NewMediumDb.FindSuperAdmin(req.Account, req.Name, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
  28. data := make([]md.AppletApplicationAdSpaceMediumListData, 0)
  29. if len(list) > 0 {
  30. for _, v := range list {
  31. var tmp = md.AppletApplicationAdSpaceMediumListData{
  32. Id: utils.IntToStr(v.Id),
  33. MediumId: utils.IntToStr(v.MediumId),
  34. Name: v.Memo,
  35. Account: v.Username,
  36. ContactName: "",
  37. Phone: "",
  38. Count: "",
  39. }
  40. NewMediumContactInfoDb := implement2.NewMediumContactInfoDb(engine)
  41. infoList, _ := NewMediumContactInfoDb.GetMediumContactInfoList(v.MediumId)
  42. if infoList != nil {
  43. tmp.ContactName = infoList.Name
  44. tmp.Phone = infoList.Phone
  45. }
  46. count, _ := engine.Where("medium_id=?", v.MediumId).Count(&model.AppletApplicationAdSpaceList{})
  47. tmp.Count = utils.Int64ToStr(count)
  48. data = append(data, tmp)
  49. }
  50. }
  51. res := md.AppletApplicationAdSpaceMediumListRes{
  52. List: data,
  53. Total: total,
  54. }
  55. e.OutSuc(c, res, nil)
  56. return
  57. }
  58. func AppletApplicationAdSpaceList(c *gin.Context) {
  59. var req md.AppletApplicationAdSpaceListReq
  60. err := c.ShouldBindJSON(&req)
  61. if err != nil {
  62. err = validate.HandleValidateErr(err)
  63. err1 := err.(e.E)
  64. e.OutErr(c, err1.Code, err1.Error())
  65. return
  66. }
  67. engine := MasterDb(c)
  68. NewAppletApplicationDb := implement.NewAppletApplicationAdSpaceListDb(engine)
  69. appletApplicationList, total, _ := NewAppletApplicationDb.FindAppletApplicationAdSpaceList(req.Name, req.Platform, req.AdType, req.CooperateState, utils.StrToInt(req.MediumId), utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
  70. data := make([]md.AppletApplicationAdSpaceListData, 0)
  71. if len(appletApplicationList) > 0 {
  72. for _, v := range appletApplicationList {
  73. var tmp = md.AppletApplicationAdSpaceListData{
  74. Id: utils.IntToStr(v.AppletApplicationAdSpaceList.Id),
  75. Name: v.AppletApplicationAdSpaceList.Name,
  76. Platform: v.Platform,
  77. Kind: v.Kind,
  78. Memo: v.AppletApplicationAdSpaceList.Memo,
  79. Logo: v.Logo,
  80. AppId: v.AppletApplicationAdSpaceList.AppId,
  81. AdId: v.AppletApplicationAdSpaceList.AdId,
  82. State: utils.IntToStr(v.AppletApplicationAdSpaceList.State),
  83. CooperateState: utils.IntToStr(v.AppletApplicationAdSpaceList.State),
  84. }
  85. data = append(data, tmp)
  86. }
  87. }
  88. res := md.AppletApplicationAdSpaceListRes{
  89. List: data,
  90. Total: total,
  91. AdType: []md.SelectData{
  92. {Name: "banner", Value: enum.AdunitTypeForBanner},
  93. {Name: "激励视频", Value: enum.AdunitTypeForRewardVideo},
  94. {Name: "插屏广告", Value: enum.AdunitTypeForInterstitial},
  95. {Name: "视频广告", Value: enum.AdunitTypeForVideoFeeds},
  96. //{Name: "视频贴片广告", Value: "5"},
  97. },
  98. Platform: []md.SelectData{
  99. {
  100. Name: "微信小程序",
  101. Value: "wx_applet",
  102. },
  103. },
  104. State: []md.SelectData{
  105. {
  106. Name: "待审核",
  107. Value: "0",
  108. },
  109. {
  110. Name: "审核通过",
  111. Value: "1",
  112. },
  113. {
  114. Name: "审核拒绝",
  115. Value: "2",
  116. },
  117. {
  118. Name: "封禁中",
  119. Value: "3",
  120. },
  121. },
  122. CooperateState: []md.SelectData{
  123. {
  124. Name: "未运行",
  125. Value: "0",
  126. },
  127. {
  128. Name: "运行中",
  129. Value: "1",
  130. },
  131. {
  132. Name: "审核拒绝",
  133. Value: "2",
  134. },
  135. {
  136. Name: "封禁中",
  137. Value: "3",
  138. },
  139. },
  140. }
  141. e.OutSuc(c, res, nil)
  142. return
  143. }
  144. func AppletApplicationAdSpaceAudit(c *gin.Context) {
  145. var req md.AppletApplicationAdSpaceSaveReq
  146. err := c.ShouldBindJSON(&req)
  147. if err != nil {
  148. err = validate.HandleValidateErr(err)
  149. err1 := err.(e.E)
  150. e.OutErr(c, err1.Code, err1.Error())
  151. return
  152. }
  153. masterId := GetMasterId(c)
  154. wxOpenThirdPartyAppListDb := implement2.NewWxOpenThirdPartyAppListDb(db.Db)
  155. wxOpenThirdPartyAppList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId))
  156. if err != nil {
  157. e.OutErr(c, e.ERR, err.Error())
  158. return
  159. }
  160. if wxOpenThirdPartyAppList == nil {
  161. e.OutErr(c, e.ERR_NOT_FAN, "未查询到对应三方应用记录")
  162. return
  163. }
  164. wxApiService, err := wechat.NewWxApiService(masterId, wxOpenThirdPartyAppList.Appid, wxOpenThirdPartyAppList.AppSecret)
  165. if err != nil {
  166. e.OutErr(c, e.ERR, err.Error())
  167. return
  168. }
  169. userWxAppletListDb := implement2.NewUserWxAppletListDb(db.Db)
  170. userWxAppletList, _ := userWxAppletListDb.GetUserWxAppletList(c.GetString("mid"))
  171. appId := ""
  172. if userWxAppletList != nil {
  173. appId = userWxAppletList.Appid
  174. }
  175. NewAppletApplicationAdSpaceListDb := implement.NewAppletApplicationAdSpaceListDb(MasterDb(c))
  176. list, _ := NewAppletApplicationAdSpaceListDb.FindAppletApplicationAdSpaceListByIds(strings.Split(req.Id, ","))
  177. if list != nil {
  178. for _, v := range *list {
  179. v.State = utils.StrToInt(req.State)
  180. v.Memo = req.Memo
  181. if v.AdId == "" && v.State == 1 && appId != "" {
  182. err, v.AdId = wxApiService.AgencyCreateAdunit(appId, v.Name, enum.AdunitType(v.Kind))
  183. if err != nil {
  184. e.OutErr(c, e.ERR, err.Error())
  185. return
  186. }
  187. v.UseState = 1
  188. }
  189. if v.AppId != "" {
  190. onOff := ""
  191. if v.State == 3 && v.UseState != 2 { //禁用
  192. onOff = enum.AdunitStatusForOff
  193. v.UseState = 2
  194. }
  195. if v.State == 1 && v.UseState == 2 { //恢复
  196. onOff = enum.AdunitStatusForOn
  197. v.UseState = 1
  198. }
  199. if onOff != "" && v.AdId != "" && appId != "" {
  200. err = wxApiService.AgencyUpdateAdunit(appId, v.AdId, v.Name, enum.AdunitType(v.Kind), enum.AdunitStatus(onOff))
  201. if err != nil {
  202. e.OutErr(c, e.ERR, err.Error())
  203. return
  204. }
  205. }
  206. }
  207. MasterDb(c).Where("id=?", v.Id).Cols("state,memo,ad_id,use_state").Update(&v)
  208. }
  209. }
  210. e.OutSuc(c, "success", nil)
  211. return
  212. }