Browse Source

adv, cdkey, mod

master
linquan 1 month ago
parent
commit
9fa7e849ec
  1. 1
      go.mod
  2. 35
      internal/serviceGame/advertisement.go
  3. 33
      internal/serviceGame/internal/cdKey.go

1
go.mod

@ -4,6 +4,7 @@ go 1.24
require ( require (
github.com/casbin/casbin/v2 v2.42.0 github.com/casbin/casbin/v2 v2.42.0
github.com/cristalhq/jwt/v3 v3.1.0
github.com/eclipse/paho.mqtt.golang v1.4.2 github.com/eclipse/paho.mqtt.golang v1.4.2
github.com/go-redis/redis/v8 v8.11.5 github.com/go-redis/redis/v8 v8.11.5
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.2.4 github.com/gogf/gf/contrib/drivers/mysql/v2 v2.2.4

35
internal/serviceGame/advertisement.go

@ -7,6 +7,7 @@ import (
"log" "log"
"math" "math"
"strconv" "strconv"
"sync"
"tyj_admin/api/v1/game" "tyj_admin/api/v1/game"
"tyj_admin/internal/dao" "tyj_admin/internal/dao"
"tyj_admin/internal/model/do" "tyj_admin/internal/model/do"
@ -21,12 +22,14 @@ type IAdvertisement interface {
ConversionHugeAmount(ctx context.Context, req *game.CSHAReq) (res *game.CSHARes, err error) ConversionHugeAmount(ctx context.Context, req *game.CSHAReq) (res *game.CSHARes, err error)
AdvertiseHugeAmount(ctx context.Context, req *game.AdvertiseHAReq) (res *game.AdvertiseHARes, err error) AdvertiseHugeAmount(ctx context.Context, req *game.AdvertiseHAReq) (res *game.AdvertiseHARes, err error)
AdvertiseHugeAmount1(ctx context.Context, androidId, idfa, os, callBack, timestamp, caid, ip string) (err error) AdvertiseHugeAmount1(ctx context.Context, androidId, idfa, os, callBack, timestamp, caid, ip string) (err error)
AdvertiseHugeAmountReadOnly(ctx context.Context, osInt int, list []map[string]string, caid, androidId, idfa, os, callBack, timestamp, ip string) (err error)
GetAccessToken(ctx context.Context, req *game.GetAccessTokenReq) (res *game.GetAccessTokenRes, err error) GetAccessToken(ctx context.Context, req *game.GetAccessTokenReq) (res *game.GetAccessTokenRes, err error)
RefreshAccessToken(ctx context.Context, req *game.RefreshAccessTokenReq) (res *game.RefreshAccessTokenRes, err error) RefreshAccessToken(ctx context.Context, req *game.RefreshAccessTokenReq) (res *game.RefreshAccessTokenRes, err error)
RefreshAdvertisementOceanegine(ctx context.Context, req *game.RefreshAdvertisementOceanegineReq) (res *game.RefreshAdvertisementOceanegineRes, err error) RefreshAdvertisementOceanegine(ctx context.Context, req *game.RefreshAdvertisementOceanegineReq) (res *game.RefreshAdvertisementOceanegineRes, err error)
} }
type advertisementImpl struct { type advertisementImpl struct {
sync.RWMutex
} }
var advertisementService = advertisementImpl{} var advertisementService = advertisementImpl{}
@ -83,8 +86,9 @@ func (g *advertisementImpl) AdvertiseHugeAmount1(ctx context.Context, androidId,
return return
} }
caid := "" caid := ""
if caidList != "" {
var list []map[string]string var list []map[string]string
if caidList != "" {
//var list []map[string]string
_ = json.Unmarshal([]byte(caidList), &list) _ = json.Unmarshal([]byte(caidList), &list)
versionNow := int64(0) versionNow := int64(0)
for _, v := range list { for _, v := range list {
@ -95,29 +99,27 @@ func (g *advertisementImpl) AdvertiseHugeAmount1(ctx context.Context, androidId,
} }
} }
} }
err = g.AdvertiseHugeAmountReadOnly(ctx, osInt, list, caid, androidId, idfa, os, callBack, timestamp, ip)
return
}
func (g *advertisementImpl) AdvertiseHugeAmountReadOnly(ctx context.Context, osInt int, list []map[string]string, caid, androidId, idfa, os, callBack, timestamp, ip string) (err error) {
//g.Lock()
model := dao.AdvertisementOceanegine1.Ctx(ctx) model := dao.AdvertisementOceanegine1.Ctx(ctx)
lastTouchTime, _ := strconv.ParseInt(timestamp, 10, 64) lastTouchTime, _ := strconv.ParseInt(timestamp, 10, 64)
adDatas := []entity.AdvertisementOceanegine1{} adDatas := []entity.AdvertisementOceanegine1{}
if osInt == 0 { if osInt == 0 {
_ = model.Where("adv_android_id=?", androidId).Where("os=?", os).Scan(&adDatas) _ = model.Where("adv_android_id=?", androidId).Where("os=?", os).Scan(&adDatas)
} else if osInt == 1 { } else if osInt == 1 {
if caidList != "" {
var list []map[string]string
_ = json.Unmarshal([]byte(caidList), &list)
for _, v := range list { for _, v := range list {
adDatas1 := []entity.AdvertisementOceanegine1{} _ = model.Where("caid=?", v["caid"]).Where("os=?", os).Scan(&adDatas)
_ = model.Where("caid=?", v["caid"]).Where("os=?", os).Scan(&adDatas1)
if len(adDatas) > 0 { if len(adDatas) > 0 {
adDatas = append(adDatas, adDatas1...) break
}
}
} }
if idfa != "" {
adDatas1 := []entity.AdvertisementOceanegine1{}
_ = model.Where("idfa=?", idfa).Where("os=?", os).Scan(&adDatas1)
if len(adDatas1) > 0 {
adDatas = append(adDatas, adDatas1...)
} }
if idfa != "" && len(adDatas) == 0 {
_ = model.Where("idfa=?", idfa).Where("os=?", os).Scan(&adDatas)
} }
} }
if len(adDatas) > 0 { if len(adDatas) > 0 {
@ -129,14 +131,16 @@ func (g *advertisementImpl) AdvertiseHugeAmount1(ctx context.Context, androidId,
} }
if adData.LastTouchTime > lastTouchTime { if adData.LastTouchTime > lastTouchTime {
err = errors.New("不是最后一次!") err = errors.New("不是最后一次!")
//g.Unlock()
return return
} }
_, err = model.WherePri(adData.Id).Update(do.AdvertisementOceanegine1{CallbackParam: callBack, LastTouchTime: timestamp, Caid: caid}) _, err = model.WherePri(adData.Id).Update(do.AdvertisementOceanegine1{CallbackParam: callBack, LastTouchTime: timestamp, Caid: caid})
//g.Unlock()
return return
} }
_, err = dao.AdvertisementOceanegine1.Ctx(ctx).Insert(do.AdvertisementOceanegine1{ _, err = model.Insert(do.AdvertisementOceanegine1{
AdvAndroidId: androidId, AdvAndroidId: androidId,
Idfa: idfa, Idfa: idfa,
Os: os, Os: os,
@ -145,6 +149,7 @@ func (g *advertisementImpl) AdvertiseHugeAmount1(ctx context.Context, androidId,
LastTouchTime: timestamp, LastTouchTime: timestamp,
Ip: ip, Ip: ip,
}) })
//g.Unlock()
return return
} }

