|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- package svc
-
- import (
- "applet/app/e"
- "applet/app/lib/validate"
- "applet/app/lib/wechat"
- "applet/app/lib/wechat/enum"
- "applet/app/md"
- "applet/app/utils"
- db "code.fnuoos.com/zhimeng/model.git/src"
- "code.fnuoos.com/zhimeng/model.git/src/implement"
- "code.fnuoos.com/zhimeng/model.git/src/model"
- implement2 "code.fnuoos.com/zhimeng/model.git/src/super/implement"
- "github.com/gin-gonic/gin"
- "github.com/jinzhu/copier"
- "strings"
- )
-
- func AppletApplicationMediumList(c *gin.Context) {
- var req md.AppletApplicationMediumListReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- engine := MasterDb(c)
- NewMediumDb := implement.NewMediumDb(engine)
- user := GetUser(c)
- appId := GetMediumIdStr(c, user.AdmId, req.Name, req.Account)
-
- list, total, _ := NewMediumDb.FindSuperAdminByMediumId(appId, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
- data := make([]md.AppletApplicationMediumListData, 0)
- if len(list) > 0 {
- for _, v := range list {
- var tmp = md.AppletApplicationMediumListData{
- Id: utils.IntToStr(v.Id),
- MediumId: utils.IntToStr(v.MediumId),
- Name: v.Memo,
- Account: v.Username,
- ContactName: "",
- Phone: "",
- Count: "",
- }
- NewMediumContactInfoDb := implement2.NewMediumContactInfoDb(db.Db)
- infoList, _ := NewMediumContactInfoDb.GetMediumContactInfoList(v.MediumId)
- if infoList != nil {
- tmp.ContactName = infoList.Name
- tmp.Phone = infoList.Phone
- }
- NewMediumListDb := implement2.NewMediumListDb(db.Db)
- GetMediumList, _ := NewMediumListDb.GetMediumList(v.MediumId)
- if GetMediumList != nil {
- tmp.Name = GetMediumList.CompanyName
- if GetMediumList.CompanyAbbreviation != "" {
- tmp.Name = GetMediumList.CompanyAbbreviation
- }
- }
- count, _ := engine.Where("medium_id=?", v.MediumId).Count(&model.AppletApplication{})
- tmp.Count = utils.Int64ToStr(count)
- data = append(data, tmp)
- }
- }
- res := md.AppletApplicationMediumListRes{
- List: data,
- Total: total,
- }
- e.OutSuc(c, res, nil)
- return
- }
- func AppletApplicationList(c *gin.Context) {
- var req md.AppletApplicationListReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- engine := MasterDb(c)
- NewAppletApplicationDb := implement.NewAppletApplicationDb(engine)
- state := make([]string, 0)
- if req.CooperateState != "" {
- if req.CooperateState == "0" {
- state = []string{"0", "1"}
- } else {
- state = []string{req.CooperateState}
- }
- }
- appletApplicationList, total, _ := NewAppletApplicationDb.FindAppletApplicationList(req.Name, req.Platform, state, utils.StrToInt(req.MediumId), utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
- data := make([]md.AppletApplicationListData, 0)
- if len(appletApplicationList) > 0 {
- for _, v := range appletApplicationList {
- var tmp md.AppletApplicationListData
- copier.Copy(&tmp, &v)
- tmp.Id = utils.IntToStr(v.Id)
- tmp.State = utils.IntToStr(v.State)
- if v.State == 1 {
- v.State = 0
- }
- tmp.CooperateState = utils.IntToStr(v.State)
- data = append(data, tmp)
- }
- }
- res := md.AppletApplicationListRes{
- List: data,
- Total: total,
- Platform: []md.SelectData{
- {
- Name: "微信小程序",
- Value: "wx_applet",
- },
- },
- State: []md.SelectData{
- {
- Name: "待审核",
- Value: "0",
- },
- {
- Name: "审核中",
- Value: "1",
- },
- {
- Name: "审核通过",
- Value: "2",
- },
- {
- Name: "审核拒绝",
- Value: "3",
- },
- {
- Name: "封禁中",
- Value: "4",
- },
- },
- CooperateState: []md.SelectData{
- {
- Name: "未运行",
- Value: "0",
- },
- {
- Name: "运行中",
- Value: "2",
- },
- {
- Name: "审核拒绝",
- Value: "3",
- },
- {
- Name: "封禁中",
- Value: "4",
- },
- },
- }
- e.OutSuc(c, res, nil)
- return
- }
- func AppletApplicationAudit(c *gin.Context) {
- var req md.AppletApplicationSaveReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- NewAppletApplicationDb := implement.NewAppletApplicationDb(MasterDb(c))
- list, _ := NewAppletApplicationDb.FindAppletApplicationListByIds(strings.Split(req.Id, ","))
- if list != nil {
- masterId := GetMasterId(c)
- wxOpenThirdPartyAppListDb := implement2.NewWxOpenThirdPartyAppListDb(db.Db)
- wxOpenThirdPartyAppList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId))
- if err != nil {
- e.OutErr(c, e.ERR, err.Error())
- return
- }
- if wxOpenThirdPartyAppList == nil {
- e.OutErr(c, e.ERR_NOT_FAN, "未查询到对应三方应用记录")
- return
- }
- wxApiService, err := wechat.NewWxApiService(masterId, wxOpenThirdPartyAppList.Appid, wxOpenThirdPartyAppList.AppSecret)
- if err != nil {
- e.OutErr(c, e.ERR, err.Error())
- return
- }
- userWxAppletListDb := implement2.NewUserWxAppletListDb(db.Db)
- userWxAppletList, _ := userWxAppletListDb.GetUserWxAppletList(c.GetString("mid"))
- appId := ""
- if userWxAppletList != nil {
- appId = userWxAppletList.Appid
- }
- for _, v := range *list {
- v.State = utils.StrToInt(req.State)
- v.Memo = req.Memo
- err := changeWx(c, wxApiService, appId, v.State, v.MediumId)
- if err != nil {
- e.OutErr(c, e.ERR, err.Error())
- return
- }
- MasterDb(c).Where("id=?", v.Id).Cols("state,memo").Update(&v)
- }
- }
- e.OutSuc(c, "success", nil)
- return
- }
- func changeWx(c *gin.Context, wxApiService wechat.WxApiService, appId string, state, mediumId int) error {
- if state != 2 && state != 4 {
- return nil
- }
- NewAppletApplicationAdSpaceListDb := implement.NewAppletApplicationAdSpaceListDb(MasterDb(c))
- list, _ := NewAppletApplicationAdSpaceListDb.FindAppletApplicationAdSpaceListByMediumId(mediumId)
- if list != nil {
- for _, v := range *list { //全部恢复 全部封禁
- if v.State != 2 && v.State != 4 {
- continue
- }
- if v.AppId != "" {
- onOff := ""
- if state == 4 { //禁用
- onOff = enum.AdunitStatusForOff
- v.UseState = 2
- v.State = 3
- }
- if state == 2 { //恢复
- onOff = enum.AdunitStatusForOn
- v.UseState = 1
- v.State = 1
- }
- if onOff != "" && v.AdId != "" && appId != "" {
- err := wxApiService.AgencyUpdateAdunit(appId, v.AdId, v.Name, enum.AdunitType(v.Kind), enum.AdunitStatus(onOff))
- if err != nil {
- return err
- }
- }
- MasterDb(c).Where("id=?", v.Id).Cols("state,use_state").Update(&v)
- }
- }
- }
- return nil
- }
|