package svc import ( "applet/app/db" "applet/app/e" "applet/app/md" "applet/app/utils" "applet/app/utils/cache" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" "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 { NewCloudBundleDb := implement.NewCloudBundleDb(db.Db) os := "1" if c.GetHeader("platform") == "iOS" { os = "2" } data, _ := NewCloudBundleDb.GetCloudBundleVersion(os, c.GetHeader("appversionname"), c.GetHeader("channel")) for _, v := range *NewAdvertisingSpace { var info = make(map[string]interface{}) json.Unmarshal([]byte(v.Info), &info) if data != nil && data.IsAuditing == 1 { //审核版本 if v.Kind == 4 { continue } } 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"), utils.GetIP(c.Request), 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 AdvertisingState(c *gin.Context) { 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 } isSuccess := "0" getString, _ := cache.GetString("advEcpm:" + req.Id) integral := "0" if getString == "" { var data model.AdvertisingCallback db.Db.Where("uniq_id=? ", req.Id).Get(&data) if data.Id > 0 { isSuccess = "1" integral = data.Integral } } else { isSuccess = "1" integral = getString } utils.FilePutContents("AdvertisingState", utils.SerializeStr(map[string]interface{}{ "is_success": isSuccess, "id": req.Id, "ecpm": req.Ecpm, "getString": getString, "time": time.Now().Format("2006-01-02 15:04:05"), })) res := md.AdvertisingState{ IsSuccess: isSuccess, Integral: integral, } if utils.StrToFloat64(req.Ecpm) > 0 { //db.Db.Where("uniq_id=?", req.Id).Cols("custom_ecpm").Update(&model.AdvertisingCallback{CustomEcpm: req.Ecpm}) } 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 }