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

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