activeUsers.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package activeUsers
  2. import (
  3. "leadGeneration/entity/power"
  4. "leadGeneration/public"
  5. "time"
  6. )
  7. /*
  8. ⚠️注意
  9. user_countbyhour 表只有一个月的数据
  10. */
  11. // GetWeekActiveFreeUsers 获取周活无权限用户
  12. func GetWeekActiveFreeUsers() (rData []string) {
  13. now := time.Now()
  14. _, start_m, start_d := now.Date()
  15. _, end_m, end_d := now.AddDate(0, 0, -7).Date()
  16. var sql string
  17. var param []interface{}
  18. if start_m != end_m {
  19. //跨月
  20. sql = "SELECT DISTINCT(user_mongoid) FROM user_countbyhour WHERE day >= ? OR day < ?"
  21. param = []interface{}{start_d, end_d}
  22. } else {
  23. //非跨月
  24. sql = "SELECT DISTINCT(user_mongoid) FROM user_countbyhour WHERE day >= ? AND day < ?"
  25. param = []interface{}{start_d, end_d}
  26. }
  27. res := public.ActiveMysql.SelectBySql(sql, param...)
  28. if res == nil || len(*res) == 0 {
  29. return
  30. }
  31. rData = make([]string, 0, len(*res))
  32. for _, v := range *res {
  33. if userId, _ := v["user_mongoid"].(string); userId != "" {
  34. if !power.HasPower(userId) {
  35. rData = append(rData, userId)
  36. }
  37. }
  38. }
  39. return rData
  40. }
  41. // GetMonthActiveFreeUsers 获取月活用户
  42. // 有订阅或有搜索词的周活用户+最近7天注册的新用户无条件生
  43. func GetMonthActiveFreeUsers() (rData []string) {
  44. //表数据为近一个月,所以直接查询全部
  45. res := public.ActiveMysql.SelectBySql("SELECT user_mongoid,sum(search) AS total FROM user_countbyhour group by user_mongoid")
  46. if res == nil || len(*res) == 0 {
  47. return
  48. }
  49. rData = make([]string, 0, len(*res))
  50. for _, v := range *res {
  51. userId, _ := v["user_mongoid"].(string)
  52. if userId == "" {
  53. continue
  54. }
  55. //非会员
  56. if hasPower := power.HasPower(userId); hasPower {
  57. continue
  58. }
  59. //无搜索记录、无关键词
  60. if searchTotal, _ := v["total"].(int); searchTotal == 0 {
  61. //无订阅词
  62. if !power.HasSubscribe(userId) {
  63. continue
  64. }
  65. }
  66. rData = append(rData, userId)
  67. }
  68. return rData
  69. }