package main import ( "app.yhyue.com/moapp/jyResourcesCenter/rpc/resourcesCenterclient" qu "app.yhyue.com/moapp/jybase/common" "app.yhyue.com/moapp/jybase/mongodb" "app.yhyue.com/moapp/jybase/redis" "fmt" "github.com/gogf/gf/v2/util/gconv" "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() { grantDateStr := time.Now().Format("200601") grantDate := gconv.Int64(grantDateStr) 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] numb := redis.GetInt(PowerCacheDb, key) log.Println(1111, userId, numb) if numb > 0 { if mongodb.IsObjectIdHex(userId) { config.Mgo_qfw.UpdateById("user", userId, map[string]interface{}{ "$set": map[string]interface{}{ "i_grantDate": grantDate, }}) } else { //职位信息 //职位id查询entId和entUserId baseUserList := config.Tidb.SelectBySql("select b.phone,a.ent_id from base_position a INNER JOIN base_user b on a.user_id=b.id where a.id= ?", userId, "", "") if len(*baseUserList) > 0 { entId := qu.Int64All((*baseUserList)[0]["ent_id"]) phone := qu.Int64All((*baseUserList)[0]["phone"]) entUser := config.Mysql.FindOne("entniche_user", map[string]interface{}{ "ent_id": entId, "phone": phone, }, "", "") if entUser != nil { entUserId := qu.Int64All((*entUser)["id"]) config.Mgo_qfw.Update("ent_user", map[string]interface{}{ "entId": entId, "entUserId": entUserId, }, map[string]interface{}{ "$set": map[string]interface{}{ "i_grantDate": grantDate, }}, false, false) } } } 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: 3, }) }(v2) } wait.Wait() }