33
internal/serviceGame/internal/cdKey.go

@ -10,6 +10,7 @@ import (
"log" "log"
"os" "os"
"strings" "strings"
"sync"
"time" "time"
"tyj_admin/api/v1/game" "tyj_admin/api/v1/game"
"tyj_admin/internal/consts" "tyj_admin/internal/consts"
@ -141,22 +142,48 @@ func GetGiftExchangeConfig(ctx context.Context, req *game.GetGiftExchangeListReq
return return
} }
var fileSize = map[string]*FileSize{} var fileSize *SMap
type FileSize struct { type FileSize struct {
Size int64 Size int64
Times int Times int
} }
type SMap struct {
sync.RWMutex
Map map[string]*FileSize
}
func (l *SMap) readMap(key string) (*FileSize, bool) {
l.RLock()
value, ok := l.Map[key]
l.RUnlock()
return value, ok
}
func (l *SMap) writeMap(key string, value *FileSize) {
l.Lock()
l.Map[key] = value
l.Unlock()
}
func init() {
fileSize = &SMap{
Map: make(map[string]*FileSize),
}
}
func GetGiftExchange(ctx context.Context, req *game.GetGiftExchangeReq) (res *game.GetGiftExchangeRes, err error) { func GetGiftExchange(ctx context.Context, req *game.GetGiftExchangeReq) (res *game.GetGiftExchangeRes, err error) {
res = new(game.GetGiftExchangeRes) res = new(game.GetGiftExchangeRes)
var path = gfile.Join(gfile.RealPath("download"), req.File) var path = gfile.Join(gfile.RealPath("download"), req.File)
//log.Println("GetGiftExchange: ", req.File, path, gfile.Exists(path)) //log.Println("GetGiftExchange: ", req.File, path, gfile.Exists(path))
if gfile.Exists(path) && gfile.Size(path) != 0 && fileSize[path] != nil && gfile.Size(path) == fileSize[path].Size { file_size, ok := fileSize.readMap(path)
gfileSize := gfile.Size(path)
if gfile.Exists(path) && gfileSize != 0 && ok && gfileSize == file_size.Size {
res.State = 1 res.State = 1
} }
err = g.Try(ctx, func(ctx context.Context) { err = g.Try(ctx, func(ctx context.Context) {
fileSize[path] = &FileSize{Size: gfile.Size(path), Times: 0} fileSize.writeMap(path, &FileSize{Size: gfile.Size(path), Times: 0})
}) })
log.Println("GetGiftExchange err: ", err) log.Println("GetGiftExchange err: ", err)
return return

Loading…
Cancel
Save