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

svc_applet_application_ad_space.go 6.5 KiB

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