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

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