|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- 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)
-
- list, total, _ := NewMediumDb.FindSuperAdmin(req.Account, req.Name, 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
- }
- 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)
- //TODO::临时处理
- //appletApplicationList, total, _ := NewAppletApplicationDb.FindAppletApplicationAdSpaceList(req.Name, req.Platform, req.CooperateState, utils.StrToInt(req.MediumId), utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
- appletApplicationList, total, _ := NewAppletApplicationDb.FindAppletApplicationAdSpaceList(req.Name, req.Platform, "", 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
- }
|