|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- 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 {
- 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"), 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(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
- }
- res := md.AdvertisingState{
- IsSuccess: isSuccess,
- Integral: integral,
- }
- user := GetUser(c)
- virtualAmountDb := implement.NewUserVirtualAmountDb(db.Db)
- wallets, _ := virtualAmountDb.GetUserVirtualAllWallets(user.Id)
- fmt.Println(utils.SerializeStr(wallets))
- 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
- }
|