main.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package main
  2. import (
  3. "app.yhyue.com/moapp/jyResourcesCenter/rpc/resourcesCenterclient"
  4. qu "app.yhyue.com/moapp/jybase/common"
  5. "app.yhyue.com/moapp/jybase/mongodb"
  6. "app.yhyue.com/moapp/jybase/redis"
  7. "fmt"
  8. "github.com/gogf/gf/v2/util/gconv"
  9. "log"
  10. "redisResource/config"
  11. "strings"
  12. "sync"
  13. "time"
  14. )
  15. var VipFileUploadNumKey = "vip_file_num_*%s"
  16. const (
  17. PowerCacheDb = "other"
  18. PowerCacheFileKey = "free_article_attach_*"
  19. Date_Short_Layout = "2006-01-02"
  20. )
  21. func main() {
  22. config.Init()
  23. redisHandle()
  24. }
  25. // redis往mysql刷超级订阅剩余数量
  26. func redisHandle() {
  27. grantDateStr := time.Now().Format("200601")
  28. grantDate := gconv.Int64(grantDateStr)
  29. now := time.Now()
  30. endTime := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location()).AddDate(0, 1, -1).Format(Date_Short_Layout)
  31. pool := make(chan bool, config.Config.GivePool)
  32. wait := &sync.WaitGroup{}
  33. VipFileUploadNumKey = fmt.Sprintf(VipFileUploadNumKey, fmt.Sprint(now.Month()))
  34. vipUserList := redis.GetKeysByPattern(PowerCacheDb, VipFileUploadNumKey)
  35. for _, v1 := range vipUserList {
  36. pool <- true
  37. wait.Add(1)
  38. go func(v interface{}) {
  39. defer qu.Catch()
  40. defer func() {
  41. <-pool
  42. wait.Done()
  43. }()
  44. key := string(v.([]uint8))
  45. userId := strings.Split(key, "_")[3]
  46. numb := redis.GetInt(PowerCacheDb, key)
  47. log.Println(1111, userId, numb)
  48. if numb > 0 {
  49. if mongodb.IsObjectIdHex(userId) {
  50. config.Mgo_qfw.UpdateById("user", userId, map[string]interface{}{
  51. "$set": map[string]interface{}{
  52. "i_grantDate": grantDate,
  53. }})
  54. } else {
  55. //职位信息
  56. //职位id查询entId和entUserId
  57. 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, "", "")
  58. if len(*baseUserList) > 0 {
  59. entId := qu.Int64All((*baseUserList)[0]["ent_id"])
  60. phone := qu.Int64All((*baseUserList)[0]["phone"])
  61. entUser := config.Mysql.FindOne("entniche_user", map[string]interface{}{
  62. "ent_id": entId,
  63. "phone": phone,
  64. }, "", "")
  65. if entUser != nil {
  66. entUserId := qu.Int64All((*entUser)["id"])
  67. config.Mgo_qfw.Update("ent_user", map[string]interface{}{
  68. "entId": entId,
  69. "entUserId": entUserId,
  70. }, map[string]interface{}{
  71. "$set": map[string]interface{}{
  72. "i_grantDate": grantDate,
  73. }}, false, false)
  74. }
  75. }
  76. }
  77. config.Purchase.PurchaseUserBalance(resourcesCenterclient.Resources{
  78. AppId: "10000",
  79. UserId: userId,
  80. ResourceType: "附件下载包",
  81. AccountId: userId,
  82. Name: "附件下载包",
  83. Number: int64(numb),
  84. Spec: "个",
  85. EndTime: endTime,
  86. Model: 3,
  87. })
  88. }
  89. }(v1)
  90. }
  91. freeUserList := redis.GetKeysByPattern(PowerCacheDb, PowerCacheFileKey)
  92. for _, v2 := range freeUserList {
  93. pool <- true
  94. wait.Add(1)
  95. go func(v interface{}) {
  96. defer qu.Catch()
  97. defer func() {
  98. <-pool
  99. wait.Done()
  100. }()
  101. key := string(v.([]uint8))
  102. userId := strings.Split(key, "_")[3]
  103. log.Println(2222, userId)
  104. config.Purchase.PurchaseUserBalance(resourcesCenterclient.Resources{
  105. AppId: "10000",
  106. UserId: userId,
  107. ResourceType: "附件下载包",
  108. AccountId: userId,
  109. Name: "附件下载包",
  110. Number: 1,
  111. Spec: "个",
  112. EndTime: endTime,
  113. Model: 3,
  114. })
  115. }(v2)
  116. }
  117. wait.Wait()
  118. }