wangkaiyue 9 months ago
parent
commit
301ed51c6d

+ 3 - 10
userSign/config.yaml

@@ -2,9 +2,9 @@ database:
   default:
     link: "clickhouse:jydev:Jsh2scksi7&hs@tcp(127.0.0.1:2900)/pub_tags?dial_timeout=2000ms&max_execution_time=60"
     debug: true
-#  default:
-#    link: "clickhouse:jytop:pwdTopJy123@tcp(192.168.3.207:19000)/pub_tags?dial_timeout=2000ms&max_execution_time=60"
-#    debug: true
+  order:
+    link: "clickhouse:jytop:pwdTopJy123@tcp(192.168.3.207:19000)/pub_tags?dial_timeout=2000ms&max_execution_time=60"
+    debug: true
 
 
 
@@ -22,10 +22,3 @@ mongodb:
     replSet: ""
     userName: "jianyu"
     password: "jylog2020_123"
-
-activeCode:
-  pcCode: pc_active
-  wxCode: wx_active
-  appCode: app_active
-  unActive30: unActive30
-  unActive90: unActive90

+ 0 - 60
userSign/lunarActivity/active.go

@@ -1,60 +0,0 @@
-package lunarActivity
-
-import (
-	"context"
-	"fmt"
-	"github.com/gogf/gf/v2/frame/g"
-	"github.com/gogf/gf/v2/util/gconv"
-	"strings"
-	"time"
-	"workTasks/userSign/match"
-)
-
-var (
-	ctx           = context.TODO()
-	ActiveCodeMap map[string]interface{}
-)
-
-func init() {
-	ActiveCodeMap = g.Cfg().MustGet(ctx, "activeCode.pcCode").Map()
-}
-
-func Active() {
-	var sqlIds, delCode, pcBaseId, wxBaseId, appBaseId []string
-	rPc, err := g.DB().Query(ctx, fmt.Sprintf(`SELECT DISTINCT(baseUserId) as baseUserId FROM user_log_byHour WHERE create_time >'%s' AND s_source ='pc';`, time.Now().AddDate(0, 0, -30).Format(time.DateTime)))
-	if err == nil && !rPc.IsEmpty() {
-		for _, m := range rPc.List() {
-			// 插入pc30天活跃用户
-			pcBaseId = append(pcBaseId, gconv.String(m["baseUserId"]))
-		}
-		if len(pcBaseId) > 0 {
-			delCode = append(delCode, gconv.String(ActiveCodeMap["pcCode"]))
-			sqlIds = append(sqlIds, fmt.Sprintf(`('%s', 'name_value1', bitmapBuild([toUInt64(%s)]), groupid_value1, 'created_at_value1', 'created_by_value1', bit_num_value1) `, ActiveCodeMap["pcCode"], strings.Join(pcBaseId, ",")))
-		}
-	}
-	rWx, err1 := g.DB().Query(ctx, fmt.Sprintf(`SELECT DISTINCT(baseUserId) as baseUserId  FROM user_log_byHour WHERE create_time >'%s' AND s_source ='wx';`, time.Now().AddDate(0, 0, -30).Format(time.DateTime)))
-	if err1 == nil && !rWx.IsEmpty() {
-		for _, m := range rWx.List() {
-			// 插入wx30天活跃用户
-			wxBaseId = append(wxBaseId, gconv.String(m["baseUserId"]))
-		}
-		if len(wxBaseId) > 0 {
-			delCode = append(delCode, gconv.String(ActiveCodeMap["wxCode"]))
-			sqlIds = append(sqlIds, fmt.Sprintf(`('%s', 'name_value1', bitmapBuild([toUInt64(%s)]), groupid_value1, 'created_at_value1', 'created_by_value1', bit_num_value1) `, ActiveCodeMap["wxCode"], strings.Join(wxBaseId, ",")))
-		}
-	}
-	rApp, err2 := g.DB().Query(ctx, fmt.Sprintf(`SELECT DISTINCT(baseUserId) as baseUserId FROM user_log_byHour WHERE create_time >'%s' AND s_source ='app';`, time.Now().AddDate(0, 0, -30).Format(time.DateTime)))
-	if err2 == nil && !rApp.IsEmpty() {
-		for _, m := range rApp.List() {
-			// 插入app30天活跃用户
-			appBaseId = append(appBaseId, gconv.String(m["baseUserId"]))
-		}
-		if len(appBaseId) > 0 {
-			delCode = append(delCode, gconv.String(ActiveCodeMap["appCode"]))
-			sqlIds = append(sqlIds, fmt.Sprintf(`('%s', 'name_value1', bitmapBuild([toUInt64(%s)]), groupid_value1, 'created_at_value1', 'created_by_value1', bit_num_value1) `, ActiveCodeMap["appCode"], strings.Join(appBaseId, ",")))
-		}
-	}
-	if len(sqlIds) > 0 {
-		match.SetUserTag(delCode, sqlIds)
-	}
-}

