main.go 2.1 KB

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