Procházet zdrojové kódy

wip:新增新注册用户标签

wkyuer před 7 měsíci
rodič
revize
f803293e26

+ 5 - 2
userSign/main.go

@@ -15,11 +15,11 @@ import (
 
 func main() {
 	ctx := gctx.New()
-	runOnce(context.TODO())
+	//runOnce(context.TODO())
 	//if e := userTag.BaseUserTag(); e != nil {
 	//	g.Log().Errorf(ctx, "BaseUserTag 异常", e)
 	//}
-	return
+
 	_, err := gcron.Add(gctx.New(), g.Cfg().MustGet(ctx, "runCron", "# 0 2 * * *").String(), func(ctx context.Context) {
 		runOnce(context.TODO())
 		if e := userTag.BaseUserTag(); e != nil {
@@ -48,6 +48,9 @@ func runOnce(ctx context.Context) {
 		allRes = append(allRes, res...)
 	}
 
+	//加载30天内取关用户
+	manager.GetMgoUnSubUser(ctx, -30)
+
 	//会员状态分析
 	if res, err := manager.GetMgoUserRes(ctx); err == nil && len(res) > 0 {
 		allRes = append(allRes, res...)

+ 11 - 0
userSign/new.sql

@@ -17,3 +17,14 @@ INSERT INTO pub_tags.dwd_d_tag (id, code, name, bitobj, groupid, created_at, cre
 INSERT INTO pub_tags.dwd_d_tag (id, code, name, bitobj, groupid, created_at, created_by, bit_num) VALUES(2012, 'active_app', '30天app活跃用户',bitmapBuild([toUInt64(0)]) , 2, '2024-10-21 00:00:00', 'wky', 2012);
 INSERT INTO pub_tags.dwd_d_tag (id, code, name, bitobj, groupid, created_at, created_by, bit_num) VALUES(2013, 'unActive_30', '30天未活跃用户',bitmapBuild([toUInt64(0)]) , 2, '2024-10-21 00:00:00', 'wky', 2013);
 INSERT INTO pub_tags.dwd_d_tag (id, code, name, bitobj, groupid, created_at, created_by, bit_num) VALUES(2014, 'unActive_90', '90天未活跃用户',bitmapBuild([toUInt64(0)]) , 2, '2024-10-21 00:00:00', 'wky', 2014);
+
+
+
+
+INSERT INTO pub_tags.dwd_d_tag (id, code, name, bitobj, groupid, created_at, created_by, bit_num) VALUES(2018, 'newUser_1', '近第1天注册用户',bitmapBuild([toUInt64(0)]) , 2, '2024-12-17 00:00:00', 'wky', 2018);
+INSERT INTO pub_tags.dwd_d_tag (id, code, name, bitobj, groupid, created_at, created_by, bit_num) VALUES(2019, 'newUser_2', '近第2天注册用户',bitmapBuild([toUInt64(0)]) , 2, '2024-12-17 00:00:00', 'wky', 2019);
+INSERT INTO pub_tags.dwd_d_tag (id, code, name, bitobj, groupid, created_at, created_by, bit_num) VALUES(2020, 'newUser_3', '近第3天注册用户',bitmapBuild([toUInt64(0)]) , 2, '2024-12-17 00:00:00', 'wky', 2020);
+INSERT INTO pub_tags.dwd_d_tag (id, code, name, bitobj, groupid, created_at, created_by, bit_num) VALUES(2021, 'newUser_4', '近第4天注册用户',bitmapBuild([toUInt64(0)]) , 2, '2024-12-17 00:00:00', 'wky', 2021);
+INSERT INTO pub_tags.dwd_d_tag (id, code, name, bitobj, groupid, created_at, created_by, bit_num) VALUES(2022, 'newUser_5', '近第5天注册用户',bitmapBuild([toUInt64(0)]) , 2, '2024-12-17 00:00:00', 'wky', 2022);
+INSERT INTO pub_tags.dwd_d_tag (id, code, name, bitobj, groupid, created_at, created_by, bit_num) VALUES(2023, 'newUser_6', '近第6天注册用户',bitmapBuild([toUInt64(0)]) , 2, '2024-12-17 00:00:00', 'wky', 2023);
+INSERT INTO pub_tags.dwd_d_tag (id, code, name, bitobj, groupid, created_at, created_by, bit_num) VALUES(2024, 'newUser_7', '近第7天注册用户',bitmapBuild([toUInt64(0)]) , 2, '2024-12-17 00:00:00', 'wky', 2024);

+ 23 - 10
userSign/userAnalysis/analysisManager.go

@@ -18,6 +18,9 @@ type (
 		Vip, Vip15, Vip30    map[BaseUserId]bool
 		Member, MemberExpire map[BaseUserId]bool
 
+		UnSubUser map[string]bool             //取关
+		NewUser   map[int]map[BaseUserId]bool //新用户
+
 		TestUser map[BaseUserId]bool
 	}
 	BaseUserId int64
@@ -53,19 +56,27 @@ func (ar *AnalysisRes) UpdateTag(ctx context.Context) {
 		}
 	}
 
-	for i, batch := range updateBatch {
-		if i == 0 {
-			execSql := fmt.Sprintf(`ALTER TABLE dwd_d_tag UPDATE bitobj = bitmapBuild([%v]) WHERE code = '%v';`, strings.Join(batch, ","), ar.Code)
-			if _, err := g.DB().Exec(ctx, execSql); err != nil {
-				g.Log().Errorf(ctx, "更新标签%s [%d]异常 %v", ar.Code, i, err)
-			}
-		} else {
-			execSql := fmt.Sprintf(`ALTER TABLE dwd_d_tag UPDATE bitobj = bitmapOr(bitobj,bitmapBuild([%v])) WHERE code = '%v';`, strings.Join(batch, ","), ar.Code)
-			if _, err := g.DB().Exec(ctx, execSql); err != nil {
-				g.Log().Errorf(ctx, "更新标签%s [%d]异常 %v", ar.Code, i, err)
+	if len(updateBatch) == 0 {
+		execSql := fmt.Sprintf(`ALTER TABLE dwd_d_tag UPDATE bitobj = bitmapBuild([toUInt64(0)]) WHERE code = '%v';`, ar.Code)
+		if _, err := g.DB().Exec(ctx, execSql); err != nil {
+			g.Log().Errorf(ctx, "更新标签%s 滞空异常 %v", ar.Code, err)
+		}
+	} else {
+		for i, batch := range updateBatch {
+			if i == 0 {
+				execSql := fmt.Sprintf(`ALTER TABLE dwd_d_tag UPDATE bitobj = bitmapBuild([%v]) WHERE code = '%v';`, strings.Join(batch, ","), ar.Code)
+				if _, err := g.DB().Exec(ctx, execSql); err != nil {
+					g.Log().Errorf(ctx, "更新标签%s [%d]异常 %v", ar.Code, i, err)
+				}
+			} else {
+				execSql := fmt.Sprintf(`ALTER TABLE dwd_d_tag UPDATE bitobj = bitmapOr(bitobj,bitmapBuild([%v])) WHERE code = '%v';`, strings.Join(batch, ","), ar.Code)
+				if _, err := g.DB().Exec(ctx, execSql); err != nil {
+					g.Log().Errorf(ctx, "更新标签%s [%d]异常 %v", ar.Code, i, err)
+				}
 			}
 		}
 	}
+
 	g.Log().Infof(ctx, "UpdateTag code %s 更新%d个完成", ar.Code, len(ar.Data))
 }
 
@@ -82,6 +93,8 @@ func NewManager() *UserAnalysis {
 		Member:           map[BaseUserId]bool{},
 		MemberExpire:     map[BaseUserId]bool{},
 		TestUser:         map[BaseUserId]bool{},
+		UnSubUser:        map[string]bool{},
+		NewUser:          map[int]map[BaseUserId]bool{},
 	}
 }
 

+ 62 - 14
userSign/userAnalysis/jobMgoUserRange.go

@@ -13,26 +13,36 @@ import (
 func (ua *UserAnalysis) GetMgoUserRes(ctx context.Context) ([]*AnalysisRes, error) {
 	ua.mgoUserRange(ctx)
 	ua.mgoEntUserRange(ctx)
-	return []*AnalysisRes{
-			{Name: "已绑定手机号用户", Code: "binPhone", Data: ua.BinPhone},
-			{Name: "已绑定邮箱用户", Code: "bindMail", Data: ua.BindMail},
-			{Name: "超级订阅用户", Code: "vip", Data: ua.Vip},
-			{Name: "超级订阅15天到期", Code: "vipExpire_15", Data: ua.Vip15},
-			{Name: "超级订阅30天到期", Code: "vipExpire_30", Data: ua.Vip30},
-			{Name: "大会员用户", Code: "member", Data: ua.Member},
-			{Name: "测试用户", Code: "testGroup", Data: ua.TestUser},
-			{Name: "曾购大会员用户", Code: "memberExpired", Data: ua.MemberExpire}},
-		nil
+	rData := []*AnalysisRes{
+		{Name: "已绑定手机号用户", Code: "binPhone", Data: ua.BinPhone},
+		{Name: "已绑定邮箱用户", Code: "bindMail", Data: ua.BindMail},
+		{Name: "超级订阅用户", Code: "vip", Data: ua.Vip},
+		{Name: "超级订阅15天到期", Code: "vipExpire_15", Data: ua.Vip15},
+		{Name: "超级订阅30天到期", Code: "vipExpire_30", Data: ua.Vip30},
+		{Name: "大会员用户", Code: "member", Data: ua.Member},
+		{Name: "测试用户", Code: "testGroup", Data: ua.TestUser},
+		{Name: "曾购大会员用户", Code: "memberExpired", Data: ua.MemberExpire}}
+
+	for i := 1; i <= 7; i++ {
+		rData = append(rData, &AnalysisRes{
+			Name: fmt.Sprintf("近第%d天注册用户", i),
+			Code: fmt.Sprintf("newUser_%d", i),
+			Data: ua.NewUser[i],
+		})
+		g.Dump(fmt.Sprintf("近第%d天注册用户", i), ua.NewUser[i])
+	}
+	return rData, nil
 }
 
 func (ua *UserAnalysis) mgoUserRange(ctx context.Context) {
 	sess := common.MG.DB().GetMgoConn()
 	defer common.MG.DB().DestoryMongoConn(sess)
 	//个人身份
-	it := sess.DB("qfw").C("user").Find(nil).Select(g.Map{"base_user_id": 1, "s_phone": 1, "s_m_phone": 1, "s_email": 1, "l_registedate": 1, "i_vip_status": 1, "l_vip_endtime": 1, "i_member_status": 1}).Iter()
+	it := sess.DB("qfw").C("user").Find(nil).Select(g.Map{"base_user_id": 1, "s_phone": 1, "s_m_phone": 1, "s_email": 1, "l_registedate": 1, "i_vip_status": 1, "l_vip_endtime": 1, "i_member_status": 1, "s_m_openid": 1, "i_ispush": 1}).Iter()
 	var (
-		index int64
-		now   = time.Now()
+		index        int64
+		now          = time.Now()
+		newUserLimit = now.AddDate(0, 0, -8).Unix()
 	)
 	for m := make(map[string]interface{}); it.Next(&m); {
 		index++
@@ -44,12 +54,31 @@ func (ua *UserAnalysis) mgoUserRange(ctx context.Context) {
 			s_phone      = gconv.String(m["s_phone"])
 			s_m_phone    = gconv.String(m["s_m_phone"])
 			s_email      = gconv.String(m["s_email"])
-			//registedate  = time.Unix(gconv.Int64(m["l_registedate"]), 0)
+			registedate  = gconv.Int64(m["l_registedate"])
+			openid       = gconv.String(m["s_m_openid"])
+			isSub        = gconv.Int(m["i_ispush"])
 		)
+		if base_user_id == 0 {
+			continue
+		}
 		//绑定手机号用户
 		if len(s_phone) == 11 || len(s_m_phone) == 11 {
 			ua.BinPhone[base_user_id] = true
 		}
+		//近8天注册用户
+		if registedate > newUserLimit {
+			//过滤取关
+			if (openid != "" && isSub == 1 && !ua.UnSubUser[openid]) || openid == "" {
+				//if !ua.UnSubUser[openid] {
+				day := 8 - gconv.Int((registedate-newUserLimit)/(60*60*24))
+				if _, ok := ua.NewUser[day]; ok {
+					ua.NewUser[day][base_user_id] = true
+				} else {
+					ua.NewUser[day] = map[BaseUserId]bool{base_user_id: true}
+				}
+			}
+		}
+
 		for _, p := range g.Cfg().MustGet(ctx, "testUserPhone").Strings() {
 			if (p == s_phone || p == s_m_phone) && p != "" {
 				fmt.Println(p, base_user_id)
@@ -131,3 +160,22 @@ func (ua *UserAnalysis) mgoEntUserRange(ctx context.Context) {
 	}
 	g.Log().Infof(ctx, "MgoUserRange 加载%d挑数据完成", index)
 }
+
+// GetMgoUnSubUser 加载num天 取关的用户
+func (ua *UserAnalysis) GetMgoUnSubUser(ctx context.Context, num int) {
+	sess := common.MG.DB().GetMgoConn()
+	defer common.MG.DB().DestoryMongoConn(sess)
+	it := sess.DB("qfw").C("jy_subscribe").Find(map[string]interface{}{
+		"s_event": "unsubscribe",
+		"l_date": map[string]interface{}{
+			"$gt": time.Now().AddDate(0, 0, num).Unix(),
+		},
+	}).Select(g.Map{"s_m_openid": 1}).Iter()
+
+	for m := make(map[string]interface{}); it.Next(&m); {
+		if openid := gconv.String(m["s_m_openid"]); openid != "" {
+			ua.UnSubUser[openid] = true
+		}
+	}
+	g.Log().Infof(ctx, "GetMgoUnSubUser 加载%d天%d个取关用户", num, len(ua.UnSubUser))
+}