12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- package main
- import (
- "app.yhyue.com/moapp/jyResourcesCenter/rpc/resourcesCenterclient"
- qu "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/redis"
- "fmt"
- "log"
- "redisResource/config"
- "strings"
- "sync"
- "time"
- )
- var VipFileUploadNumKey = "vip_file_num_*%s"
- const (
- PowerCacheDb = "other"
- PowerCacheFileKey = "free_article_attach_*"
- Date_Short_Layout = "2006-01-02"
- )
- func main() {
- config.Init()
- redisHandle()
- }
- // redis往mysql刷超级订阅剩余数量
- func redisHandle() {
- now := time.Now()
- endTime := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location()).AddDate(0, 1, -1).Format(Date_Short_Layout)
- pool := make(chan bool, config.Config.GivePool)
- wait := &sync.WaitGroup{}
- VipFileUploadNumKey = fmt.Sprintf(VipFileUploadNumKey, fmt.Sprint(now.Month()))
- vipUserList := redis.GetKeysByPattern(PowerCacheDb, VipFileUploadNumKey)
- for _, v1 := range vipUserList {
- pool <- true
- wait.Add(1)
- go func(v interface{}) {
- defer qu.Catch()
- defer func() {
- <-pool
- wait.Done()
- }()
- key := string(v.([]uint8))
- userId := strings.Split(key, "_")[3]
- log.Println(1111, userId)
- numb := redis.GetInt(PowerCacheDb, key)
- if numb > 0 {
- config.Purchase.PurchaseUserBalance(resourcesCenterclient.Resources{
- AppId: "10000",
- UserId: userId,
- ResourceType: "附件下载包",
- AccountId: userId,
- Name: "附件下载包",
- Number: int64(numb),
- Spec: "个",
- EndTime: endTime,
- Model: 3,
- })
- }
- }(v1)
- }
- freeUserList := redis.GetKeysByPattern(PowerCacheDb, PowerCacheFileKey)
- for _, v2 := range freeUserList {
- pool <- true
- wait.Add(1)
- go func(v interface{}) {
- defer qu.Catch()
- defer func() {
- <-pool
- wait.Done()
- }()
- key := string(v.([]uint8))
- userId := strings.Split(key, "_")[3]
- log.Println(2222, userId)
- config.Purchase.PurchaseUserBalance(resourcesCenterclient.Resources{
- AppId: "10000",
- UserId: userId,
- ResourceType: "附件下载包",
- AccountId: userId,
- Name: "附件下载包",
- Number: 1,
- Spec: "个",
- EndTime: endTime,
- Model: 4,
- })
- }(v2)
- }
- wait.Wait()
- }
|