+ 0 - 48
userSign/lunarActivity/unActive.go

@@ -1,48 +0,0 @@
-package lunarActivity
-
-import (
-	"fmt"
-	"github.com/gogf/gf/v2/frame/g"
-	"github.com/gogf/gf/v2/util/gconv"
-	"strings"
-	"time"
-	"workTasks/userSign/match"
-)
-
-func UnActive() {
-	//30天未活跃
-	var sqlIds, delCode, unActive30, unActive90 []string
-	rMonth, err2 := g.DB().Query(ctx, fmt.Sprintf(`SELECT DISTINCT(dmp.baseUserId) as baseUserId1 FROM dwd_mgo_position dmp
-	left join (	SELECT DISTINCT(baseUserId) as baseUserId
-    FROM user_log_byHour ulbh
-    WHERE create_time > '%s' ) ulog  on  dmp.baseUserId =ulog.baseUserId where ulog.baseUserId=0`, time.Now().AddDate(0, 0, -30).Format(time.DateTime)))
-	if err2 == nil && !rMonth.IsEmpty() {
-		for _, m := range rMonth.List() {
-			// 插入30天未活跃
-			unActive30 = append(unActive30, gconv.String(m["baseUserId"]))
-		}
-		if len(unActive30) > 0 {
-			sqlIds = append(sqlIds, fmt.Sprintf(`('%s', 'name_value1', bitmapBuild([toUInt64(%s)]), groupid_value1, 'created_at_value1', 'created_by_value1', bit_num_value1) `, ActiveCodeMap["unActive30"], strings.Join(unActive30, ",")))
-			delCode = append(delCode, gconv.String(ActiveCodeMap["unActive30"]))
-		}
-	}
-
-	//90天未活跃
-	rQuarter, err2 := g.DB().Query(ctx, fmt.Sprintf(`SELECT DISTINCT(dmp.baseUserId) as baseUserId1 FROM dwd_mgo_position dmp
-	left join (	SELECT DISTINCT(baseUserId) as baseUserId
-    FROM user_log_byHour ulbh
-    WHERE create_time > '%s' ) ulog  on  dmp.baseUserId =ulog.baseUserId where ulog.baseUserId=0`, time.Now().AddDate(0, 0, -90).Format(time.DateTime)))
-	if err2 == nil && !rQuarter.IsEmpty() {
-		for _, m := range rQuarter.List() {
-			// 插入90天未活跃
-			unActive90 = append(unActive90, gconv.String(m["baseUserId"]))
-		}
-		if len(unActive90) > 0 {
-			delCode = append(delCode, gconv.String(ActiveCodeMap["unActive30"]))
-			sqlIds = append(sqlIds, fmt.Sprintf(`('%s', 'name_value1', bitmapBuild([toUInt64(%s)]), groupid_value1, 'created_at_value1', 'created_by_value1', bit_num_value1) `, ActiveCodeMap["unActive90"], strings.Join(unActive90, ",")))
-		}
-	}
-	if len(sqlIds) > 0 {
-		match.SetUserTag(delCode, sqlIds)
-	}
-}

