|
- 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"
- "strings"
- )
-
- func AppletApplicationAdSpaceMediumList(c *gin.Context) {
- var req md.AppletApplicationAdSpaceMediumListReq
- 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.AppletApplicationAdSpaceMediumListData, 0)
- if len(list) > 0 {
- for _, v := range list {
- var tmp = md.AppletApplicationAdSpaceMediumListData{
- Id: utils.IntToStr(v.Id),
- MediumId: utils.IntToStr(v.MediumId),
- Name: v.Memo,
- Account: v.Username,
- ContactName: "",
- Phone: "",
- Count: "",
- }
- NewMediumContactInfoDb := implement2.NewMediumContactInfoDb(engine)
- 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.AppletApplicationAdSpaceList{})
- tmp.Count = utils.Int64ToStr(count)
- data = append(data, tmp)
- }
- }
- res := md.AppletApplicationAdSpaceMediumListRes{
- List: data,
- Total: total,
- }
- e.OutSuc(c, res, nil)
- return
- }
-
- func AppletApplicationAdSpaceList(c *gin.Context) {
- var req md.AppletApplicationAdSpaceListReq
- 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.NewAppletApplicationAdSpaceListDb(engine)
- appletApplicationList, total, _ := NewAppletApplicationDb.FindAppletApplicationAdSpaceList(req.Name, req.Platform, req.AdType, req.CooperateState, utils.StrToInt(req.MediumId), utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
- data := make([]md.AppletApplicationAdSpaceListData, 0)
- if len(appletApplicationList) > 0 {
- for _, v := range appletApplicationList {
- var tmp = md.AppletApplicationAdSpaceListData{
- Id: utils.IntToStr(v.AppletApplicationAdSpaceList.Id),
- Name: v.AppletApplicationAdSpaceList.Name,
- Platform: v.Platform,
- Kind: v.Kind,
- Memo: v.AppletApplicationAdSpaceList.Memo,
- Logo: v.Logo,
- AppId: v.AppletApplicationAdSpaceList.AppId,
- AdId: v.AppletApplicationAdSpaceList.AdId,
- State: utils.IntToStr(v.AppletApplicationAdSpaceList.State),
- CooperateState: utils.IntToStr(v.AppletApplicationAdSpaceList.State),
- }
- data = append(data, tmp)
- }
- }
- res := md.AppletApplicationAdSpaceListRes{
- List: data,
- Total: total,
- AdType: []md.SelectData{
- {Name: "banner", Value: enum.AdunitTypeForBanner},
- {Name: "激励视频", Value: enum.AdunitTypeForRewardVideo},
- {Name: "插屏广告", Value: enum.AdunitTypeForInterstitial},
- {Name: "视频广告", Value: enum.AdunitTypeForVideoFeeds},
- //{Name: "视频贴片广告", Value: "5"},
- },
- Platform: []md.SelectData{
- {
- Name: "微信小程序",
- Value: "wx_applet",
- },
- },
- State: []md.SelectData{
- {
- Name: "待审核",
- Value: "0",
- },
- {
- Name: "审核通过",
- Value: "1",
- },
- {
- Name: "审核拒绝",
- Value: "2",
- },
- {
- Name: "封禁中",
- Value: "3",
- },
- },
- CooperateState: []md.SelectData{
- {
- Name: "未运行",
- Value: "0",
- },
- {
- Name: "运行中",
- Value: "1",
- },
- {
- Name: "审核拒绝",
- Value: "2",
- },
- {
- Name: "封禁中",
- Value: "3",
- },
- },
- }
- e.OutSuc(c, res, nil)
- return
- }
- func AppletApplicationAdSpaceAudit(c *gin.Context) {
- var req md.AppletApplicationAdSpaceSaveReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- 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
- }
- NewAppletApplicationAdSpaceListDb := implement.NewAppletApplicationAdSpaceListDb(MasterDb(c))
- list, _ := NewAppletApplicationAdSpaceListDb.FindAppletApplicationAdSpaceListByIds(strings.Split(req.Id, ","))
- if list != nil {
-
- for _, v := range *list {
- v.State = utils.StrToInt(req.State)
- v.Memo = req.Memo
- if v.AdId == "" && v.State == 1 && appId != "" {
- err, v.AdId = wxApiService.AgencyCreateAdunit(appId, v.Name, enum.AdunitType(v.Kind))
- if err != nil {
- e.OutErr(c, e.ERR, err.Error())
- return
- }
- v.UseState = 1
- }
- if v.AppId != "" {
- onOff := ""
- if v.State == 3 && v.UseState != 2 { //禁用
- onOff = enum.AdunitStatusForOff
- v.UseState = 2
- }
- if v.State == 1 && v.UseState == 2 { //恢复
- onOff = enum.AdunitStatusForOn
- v.UseState = 1
- }
- if onOff != "" && v.AdId != "" && appId != "" {
- err = wxApiService.AgencyUpdateAdunit(appId, v.AdId, v.Name, enum.AdunitType(v.Kind), enum.AdunitStatus(onOff))
- if err != nil {
- e.OutErr(c, e.ERR, err.Error())
- return
- }
- }
- }
- MasterDb(c).Where("id=?", v.Id).Cols("state,memo,ad_id,use_state").Update(&v)
- }
- }
- e.OutSuc(c, "success", nil)
- return
- }
|