广告平台(站长使用)
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

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