+ 26 - 223
userSign/main.go

@@ -2,243 +2,46 @@ package main
 
 import (
 	"context"
+	"fmt"
 	"github.com/gogf/gf/v2/frame/g"
-	"github.com/gogf/gf/v2/util/gconv"
-	"strings"
 	"time"
-	"workTasks/common"
+	"workTasks/userSign/userAnalysis"
 )
 
-type UserAnalysis struct {
-	UserMapping map[string]BaseUserId
-
-	BinPhone, BindMail        map[BaseUserId]bool
-	Vip, Vip15, Vip30         map[BaseUserId]bool
-	Member, MemberExpire      map[BaseUserId]bool
-	hasPay                    map[BaseUserId]bool
-	UnBuyVip30, UnBuyMember30 map[BaseUserId]bool
+func main() {
+	runOnce(context.TODO())
 }
-type BaseUserId int64
 
-func (ua *UserAnalysis) MgoUserRange(ctx context.Context) {
-	sess := common.MG.DB().GetMgoConn()
-	defer common.MG.DB().DestoryMongoConn(sess)
-	//个人身份
-	it := sess.DB("qfw").C("user").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()
-	var (
-		index int64
-		now   = time.Now()
-	)
-	for m := make(map[string]interface{}); it.Next(&m); {
-		index++
-		if index%10e4 == 0 {
-			g.Log().Infof(context.TODO(), "MgoUserRange %d", index)
-		}
-		var (
-			base_user_id = BaseUserId(gconv.Int64(m["base_user_id"]))
-			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)
-		)
-		//绑定手机号用户
-		if len(s_phone) == 11 || len(s_m_phone) == 11 {
-			ua.BinPhone[base_user_id] = true
-		}
-		//绑定邮箱用户
-		if s_email != "" && strings.Contains(s_email, "@") {
-			ua.BindMail[base_user_id] = true
-		}
-		//超级订阅用户处理
-		if vip_status := gconv.Int(m["i_vip_status"]); vip_status > 0 {
-			ua.Vip[base_user_id] = true
-			if timeStamp := gconv.Int64(m["l_vip_endtime"]); timeStamp > 0 {
-				var vip_endtime = time.Unix(timeStamp, 0)
-				if vip_endtime.AddDate(0, 0, -15).Before(now) {
-					ua.Vip15[base_user_id] = true
-				}
-				if vip_endtime.AddDate(0, 0, -30).Before(now) {
-					ua.Vip30[base_user_id] = true
-				}
-			}
-		}
-		//大会员处理
-		if member_status := gconv.Int(m["i_member_status"]); member_status > 0 {
-			ua.Member[base_user_id] = true
-		} else if member_status != 0 {
-			ua.MemberExpire[base_user_id] = true
-		}
+func runOnce(ctx context.Context) {
+	manager := userAnalysis.NewManager()
+	if err := manager.LoadMapping(); err != nil {
+		g.Log().Errorf(ctx, "加载对应关系异常 %v", err)
 	}
-	g.Log().Infof(ctx, "MgoUserRange 加载%d挑数据完成", index)
-	//企业身份
-}
-
-func (ua *UserAnalysis) MgoEntUserRange(ctx context.Context) {
-	sess := common.MG.DB().GetMgoConn()
-	defer common.MG.DB().DestoryMongoConn(sess)
-
-	var (
-		Vip, Vip15, Vip30    = map[int64]bool{}, map[int64]bool{}, map[int64]bool{}
-		Member, MemberExpire = map[int64]bool{}, map[int64]bool{}
-	)
-	//企业身份
-	it := sess.DB("qfw").C("ent_user").Select(g.Map{"i_userid": 1, "l_registedate": 1, "i_vip_status": 1, "l_vip_endtime": 1, "i_member_status": 1}).Iter()
-	var (
-		index int64
-		now   = time.Now()
-	)
-	for m := make(map[string]interface{}); it.Next(&m); {
-		index++
-		if index%10e4 == 0 {
-			g.Log().Infof(context.TODO(), "MgoUserRange %d", index)
-		}
-		var (
-			entUserId = gconv.Int64(m["i_userid"])
-		)
-		//超级订阅用户处理
-		if vip_status := gconv.Int(m["i_vip_status"]); vip_status > 0 {
-			Vip[entUserId] = true
-			if timeStamp := gconv.Int64(m["l_vip_endtime"]); timeStamp > 0 {
-				var vip_endtime = time.Unix(timeStamp, 0)
-				if vip_endtime.AddDate(0, 0, -15).Before(now) {
-					Vip15[entUserId] = true
-				}
-				if vip_endtime.AddDate(0, 0, -30).Before(now) {
-					Vip30[entUserId] = true
-				}
-			}
-		}
-		//大会员处理
-		if member_status := gconv.Int(m["i_member_status"]); member_status > 0 {
-			Member[entUserId] = true
-		} else if member_status != 0 {
-			MemberExpire[entUserId] = true
-		}
+	var allRes []*userAnalysis.AnalysisRes
+	//订单分析
+	if res, err := manager.TiDBOrderRange(ctx); err == nil && len(res) > 0 {
+		allRes = append(allRes, res...)
 	}
-	g.Log().Infof(ctx, "MgoUserRange 加载%d挑数据完成", index)
-	//根据entUserId获取
-	baseUserIdMapping := func() map[int64]BaseUserId {
-		var (
-			all   = map[int64]bool{}
-			rData = map[int64]BaseUserId{}
-		)
-		for i, _ := range Member {
-			all[i] = true
-		}
-		for i, _ := range Vip {
-			all[i] = true
-		}
-		doQuery := func(entUserId []int64) map[int64]BaseUserId {
-			return nil
-		}
-
-		var query []int64
-		for i, _ := range all {
-			query = append(query, i)
-			if i >= 500 {
-				for m, n := range doQuery(query) {
-					rData[m] = n
-				}
-				query = []int64{}
-			}
-		}
-		if len(query) > 0 {
-			for m, n := range doQuery(query) {
-				rData[m] = n
-			}
-		}
-		return rData
-	}()
-	//Vip, Vip15, Vip30
-	for entId, _ := range Vip {
-		if baseUserId, ok := baseUserIdMapping[entId]; ok {
-			ua.Vip[baseUserId] = true
-		}
-	}
-	for entId, _ := range Vip15 {
-		if baseUserId, ok := baseUserIdMapping[entId]; ok {
-			ua.Vip15[baseUserId] = true
-		}
-	}
-	for entId, _ := range Vip30 {
-		if baseUserId, ok := baseUserIdMapping[entId]; ok {
-			ua.Vip30[baseUserId] = true
-		}
-	}
-	for entId, _ := range Member {
-		if baseUserId, ok := baseUserIdMapping[entId]; ok {
-			ua.Member[baseUserId] = true
-		}
+	//会员状态分析
+	if res, err := manager.GetMgoUserRes(ctx); err == nil && len(res) > 0 {
+		allRes = append(allRes, res...)
 	}
-	for entId, _ := range MemberExpire {
-		if baseUserId, ok := baseUserIdMapping[entId]; ok {
-			ua.MemberExpire[baseUserId] = true
-		}
-	}
-}
 
-func (ua *UserAnalysis) TiDBOrderRange(ctx context.Context) {
-	order, err := g.DB().Query(ctx, "SELECT user_id,order_status,product_type,create_time,order_money FROM dataexport_order")
-	if err != nil {
-		g.Log().Errorf(ctx, "读取订单异常")
-	}
 	var (
-		now         = time.Now()
-		vip, member = map[BaseUserId]int{}, map[BaseUserId]int{}
+		sourceArr    = []string{"pc", "wx", "app"}
+		nowTime      = time.Now()
+		unActiveTime = []int{30, 90}
 	)
-	for index, m := range order.List() {
-		if index%10e4 == 0 {
-			g.Log().Infof(context.TODO(), "TiDBOrderRange %d/%d", index, order.Size())
-		}
-		var (
-			userId      = gconv.String(m["user_id"])
-			baseUserId  BaseUserId
-			product     = gconv.String(m["product_type"])
-			orderStatus = gconv.Int(m["order_status"])
-		)
-		baseUserId, ok := ua.UserMapping[userId]
-		if !ok {
-			continue
-		}
-		if orderStatus == 1 {
-			ua.hasPay[baseUserId] = true
-		}
-		if orderStatus == -1 {
-			continue
-		}
-		//统计超级订阅、大会员当月加购未购
-		if product == "VIP订阅" || product == "大会员" {
-			var order_money = gconv.Int(m["order_money"])
-			t, err := time.ParseInLocation(time.DateTime, gconv.String(m["create_time"]), time.Local)
-			if err != nil {
-				continue
-			}
-			if now.Month() == t.Month() && now.Year() == t.Year() {
-				if product == "VIP订阅" {
-					if orderStatus <= 0 && order_money == 0 {
-						vip[baseUserId] += 0
-					} else {
-						vip[baseUserId] += 1
-					}
-				}
-				if product == "大会员" {
-					if orderStatus <= 0 && order_money == 0 {
-						member[baseUserId] += 0
-					} else {
-						member[baseUserId] += 1
-					}
-				}
-			}
-		}
-	}
-	for id, i := range vip {
-		if i == 0 {
-			ua.UnBuyVip30[id] = true
+	//活跃用户分析
+	for _, source := range sourceArr {
+		if res, err := manager.ActiveUserLoad(ctx, nowTime.AddDate(0, 0, -30), source); err == nil && len(res) > 0 {
+			allRes = append(allRes, &userAnalysis.AnalysisRes{Name: fmt.Sprintf("30天%s活跃用户", source), Code: fmt.Sprintf("active-%s-%d", source, 30), Data: res})
 		}
 	}
-	for id, i := range member {
-		if i == 0 {
-			ua.UnBuyMember30[id] = true
+	//未活跃用户占比
+	for _, day := range unActiveTime {
+		if res, err := manager.UnActiveUserLoad(ctx, nowTime.AddDate(0, 0, -day)); err == nil && len(res) > 0 {
+			allRes = append(allRes, &userAnalysis.AnalysisRes{Name: fmt.Sprintf("%d天未活跃用户", day), Code: "hasPay", Data: res})
 		}
 	}
 }

+ 54 - 0
userSign/userAnalysis/analysisManager.go

@@ -0,0 +1,54 @@
+package userAnalysis
+
+import (
+	"github.com/gogf/gf/v2/frame/g"
+	"github.com/gogf/gf/v2/util/gconv"
+)
+
+type (
+	UserAnalysis struct {
+		UserMapping map[string]BaseUserId //职位id、mongouserId对应的baseUserId
+
+		BinPhone, BindMail   map[BaseUserId]bool
+		Vip, Vip15, Vip30    map[BaseUserId]bool
+		Member, MemberExpire map[BaseUserId]bool
+	}
+	BaseUserId int64
+
+	AnalysisRes struct {
+		Name, Code string              //标签名字
+		Data       map[BaseUserId]bool //数据
+	}
+)
+
+func NewManager() *UserAnalysis {
+	return &UserAnalysis{
+		UserMapping:  map[string]BaseUserId{},
+		BinPhone:     map[BaseUserId]bool{},
+		BindMail:     map[BaseUserId]bool{},
+		Vip:          map[BaseUserId]bool{},
+		Vip15:        map[BaseUserId]bool{},
+		Vip30:        map[BaseUserId]bool{},
+		Member:       map[BaseUserId]bool{},
+		MemberExpire: map[BaseUserId]bool{},
+	}
+}
+
+func (ua *UserAnalysis) LoadMapping() error {
+	data, err := g.DB().Query(ctx, "SELECT mgoUserId,positionId,baseUserId FROM dwd_mgo_position")
+	if err != nil {
+		return err
+	}
+	newMapping := map[string]BaseUserId{}
+	for _, m := range data.List() {
+		var (
+			mgoUserId  = gconv.String(m["mgoUserId"])
+			positionId = gconv.String(m["positionId"])
+			baseUserId = BaseUserId(gconv.Int64(m["baseUserId"]))
+		)
+		newMapping[mgoUserId] = baseUserId
+		newMapping[positionId] = baseUserId
+	}
+	ua.UserMapping = newMapping
+	return nil
+}

+ 48 - 0
userSign/userAnalysis/jobLogsAnalysis.go

@@ -0,0 +1,48 @@
+package userAnalysis
+
+import (
+	"context"
+	"github.com/gogf/gf/v2/frame/g"
+	"github.com/gogf/gf/v2/util/gconv"
+	"time"
+)
+
+var (
+	ctx           = context.TODO()
+	ActiveCodeMap map[string]interface{}
+)
+
+func init() {
+	ActiveCodeMap = g.Cfg().MustGet(ctx, "activeCode.pcCode").Map()
+}
+
+// ActiveUserLoad 活跃用户
+func (ua *UserAnalysis) ActiveUserLoad(ctx context.Context, start time.Time, source string) (map[BaseUserId]bool, error) {
+	rPc, err := g.DB().Query(ctx, "SELECT DISTINCT(baseUserId) as baseUserId FROM user_log_byHour WHERE create_time > ? AND s_source =?;", start.Format(time.DateTime), source)
+	if err != nil {
+		return nil, err
+	}
+	activeUser := map[BaseUserId]bool{}
+	for _, m := range rPc.List() {
+		// 插入pc30天活跃用户
+		activeUser[BaseUserId(gconv.Int64(m["baseUserId"]))] = true
+	}
+	return activeUser, nil
+}
+
+// UnActiveUserLoad 未活跃用户
+func (ua *UserAnalysis) UnActiveUserLoad(ctx context.Context, start time.Time) (map[BaseUserId]bool, error) {
+	rPc, err := g.DB().Query(ctx, `SELECT DISTINCT(dmp.baseUserId) as baseUserId1 FROM dwd_mgo_position dmp
+	left join (	SELECT DISTINCT(baseUserId) as baseUserId
+	FROM user_log_byHour ulbh
+	WHERE create_time > ? ) ulog  on  dmp.baseUserId =ulog.baseUserId where ulog.baseUserId=0`, start.Format(time.DateTime))
+	if err != nil {
+		return nil, err
+	}
+	unActiveUser := map[BaseUserId]bool{}
+	for _, m := range rPc.List() {
+		// 插入pc30天活跃用户
+		unActiveUser[BaseUserId(gconv.Int64(m["baseUserId"]))] = true
+	}
+	return unActiveUser, nil
+}

+ 183 - 0
userSign/userAnalysis/jobMgoUserRange.go

@@ -0,0 +1,183 @@
+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) GetMgoUserRes(ctx context.Context) ([]*AnalysisRes, error) {
+	if len(ua.UserMapping) == 0 {
+		return nil, nil
+	}
+	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: "Vip15", Data: ua.Vip15},
+			{Name: "超级订阅30天到期用户", Code: "Vip30", Data: ua.Vip30},
+			{Name: "大会员用户", Code: "Member", Data: ua.Member},
+			{Name: "曾购大会员用户", Code: "MemberExpire", Data: ua.MemberExpire}},
+		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").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()
+	var (
+		index int64
+		now   = time.Now()
+	)
+	for m := make(map[string]interface{}); it.Next(&m); {
+		index++
+		if index%10e4 == 0 {
+			g.Log().Infof(context.TODO(), "MgoUserRange %d", index)
+		}
+		var (
+			base_user_id = BaseUserId(gconv.Int64(m["base_user_id"]))
+			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)
+		)
+		//绑定手机号用户
+		if len(s_phone) == 11 || len(s_m_phone) == 11 {
+			ua.BinPhone[base_user_id] = true
+		}
+		//绑定邮箱用户
+		if s_email != "" && strings.Contains(s_email, "@") {
+			ua.BindMail[base_user_id] = true
+		}
+		//超级订阅用户处理
+		if vip_status := gconv.Int(m["i_vip_status"]); vip_status > 0 {
+			ua.Vip[base_user_id] = true
+			if timeStamp := gconv.Int64(m["l_vip_endtime"]); timeStamp > 0 {
+				var vip_endtime = time.Unix(timeStamp, 0)
+				if vip_endtime.AddDate(0, 0, -15).Before(now) {
+					ua.Vip15[base_user_id] = true
+				}
+				if vip_endtime.AddDate(0, 0, -30).Before(now) {
+					ua.Vip30[base_user_id] = true
+				}
+			}
+		}
+		//大会员处理
+		if member_status := gconv.Int(m["i_member_status"]); member_status > 0 {
+			ua.Member[base_user_id] = true
+		} else if member_status != 0 {
+			ua.MemberExpire[base_user_id] = true
+		}
+	}
+	g.Log().Infof(ctx, "MgoUserRange 加载%d挑数据完成", index)
+}
+
+func (ua *UserAnalysis) mgoEntUserRange(ctx context.Context) {
+	sess := common.MG.DB().GetMgoConn()
+	defer common.MG.DB().DestoryMongoConn(sess)
+
+	var (
+		Vip, Vip15, Vip30    = map[int64]bool{}, map[int64]bool{}, map[int64]bool{}
+		Member, MemberExpire = map[int64]bool{}, map[int64]bool{}
+	)
+	//企业身份
+	it := sess.DB("qfw").C("ent_user").Select(g.Map{"i_userid": 1, "l_registedate": 1, "i_vip_status": 1, "l_vip_endtime": 1, "i_member_status": 1}).Iter()
+	var (
+		index int64
+		now   = time.Now()
+	)
+	for m := make(map[string]interface{}); it.Next(&m); {
+		index++
+		if index%10e4 == 0 {
+			g.Log().Infof(context.TODO(), "MgoUserRange %d", index)
+		}
+		var (
+			entUserId = gconv.Int64(m["i_userid"])
+		)
+		//超级订阅用户处理
+		if vip_status := gconv.Int(m["i_vip_status"]); vip_status > 0 {
+			Vip[entUserId] = true
+			if timeStamp := gconv.Int64(m["l_vip_endtime"]); timeStamp > 0 {
+				var vip_endtime = time.Unix(timeStamp, 0)
+				if vip_endtime.AddDate(0, 0, -15).Before(now) {
+					Vip15[entUserId] = true
+				}
+				if vip_endtime.AddDate(0, 0, -30).Before(now) {
+					Vip30[entUserId] = true
+				}
+			}
+		}
+		//大会员处理
+		if member_status := gconv.Int(m["i_member_status"]); member_status > 0 {
+			Member[entUserId] = true
+		} else if member_status != 0 {
+			MemberExpire[entUserId] = true
+		}
+	}
+	g.Log().Infof(ctx, "MgoUserRange 加载%d挑数据完成", index)
+	//根据entUserId获取
+	baseUserIdMapping := func() map[int64]BaseUserId {
+		var (
+			all   = map[int64]bool{}
+			rData = map[int64]BaseUserId{}
+		)
+		for i, _ := range Member {
+			all[i] = true
+		}
+		for i, _ := range Vip {
+			all[i] = true
+		}
+		doQuery := func(entUserId []int64) map[int64]BaseUserId {
+			return nil
+		}
+
+		var query []int64
+		for i, _ := range all {
+			query = append(query, i)
+			if i >= 500 {
+				for m, n := range doQuery(query) {
+					rData[m] = n
+				}
+				query = []int64{}
+			}
+		}
+		if len(query) > 0 {
+			for m, n := range doQuery(query) {
+				rData[m] = n
+			}
+		}
+		return rData
+	}()
+	//Vip, Vip15, Vip30
+	for entId, _ := range Vip {
+		if baseUserId, ok := baseUserIdMapping[entId]; ok {
+			ua.Vip[baseUserId] = true
+		}
+	}
+	for entId, _ := range Vip15 {
+		if baseUserId, ok := baseUserIdMapping[entId]; ok {
+			ua.Vip15[baseUserId] = true
+		}
+	}
+	for entId, _ := range Vip30 {
+		if baseUserId, ok := baseUserIdMapping[entId]; ok {
+			ua.Vip30[baseUserId] = true
+		}
+	}
+	for entId, _ := range Member {
+		if baseUserId, ok := baseUserIdMapping[entId]; ok {
+			ua.Member[baseUserId] = true
+		}
+	}
+	for entId, _ := range MemberExpire {
+		if baseUserId, ok := baseUserIdMapping[entId]; ok {
+			ua.MemberExpire[baseUserId] = true
+		}
+	}
+}

+ 87 - 0
userSign/userAnalysis/jobOrderRange.go

@@ -0,0 +1,87 @@
+package userAnalysis
+
+import (
+	"context"
+	"github.com/gogf/gf/v2/frame/g"
+	"github.com/gogf/gf/v2/util/gconv"
+	"time"
+)
+
+// TiDBOrderRange 订单分析
+func (ua *UserAnalysis) TiDBOrderRange(ctx context.Context) ([]*AnalysisRes, error) {
+	if len(ua.UserMapping) > 0 {
+		return nil, nil
+	}
+	order, err := g.DB("order").Query(ctx, "SELECT user_id,order_status,product_type,create_time,order_money FROM dataexport_order")
+	if err != nil {
+		g.Log().Errorf(ctx, "读取订单异常")
+		return nil, err
+	}
+	var (
+		now                             = time.Now()
+		hasPay                          = map[BaseUserId]bool{}
+		unBuyVipMonth, unBuyMemberMonth = map[BaseUserId]bool{}, map[BaseUserId]bool{}
+
+		vip, member = map[BaseUserId]int{}, map[BaseUserId]int{}
+	)
+	for index, m := range order.List() {
+		if index%10e4 == 0 {
+			g.Log().Infof(context.TODO(), "TiDBOrderRange %d/%d", index, order.Size())
+		}
+		var (
+			userId      = gconv.String(m["user_id"])
+			baseUserId  BaseUserId
+			product     = gconv.String(m["product_type"])
+			orderStatus = gconv.Int(m["order_status"])
+		)
+		baseUserId, ok := ua.UserMapping[userId]
+		if !ok {
+			continue
+		}
+		if orderStatus == 1 {
+			hasPay[baseUserId] = true
+		}
+		if orderStatus == -1 {
+			continue
+		}
+		//统计超级订阅、大会员当月加购未购
+		if product == "VIP订阅" || product == "大会员" {
+			var order_money = gconv.Int(m["order_money"])
+			t, err := time.ParseInLocation(time.DateTime, gconv.String(m["create_time"]), time.Local)
+			if err != nil {
+				continue
+			}
+			if now.Month() == t.Month() && now.Year() == t.Year() {
+				if product == "VIP订阅" {
+					if orderStatus <= 0 && order_money == 0 {
+						vip[baseUserId] += 0
+					} else {
+						vip[baseUserId] += 1
+					}
+				}
+				if product == "大会员" {
+					if orderStatus <= 0 && order_money == 0 {
+						member[baseUserId] += 0
+					} else {
+						member[baseUserId] += 1
+					}
+				}
+			}
+		}
+	}
+	for id, i := range vip {
+		if i == 0 {
+			unBuyVipMonth[id] = true
+		}
+	}
+	for id, i := range member {
+		if i == 0 {
+			unBuyMemberMonth[id] = true
+		}
+	}
+	return []*AnalysisRes{
+			{Name: "付费用户", Code: "hasPay", Data: hasPay},
+			{Name: "本月加购未购超级订阅", Code: "unBuyVipMonth", Data: unBuyVipMonth},
+			{Name: "本月加购未购大会员", Code: "unBuyMemberMonth", Data: unBuyMemberMonth}},
+		nil
+}