package svc import ( "applet/app/e" "applet/app/enum" "applet/app/lib/validate" "applet/app/md" "applet/app/utils" "code.fnuoos.com/zhimeng/model.git/src/implement" "code.fnuoos.com/zhimeng/model.git/src/model" "github.com/gin-gonic/gin" "time" ) 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 } user := GetUser(c) engine := MasterDb(c) NewAppletApplicationDb := implement.NewAppletApplicationAdSpaceListDb(engine) appletApplicationList, total, _ := NewAppletApplicationDb.FindAppletApplicationAdSpaceList(req.Name, req.Platform, req.CooperateState, user.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.AdId, State: utils.IntToStr(v.AppletApplicationAdSpaceList.State), CooperateState: utils.IntToStr(v.AppletApplicationAdSpaceList.State), } data = append(data, tmp) } } applicationDb := implement.NewAppletApplicationDb(engine) list, _, _ := applicationDb.FindAppletApplicationList("", req.Platform, []string{"2"}, user.MediumId, 0, 0) var application = make([]map[string]string, 0) for _, v := range list { tmp := map[string]string{ "app_id": v.AppId, "logo": v.Logo, "name": v.Name, "state_str": "运行中", } application = append(application, tmp) } res := md.AppletApplicationAdSpaceListRes{ List: data, Total: total, Application: application, 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 AppletApplicationAdSpaceSave(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 } if req.AppId == "" { e.OutErr(c, 400, e.NewErr(400, "请填写小程序appid")) return } NewAppletApplicationDb := implement.NewAppletApplicationDb(MasterDb(c)) app, _ := NewAppletApplicationDb.GetAppletApplicationListByAppid(req.AppId) if app == nil { e.OutErr(c, 400, e.NewErr(400, "应用不存在")) return } user := GetUser(c) engine := MasterDb(c) data := &model.AppletApplicationAdSpaceList{ Name: req.Name, AppId: req.AppId, Kind: req.Kind, State: 0, MediumId: user.MediumId, CreateAt: time.Now(), UpdateAt: time.Now(), } engine.Insert(data) e.OutSuc(c, "success", nil) return }