123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- package userAnalysis
- import (
- "context"
- "github.com/gogf/gf/v2/frame/g"
- "github.com/gogf/gf/v2/util/gconv"
- "strings"
- "time"
- "workTasks/common"
- )
- func (ua *UserAnalysis) GetBackLogsTagsData(ctx context.Context, t time.Time) (fData []*AnalysisRes, err error) {
- // 留资日志
- saleLeadsData, saleLeadsErr := ua.saleLeadsLog(ctx, t.AddDate(0, 0, -7))
- if saleLeadsErr != nil {
- g.Log().Errorf(ctx, "init saleLeadsLog err:%v", saleLeadsErr)
- }
- for _, datum := range saleLeadsData {
- fData = append(fData, datum)
- }
- // 大会员日志
- bigData, bigErr := ua.bigMemberLog(ctx, t.AddDate(0, 0, -1))
- if bigErr != nil {
- g.Log().Errorf(ctx, "init bigErr err:%v", err)
- }
- for _, datum := range bigData {
- fData = append(fData, datum)
- }
- // 大会员日志
- publicData, publicErr := ua.publicLog(ctx, t.AddDate(0, 0, -1))
- if publicErr != nil {
- g.Log().Errorf(ctx, "init publicErr err:%v", err)
- }
- for _, datum := range publicData {
- fData = append(fData, datum)
- }
- return
- }
- // saleLeadsLog 查询是否留资。用于点击留资弹框
- func (ua *UserAnalysis) saleLeadsLog(ctx context.Context, t time.Time) ([]*AnalysisRes, error) {
- clickSaleLeads7Day := map[BaseUserId]bool{}
- sess := common.MG.DB("log").GetMgoConn()
- defer common.MG.DB("log").DestoryMongoConn(sess)
- it := sess.DB("qfw").C("salesLeads_logs").Find(g.Map{"date": g.Map{"$gte": t.Unix()}}).Select(g.Map{"userid": 1, "url": 1}).Iter()
- for m := make(map[string]interface{}); it.Next(&m); {
- var (
- userId = gconv.String(m["userid"])
- url = gconv.String(m["url"])
- )
- if !strings.HasPrefix(url, "/salesLeads/retainedCapital") {
- continue
- }
- baseUserId, ok := ua.UserMapping[userId]
- if ok {
- clickSaleLeads7Day[baseUserId] = true
- }
- }
- return []*AnalysisRes{
- {"近7天点击平台产品留资弹窗>=1次", "click_saleLeads_gte_1_7day", clickSaleLeads7Day, false},
- }, nil
- }
- // bigMemberLog 大会员日志库
- func (ua *UserAnalysis) bigMemberLog(ctx context.Context, t time.Time) ([]*AnalysisRes, error) {
- cacheData := map[string]map[BaseUserId]bool{
- "/bigmember/follow/project/add": map[BaseUserId]bool{},
- "/bigmember/follow/ent/addFollow": map[BaseUserId]bool{},
- }
- sess := common.MG.DB("log").GetMgoConn()
- defer common.MG.DB("log").DestoryMongoConn(sess)
- it := sess.DB("qfw").C("bigmember_logs").Find(g.Map{"date": g.Map{"$gte": t.Unix()}}).Select(g.Map{"userid": 1, "url": 1}).Iter()
- for m := make(map[string]interface{}); it.Next(&m); {
- var (
- userId = gconv.String(m["userid"])
- urlStr = gconv.String(m["url"])
- )
- if baseUserId, ok := ua.UserMapping[userId]; ok {
- for key, _ := range cacheData {
- if strings.HasPrefix(urlStr, key) {
- cacheData[key][baseUserId] = true
- }
- }
- }
- }
- return []*AnalysisRes{
- {"近1天新增监控项目用户", "add_monitor_project_1_day", cacheData["/bigmember/follow/project/add"], false},
- {"近1天新增监控企业用户", "add_monitor_ent_1_day", cacheData["/bigmember/follow/ent/addFollow"], false},
- }, nil
- }
- func (ua *UserAnalysis) publicLog(ctx context.Context, t time.Time) ([]*AnalysisRes, error) {
- cacheData := map[string]map[BaseUserId]bool{
- "/publicapply/customer/attention": map[BaseUserId]bool{},
- "/publicapply/subscribe/setUserInfo": map[BaseUserId]bool{}, //订阅词修改
- }
- sess := common.MG.DB("log").GetMgoConn()
- defer common.MG.DB("log").DestoryMongoConn(sess)
- it := sess.DB("qfw").C("publicapply_logs").Find(g.Map{"date": g.Map{"$gte": t.Unix()}}).Select(g.Map{"userid": 1, "url": 1}).Iter()
- for m := make(map[string]interface{}); it.Next(&m); {
- var (
- userId = gconv.String(m["userid"])
- urlStr = gconv.String(m["url"])
- )
- if baseUserId, ok := ua.UserMapping[userId]; ok {
- for key, _ := range cacheData {
- if strings.HasPrefix(urlStr, key) {
- cacheData[key][baseUserId] = true
- }
- }
- }
- }
- return []*AnalysisRes{
- {"近1天新增监控业主用户", "add_monitor_buyer_1_day", cacheData["/publicapply/customer/attention"], false},
- {"近1天调整订阅词用户", "add_change_subscribe_1_day", cacheData["/publicapply/subscribe/setUserInfo"], false},
- }, nil
- }
|