main.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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/redis"
  6. "fmt"
  7. "log"
  8. "redisResource/config"
  9. "strings"
  10. "sync"
  11. "time"
  12. )
  13. var VipFileUploadNumKey = "vip_file_num_*%s"
  14. const (
  15. PowerCacheDb = "other"
  16. PowerCacheFileKey = "free_article_attach_*"
  17. Date_Short_Layout = "2006-01-02"
  18. )
  19. func main() {
  20. config.Init()
  21. redisHandle()
  22. }
  23. // redis往mysql刷超级订阅剩余数量
  24. func redisHandle() {
  25. now := time.Now()
  26. endTime := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location()).AddDate(0, 1, -1).Format(Date_Short_Layout)
  27. pool := make(chan bool, config.Config.GivePool)
  28. wait := &sync.WaitGroup{}
  29. VipFileUploadNumKey = fmt.Sprintf(VipFileUploadNumKey, fmt.Sprint(now.Month()))
  30. vipUserList := redis.GetKeysByPattern(PowerCacheDb, VipFileUploadNumKey)
  31. for _, v1 := range vipUserList {
  32. pool <- true
  33. wait.Add(1)
  34. go func(v interface{}) {
  35. defer qu.Catch()
  36. defer func() {
  37. <-pool
  38. wait.Done()
  39. }()
  40. key := string(v.([]uint8))
  41. userId := strings.Split(key, "_")[3]
  42. log.Println(1111, userId)
  43. numb := redis.GetInt(PowerCacheDb, key)
  44. if numb > 0 {
  45. config.Purchase.PurchaseUserBalance(resourcesCenterclient.Resources{
  46. AppId: "10000",
  47. UserId: userId,
  48. ResourceType: "附件下载包",
  49. AccountId: userId,
  50. Name: "附件下载包",
  51. Number: int64(numb),
  52. Spec: "个",
  53. EndTime: endTime,
  54. Model: 3,
  55. })
  56. }
  57. }(v1)
  58. }
  59. freeUserList := redis.GetKeysByPattern(PowerCacheDb, PowerCacheFileKey)
  60. for _, v2 := range freeUserList {
  61. pool <- true
  62. wait.Add(1)
  63. go func(v interface{}) {
  64. defer qu.Catch()
  65. defer func() {
  66. <-pool
  67. wait.Done()
  68. }()
  69. key := string(v.([]uint8))
  70. userId := strings.Split(key, "_")[3]
  71. log.Println(2222, userId)
  72. config.Purchase.PurchaseUserBalance(resourcesCenterclient.Resources{
  73. AppId: "10000",
  74. UserId: userId,
  75. ResourceType: "附件下载包",
  76. AccountId: userId,
  77. Name: "附件下载包",
  78. Number: 1,
  79. Spec: "个",
  80. EndTime: endTime,
  81. Model: 4,
  82. })
  83. }(v2)
  84. }
  85. wait.Wait()
  86. }