|
- 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)
-
- list, total, _ := NewMediumDb.FindSuperAdmin(req.Account, req.Name, 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
- }
|