backLogs.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package userAnalysis
  2. import (
  3. "context"
  4. "github.com/gogf/gf/v2/frame/g"
  5. "github.com/gogf/gf/v2/util/gconv"
  6. "strings"
  7. "time"
  8. "workTasks/common"
  9. )
  10. func (ua *UserAnalysis) GetBackLogsTagsData(ctx context.Context, t time.Time) (fData []*AnalysisRes, err error) {
  11. // 留资日志
  12. saleLeadsData, saleLeadsErr := ua.saleLeadsLog(ctx, t.AddDate(0, 0, -7))
  13. if saleLeadsErr != nil {
  14. g.Log().Errorf(ctx, "init saleLeadsLog err:%v", saleLeadsErr)
  15. }
  16. for _, datum := range saleLeadsData {
  17. fData = append(fData, datum)
  18. }
  19. // 大会员日志
  20. bigData, bigErr := ua.bigMemberLog(ctx, t.AddDate(0, 0, -1))
  21. if bigErr != nil {
  22. g.Log().Errorf(ctx, "init bigErr err:%v", err)
  23. }
  24. for _, datum := range bigData {
  25. fData = append(fData, datum)
  26. }
  27. // 大会员日志
  28. publicData, publicErr := ua.publicLog(ctx, t.AddDate(0, 0, -1))
  29. if publicErr != nil {
  30. g.Log().Errorf(ctx, "init publicErr err:%v", err)
  31. }
  32. for _, datum := range publicData {
  33. fData = append(fData, datum)
  34. }
  35. return
  36. }
  37. // saleLeadsLog 查询是否留资。用于点击留资弹框
  38. func (ua *UserAnalysis) saleLeadsLog(ctx context.Context, t time.Time) ([]*AnalysisRes, error) {
  39. clickSaleLeads7Day := map[BaseUserId]bool{}
  40. sess := common.MG.DB("log").GetMgoConn()
  41. defer common.MG.DB("log").DestoryMongoConn(sess)
  42. it := sess.DB("qfw").C("salesLeads_logs").Find(g.Map{"date": g.Map{"$gte": t.Unix()}}).Select(g.Map{"userid": 1, "url": 1}).Iter()
  43. for m := make(map[string]interface{}); it.Next(&m); {
  44. var (
  45. userId = gconv.String(m["userid"])
  46. url = gconv.String(m["url"])
  47. )
  48. if !strings.HasPrefix(url, "/salesLeads/retainedCapital") {
  49. continue
  50. }
  51. baseUserId, ok := ua.UserMapping[userId]
  52. if ok {
  53. clickSaleLeads7Day[baseUserId] = true
  54. }
  55. }
  56. return []*AnalysisRes{
  57. {"近7天点击平台产品留资弹窗>=1次", "click_saleLeads_gte_1_7day", clickSaleLeads7Day, false},
  58. }, nil
  59. }
  60. // bigMemberLog 大会员日志库
  61. func (ua *UserAnalysis) bigMemberLog(ctx context.Context, t time.Time) ([]*AnalysisRes, error) {
  62. cacheData := map[string]map[BaseUserId]bool{
  63. "/bigmember/follow/project/add": map[BaseUserId]bool{},
  64. "/bigmember/follow/ent/addFollow": map[BaseUserId]bool{},
  65. }
  66. sess := common.MG.DB("log").GetMgoConn()
  67. defer common.MG.DB("log").DestoryMongoConn(sess)
  68. it := sess.DB("qfw").C("bigmember_logs").Find(g.Map{"date": g.Map{"$gte": t.Unix()}}).Select(g.Map{"userid": 1, "url": 1}).Iter()
  69. for m := make(map[string]interface{}); it.Next(&m); {
  70. var (
  71. userId = gconv.String(m["userid"])
  72. urlStr = gconv.String(m["url"])
  73. )
  74. if baseUserId, ok := ua.UserMapping[userId]; ok {
  75. for key, _ := range cacheData {
  76. if strings.HasPrefix(urlStr, key) {
  77. cacheData[key][baseUserId] = true
  78. }
  79. }
  80. }
  81. }
  82. return []*AnalysisRes{
  83. {"近1天新增监控项目用户", "add_monitor_project_1_day", cacheData["/bigmember/follow/project/add"], false},
  84. {"近1天新增监控企业用户", "add_monitor_ent_1_day", cacheData["/bigmember/follow/ent/addFollow"], false},
  85. }, nil
  86. }
  87. func (ua *UserAnalysis) publicLog(ctx context.Context, t time.Time) ([]*AnalysisRes, error) {
  88. cacheData := map[string]map[BaseUserId]bool{
  89. "/publicapply/customer/attention": map[BaseUserId]bool{},
  90. "/publicapply/subscribe/setUserInfo": map[BaseUserId]bool{}, //订阅词修改
  91. }
  92. sess := common.MG.DB("log").GetMgoConn()
  93. defer common.MG.DB("log").DestoryMongoConn(sess)
  94. it := sess.DB("qfw").C("publicapply_logs").Find(g.Map{"date": g.Map{"$gte": t.Unix()}}).Select(g.Map{"userid": 1, "url": 1}).Iter()
  95. for m := make(map[string]interface{}); it.Next(&m); {
  96. var (
  97. userId = gconv.String(m["userid"])
  98. urlStr = gconv.String(m["url"])
  99. )
  100. if baseUserId, ok := ua.UserMapping[userId]; ok {
  101. for key, _ := range cacheData {
  102. if strings.HasPrefix(urlStr, key) {
  103. cacheData[key][baseUserId] = true
  104. }
  105. }
  106. }
  107. }
  108. return []*AnalysisRes{
  109. {"近1天新增监控业主用户", "add_monitor_buyer_1_day", cacheData["/publicapply/customer/attention"], false},
  110. {"近1天调整订阅词用户", "add_change_subscribe_1_day", cacheData["/publicapply/subscribe/setUserInfo"], false},
  111. }, nil
  112. }