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

svc_applet_application.go 6.4 KiB

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