package svc import ( "applet/app/db" "applet/app/e" "applet/app/md" "applet/app/utils" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "encoding/json" "fmt" "github.com/gin-gonic/gin" "time" ) func Advertising(c *gin.Context) { eg := db.Db var res = md.AdvertisingResp{} NewAdvertisingBasicDb := implement.NewAdvertisingBasicDb(eg) NewAdvertisingBasic, _ := NewAdvertisingBasicDb.GetAdvertisingBasicDb() if NewAdvertisingBasic != nil { var info = make(map[string]interface{}) json.Unmarshal([]byte(NewAdvertisingBasic.Info), &info) res.Basic = md.AdvertisingBasic{ Info: info, AndroidAdIsOpen: utils.IntToStr(NewAdvertisingBasic.AndroidOpenAdIsOpen), IosAdIsOpen: utils.IntToStr(NewAdvertisingBasic.IosAdIsOpen), AndroidOpenAdIsOpen: utils.IntToStr(NewAdvertisingBasic.AndroidOpenAdIsOpen), IosOpenAdIsOpen: utils.IntToStr(NewAdvertisingBasic.IosOpenAdIsOpen), Voice: GetOssUrl(NewAdvertisingBasic.Voice), } } NewAdvertisingLimitDb := implement.NewAdvertisingLimitDb(eg) NewAdvertisingLimit, _ := NewAdvertisingLimitDb.GetAdvertisingLimit() if NewAdvertisingLimit != nil { res.Pop = md.AdvertisingLimit{ PublicImg: GetOssUrl(NewAdvertisingLimit.PublicImg), PublicStr: NewAdvertisingLimit.PublicStr, WithdrawImg: GetOssUrl(NewAdvertisingLimit.WithdrawImg), WithdrawStr: NewAdvertisingLimit.WithdrawStr, } } NewAdvertisingFunctionDb := implement.NewAdvertisingFunctionDb(eg) NewAdvertisingFunction, _ := NewAdvertisingFunctionDb.AdvertisingFunctionAll() AdvertisingFunctionTmp := make([]md.AdvertisingFunction, 0) if NewAdvertisingFunction != nil { for _, v := range *NewAdvertisingFunction { tmp := md.AdvertisingFunction{ Name: v.Name, Type: v.Type, AdId: utils.IntToStr(v.AdId), } AdvertisingFunctionTmp = append(AdvertisingFunctionTmp, tmp) } } res.Function = AdvertisingFunctionTmp NewAdvertisingSpaceDb := implement.NewAdvertisingSpaceDb(eg) NewAdvertisingSpace, _ := NewAdvertisingSpaceDb.AdvertisingSpaceAll() NewAdvertisingSpaceTmp := make([]md.AdvertisingSpace, 0) if NewAdvertisingSpace != nil { for _, v := range *NewAdvertisingSpace { var info = make(map[string]interface{}) json.Unmarshal([]byte(v.Info), &info) tmp := md.AdvertisingSpace{ Id: utils.IntToStr(v.Id), Name: v.Name, Kind: utils.IntToStr(v.Kind), Info: info, CountingDown: utils.IntToStr(v.CountingDown), } NewAdvertisingSpaceTmp = append(NewAdvertisingSpaceTmp, tmp) } } res.Space = NewAdvertisingSpaceTmp e.OutSuc(c, res, nil) return } func AdvertisingCheck(c *gin.Context) { eg := db.Db var req md.AdvertisingReq err := c.ShouldBindJSON(&req) if err != nil { err = HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } user := GetUser(c) var res = md.AdvertisingCheck{IsCanVisit: "0"} NewAdvertisingSpaceDb := implement.NewAdvertisingSpaceDb(eg) NewAdvertisingSpace, _ := NewAdvertisingSpaceDb.GetAdvertisingSpace(req.Id) if NewAdvertisingSpace != nil { if NewAdvertisingSpace.Kind != 3 { res.IsCanVisit = "1" } else { NewAdvertisingLimitDb := implement.NewAdvertisingLimitDb(eg) NewAdvertisingLimit, _ := NewAdvertisingLimitDb.GetAdvertisingLimit() if NewAdvertisingLimit != nil && NewAdvertisingLimit.ImeiNum > 0 { sql := `SELECT uid FROM user_imei WHERE create_at>='%s' and ip='%s' GROUP BY imei LIMIT %s` now := time.Now().Unix() - int64(NewAdvertisingLimit.Minute*60) sql = fmt.Sprintf(sql, time.Unix(now, 0).Format("2006-01-02 15:04:05"), c.ClientIP(), NewAdvertisingLimit.ImeiNum) nativeString, _ := db.QueryNativeString(db.Db, sql) for _, v := range nativeString { if utils.StrToInt64(v["uid"]) == user.Id { res.IsCanVisit = "1" } } if res.IsCanVisit != "1" && len(nativeString) < NewAdvertisingLimit.ImeiNum { UserImeiAdd(c, user.Id) res.IsCanVisit = "1" } } } } e.OutSuc(c, res, nil) return } func AdvertisingDetail(c *gin.Context) { eg := db.Db var req md.AdvertisingReq err := c.ShouldBindJSON(&req) if err != nil { err = HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } var res = md.AdvertisingSpace{} NewAdvertisingSpaceDb := implement.NewAdvertisingSpaceDb(eg) NewAdvertisingSpace, _ := NewAdvertisingSpaceDb.GetAdvertisingSpace(req.Id) if NewAdvertisingSpace != nil { var info = make(map[string]interface{}) json.Unmarshal([]byte(NewAdvertisingSpace.Info), &info) tmp := md.AdvertisingSpace{ Id: utils.IntToStr(NewAdvertisingSpace.Id), Name: NewAdvertisingSpace.Name, Kind: utils.IntToStr(NewAdvertisingSpace.Kind), Info: info, CountingDown: utils.IntToStr(NewAdvertisingSpace.CountingDown), } res = tmp } e.OutSuc(c, res, nil) return }