diff --git a/go.mod b/go.mod index dee6b0d..438df74 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.24 require ( 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/go-redis/redis/v8 v8.11.5 github.com/gogf/gf/contrib/drivers/mysql/v2 v2.2.4 diff --git a/internal/serviceGame/advertisement.go b/internal/serviceGame/advertisement.go index f15bdef..9730d95 100644 --- a/internal/serviceGame/advertisement.go +++ b/internal/serviceGame/advertisement.go @@ -7,6 +7,7 @@ import ( "log" "math" "strconv" + "sync" "tyj_admin/api/v1/game" "tyj_admin/internal/dao" "tyj_admin/internal/model/do" @@ -21,12 +22,14 @@ type IAdvertisement interface { ConversionHugeAmount(ctx context.Context, req *game.CSHAReq) (res *game.CSHARes, 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) + 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) RefreshAccessToken(ctx context.Context, req *game.RefreshAccessTokenReq) (res *game.RefreshAccessTokenRes, err error) RefreshAdvertisementOceanegine(ctx context.Context, req *game.RefreshAdvertisementOceanegineReq) (res *game.RefreshAdvertisementOceanegineRes, err error) } type advertisementImpl struct { + sync.RWMutex } var advertisementService = advertisementImpl{} @@ -83,8 +86,9 @@ func (g *advertisementImpl) AdvertiseHugeAmount1(ctx context.Context, androidId, return } caid := "" + var list []map[string]string if caidList != "" { - var list []map[string]string + //var list []map[string]string _ = json.Unmarshal([]byte(caidList), &list) versionNow := int64(0) 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) lastTouchTime, _ := strconv.ParseInt(timestamp, 10, 64) adDatas := []entity.AdvertisementOceanegine1{} if osInt == 0 { _ = model.Where("adv_android_id=?", androidId).Where("os=?", os).Scan(&adDatas) } else if osInt == 1 { - if caidList != "" { - var list []map[string]string - _ = json.Unmarshal([]byte(caidList), &list) - for _, v := range list { - adDatas1 := []entity.AdvertisementOceanegine1{} - _ = model.Where("caid=?", v["caid"]).Where("os=?", os).Scan(&adDatas1) - if len(adDatas) > 0 { - adDatas = append(adDatas, adDatas1...) - } + for _, v := range list { + _ = model.Where("caid=?", v["caid"]).Where("os=?", os).Scan(&adDatas) + if len(adDatas) > 0 { + 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 { @@ -129,14 +131,16 @@ func (g *advertisementImpl) AdvertiseHugeAmount1(ctx context.Context, androidId, } if adData.LastTouchTime > lastTouchTime { err = errors.New("不是最后一次!") + //g.Unlock() return } _, err = model.WherePri(adData.Id).Update(do.AdvertisementOceanegine1{CallbackParam: callBack, LastTouchTime: timestamp, Caid: caid}) + //g.Unlock() return } - _, err = dao.AdvertisementOceanegine1.Ctx(ctx).Insert(do.AdvertisementOceanegine1{ + _, err = model.Insert(do.AdvertisementOceanegine1{ AdvAndroidId: androidId, Idfa: idfa, Os: os, @@ -145,6 +149,7 @@ func (g *advertisementImpl) AdvertiseHugeAmount1(ctx context.Context, androidId, LastTouchTime: timestamp, Ip: ip, }) + //g.Unlock() return } diff --git a/internal/serviceGame/internal/cdKey.go b/internal/serviceGame/internal/cdKey.go index 8004d03..4f0faff 100644 --- a/internal/serviceGame/internal/cdKey.go +++ b/internal/serviceGame/internal/cdKey.go @@ -10,6 +10,7 @@ import ( "log" "os" "strings" + "sync" "time" "tyj_admin/api/v1/game" "tyj_admin/internal/consts" @@ -141,22 +142,48 @@ func GetGiftExchangeConfig(ctx context.Context, req *game.GetGiftExchangeListReq return } -var fileSize = map[string]*FileSize{} +var fileSize *SMap type FileSize struct { Size int64 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) { res = new(game.GetGiftExchangeRes) var path = gfile.Join(gfile.RealPath("download"), req.File) //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 } 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) return