package advertising import ( "applet/app/db" "applet/app/e" "applet/app/md" "applet/app/utils" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" "github.com/gin-gonic/gin" ) func List(c *gin.Context) { var req *md.AdvertisingListReq if err := c.ShouldBindJSON(&req); err != nil { e.OutErr(c, e.ERR_INVALID_ARGS, err) return } var resp md.AdvertisingListResp noticeList := make([]md.AdvertisingList, 0) resp.AdvData = []map[string]string{ {"name": "开屏广告", "value": "1"}, {"name": "插屏广告", "value": "2"}, {"name": "激励视频", "value": "3"}, {"name": "信息流广告", "value": "4"}, {"name": "全屏视频", "value": "5"}, } resp.SelectData = md.AdvertisingPlatform NewJpushNoticeDb := implement.NewAdvertisingSpaceDb(db.Db) notice, total, _ := NewJpushNoticeDb.FindUserFeedbackCateAndTotal(req.Page, req.Limit, req.Name, req.Kind) resp.Total = total if notice != nil { for _, v := range *notice { tmp := md.AdvertisingList{ Id: utils.IntToStr(v.Id), CountingDown: utils.IntToStr(v.CountingDown), Kind: utils.IntToStr(v.Kind), Info: v.Info, Name: v.Name, } noticeList = append(noticeList, tmp) } } resp.List = noticeList e.OutSuc(c, resp, nil) return } func VisitList(c *gin.Context) { var req *md.AdvertisingVisitListReq if err := c.ShouldBindJSON(&req); err != nil { e.OutErr(c, e.ERR_INVALID_ARGS, err) return } var resp md.AdvertisingVisitListResp noticeList := make([]md.AdvertisingVisitList, 0) resp.TypeData = md.AdvertisingType resp.PlatformData = md.AdvertisingPlatform uid := req.Uid if req.Phone != "" { userDb := implement.NewUserDb(db.Db) user, err := userDb.UserGetOneByParams(map[string]interface{}{ "key": "phone", "value": req.Phone, }) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } uid = utils.Int64ToStr(user.Id) } NewAdvertisingCallbackDb := implement.NewAdvertisingCallbackDb(db.Db) notice, total, _ := NewAdvertisingCallbackDb.FindAdvertisingCallbackAndTotal(req.Page, req.Limit, req.Amount, uid, req.StartTime, req.EndTime, req.Platform, req.Type) resp.Total = total if notice != nil { for _, v := range *notice { userDb := implement.NewUserDb(db.Db) users, _ := userDb.UserGetOneByParams(map[string]interface{}{ "key": "id", "value": v.Uid, }) phone := "" if users != nil { phone = users.Phone } tmp := md.AdvertisingVisitList{ Id: utils.IntToStr(v.Id), Uid: utils.IntToStr(v.Uid), Phone: phone, Ecpm: v.Amount, Integral: v.Integral, Platform: v.Platform, PhonePlatform: v.PhonePlatform, Type: v.Type, Time: v.CreateAt.Format("2006-01-02 15:04:05"), } noticeList = append(noticeList, tmp) } } resp.List = noticeList e.OutSuc(c, resp, nil) return } func Del(c *gin.Context) { var req *md.ArticleCateDelReq if err := c.ShouldBindJSON(&req); err != nil { e.OutErr(c, e.ERR_INVALID_ARGS, err) return } db.Db.In("id", req.Id).Delete(&model.AdvertisingSpace{}) e.OutSuc(c, "success", nil) return } func Save(c *gin.Context) { var req *md.AdvertisingSaveReq if err := c.ShouldBindJSON(&req); err != nil { e.OutErr(c, e.ERR_INVALID_ARGS, err) return } var data = new(model.AdvertisingSpace) if utils.StrToInt(req.Id) > 0 { NewAdvertisingSpaceDb := implement.NewAdvertisingSpaceDb(db.Db) space, _ := NewAdvertisingSpaceDb.GetAdvertisingSpace(req.Id) if space == nil { e.OutErr(c, 400, e.NewErr(400, "记录不存在")) return } data = space } else { db.Db.Insert(data) } data.Name = req.Name data.Info = req.Info data.Kind = utils.StrToInt(req.Kind) data.CountingDown = utils.StrToInt(req.CountingDown) db.Db.Where("id=?", data.Id).Update(data) e.OutSuc(c, "success", nil) return }