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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. "github.com/jinzhu/copier"
  15. "strings"
  16. )
  17. func AppletApplicationMediumList(c *gin.Context) {
  18. var req md.AppletApplicationMediumListReq
  19. err := c.ShouldBindJSON(&req)
  20. if err != nil {
  21. err = validate.HandleValidateErr(err)
  22. err1 := err.(e.E)
  23. e.OutErr(c, err1.Code, err1.Error())
  24. return
  25. }
  26. engine := MasterDb(c)
  27. NewMediumDb := implement.NewMediumDb(engine)
  28. list, total, _ := NewMediumDb.FindSuperAdmin(req.Account, req.Name, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
  29. data := make([]md.AppletApplicationMediumListData, 0)
  30. if len(list) > 0 {
  31. for _, v := range list {
  32. var tmp = md.AppletApplicationMediumListData{
  33. Id: utils.IntToStr(v.Id),
  34. MediumId: utils.IntToStr(v.MediumId),
  35. Name: v.Memo,
  36. Account: v.Username,
  37. ContactName: "",
  38. Phone: "",
  39. Count: "",
  40. }
  41. NewMediumContactInfoDb := implement2.NewMediumContactInfoDb(db.Db)
  42. infoList, _ := NewMediumContactInfoDb.GetMediumContactInfoList(v.MediumId)
  43. if infoList != nil {
  44. tmp.ContactName = infoList.Name
  45. tmp.Phone = infoList.Phone
  46. }
  47. count, _ := engine.Where("medium_id=?", v.MediumId).Count(&model.AppletApplication{})
  48. tmp.Count = utils.Int64ToStr(count)
  49. data = append(data, tmp)
  50. }
  51. }
  52. res := md.AppletApplicationMediumListRes{
  53. List: data,
  54. Total: total,
  55. }
  56. e.OutSuc(c, res, nil)
  57. return
  58. }
  59. func AppletApplicationList(c *gin.Context) {
  60. var req md.AppletApplicationListReq
  61. err := c.ShouldBindJSON(&req)
  62. if err != nil {
  63. err = validate.HandleValidateErr(err)
  64. err1 := err.(e.E)
  65. e.OutErr(c, err1.Code, err1.Error())
  66. return
  67. }
  68. engine := MasterDb(c)
  69. NewAppletApplicationDb := implement.NewAppletApplicationDb(engine)
  70. state := make([]string, 0)
  71. if req.CooperateState != "" {
  72. if req.CooperateState == "0" {
  73. state = []string{"0", "1"}
  74. } else {
  75. state = []string{req.CooperateState}
  76. }
  77. }
  78. appletApplicationList, total, _ := NewAppletApplicationDb.FindAppletApplicationList(req.Name, req.Platform, state, utils.StrToInt(req.MediumId), utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
  79. data := make([]md.AppletApplicationListData, 0)
  80. if len(appletApplicationList) > 0 {
  81. for _, v := range appletApplicationList {
  82. var tmp md.AppletApplicationListData
  83. copier.Copy(&tmp, &v)
  84. tmp.Id = utils.IntToStr(v.Id)
  85. tmp.State = utils.IntToStr(v.State)
  86. if v.State == 1 {
  87. v.State = 0
  88. }
  89. tmp.CooperateState = utils.IntToStr(v.State)
  90. data = append(data, tmp)
  91. }
  92. }
  93. res := md.AppletApplicationListRes{
  94. List: data,
  95. Total: total,
  96. Platform: []md.SelectData{
  97. {
  98. Name: "微信小程序",
  99. Value: "wx_applet",
  100. },
  101. },
  102. State: []md.SelectData{
  103. {
  104. Name: "待审核",
  105. Value: "0",
  106. },
  107. {
  108. Name: "审核中",
  109. Value: "1",
  110. },
  111. {
  112. Name: "审核通过",
  113. Value: "2",
  114. },
  115. {
  116. Name: "审核拒绝",
  117. Value: "3",
  118. },
  119. {
  120. Name: "封禁中",
  121. Value: "4",
  122. },
  123. },
  124. CooperateState: []md.SelectData{
  125. {
  126. Name: "未运行",
  127. Value: "0",
  128. },
  129. {
  130. Name: "运行中",
  131. Value: "2",
  132. },
  133. {
  134. Name: "审核拒绝",
  135. Value: "3",
  136. },
  137. {
  138. Name: "封禁中",
  139. Value: "4",
  140. },
  141. },
  142. }
  143. e.OutSuc(c, res, nil)
  144. return
  145. }
  146. func AppletApplicationAudit(c *gin.Context) {
  147. var req md.AppletApplicationSaveReq
  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. NewAppletApplicationDb := implement.NewAppletApplicationDb(MasterDb(c))
  156. list, _ := NewAppletApplicationDb.FindAppletApplicationListByIds(strings.Split(req.Id, ","))
  157. if list != nil {
  158. masterId := GetMasterId(c)
  159. wxOpenThirdPartyAppListDb := implement2.NewWxOpenThirdPartyAppListDb(db.Db)
  160. wxOpenThirdPartyAppList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId))
  161. if err != nil {
  162. e.OutErr(c, e.ERR, err.Error())
  163. return
  164. }
  165. if wxOpenThirdPartyAppList == nil {
  166. e.OutErr(c, e.ERR_NOT_FAN, "未查询到对应三方应用记录")
  167. return
  168. }
  169. wxApiService, err := wechat.NewWxApiService(masterId, wxOpenThirdPartyAppList.Appid, wxOpenThirdPartyAppList.AppSecret)
  170. if err != nil {
  171. e.OutErr(c, e.ERR, err.Error())
  172. return
  173. }
  174. userWxAppletListDb := implement2.NewUserWxAppletListDb(db.Db)
  175. userWxAppletList, _ := userWxAppletListDb.GetUserWxAppletList(c.GetString("mid"))
  176. appId := ""
  177. if userWxAppletList != nil {
  178. appId = userWxAppletList.Appid
  179. }
  180. for _, v := range *list {
  181. v.State = utils.StrToInt(req.State)
  182. v.Memo = req.Memo
  183. err := changeWx(c, wxApiService, appId, v.State, v.MediumId)
  184. if err != nil {
  185. e.OutErr(c, e.ERR, err.Error())
  186. return
  187. }
  188. MasterDb(c).Where("id=?", v.Id).Cols("state,memo").Update(&v)
  189. }
  190. }
  191. e.OutSuc(c, "success", nil)
  192. return
  193. }
  194. func changeWx(c *gin.Context, wxApiService wechat.WxApiService, appId string, state, mediumId int) error {
  195. if state != 2 && state != 4 {
  196. return nil
  197. }
  198. NewAppletApplicationAdSpaceListDb := implement.NewAppletApplicationAdSpaceListDb(MasterDb(c))
  199. list, _ := NewAppletApplicationAdSpaceListDb.FindAppletApplicationAdSpaceListByMediumId(mediumId)
  200. if list != nil {
  201. for _, v := range *list { //全部恢复 全部封禁
  202. if v.State != 2 && v.State != 4 {
  203. continue
  204. }
  205. if v.AppId != "" {
  206. onOff := ""
  207. if state == 4 { //禁用
  208. onOff = enum.AdunitStatusForOff
  209. v.UseState = 2
  210. v.State = 3
  211. }
  212. if state == 2 { //恢复
  213. onOff = enum.AdunitStatusForOn
  214. v.UseState = 1
  215. v.State = 1
  216. }
  217. if onOff != "" && v.AdId != "" && appId != "" {
  218. err := wxApiService.AgencyUpdateAdunit(appId, v.AdId, v.Name, enum.AdunitType(v.Kind), enum.AdunitStatus(onOff))
  219. if err != nil {
  220. return err
  221. }
  222. }
  223. MasterDb(c).Where("id=?", v.Id).Cols("state,use_state").Update(&v)
  224. }
  225. }
  226. }
  227. return nil
  228. }