Skip to content

Commit

Permalink
随机广告优化
Browse files Browse the repository at this point in the history
  • Loading branch information
TruthHun88 committed Apr 2, 2020
1 parent ca5927d commit 2f7ff80
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions models/ads.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package models

import (
"fmt"
"math/rand"
"sync"
"time"

Expand Down Expand Up @@ -293,13 +294,12 @@ func GetAdsCode(positionIdentify string, isMobile bool) (code string) {
}
}
lenAds := len(ads)
if len(data.([]AdsCont)) != lenAds {
adsCache.Store(pid.(int), ads)
}

if lenAds == 0 {
return
} else if lenAds == 1 {
return ads[0].Code
}
return ads[time.Now().UnixNano()%int64(lenAds)].Code
rand.Seed(time.Now().UnixNano())
return ads[rand.Intn(lenAds)].Code
}

0 comments on commit 2f7ff80

Please sign in to comment.