Browse Source

no message

zhangchuanxing 3 weeks ago
parent
commit
541bd579da

+ 8 - 0
models/activity_video_history.go

@@ -71,3 +71,11 @@ func UpdateLastCygxActivityVideoHistory(playSeconds string, lastId int) (err err
 	_, err = o.Raw(sql, playSeconds, lastId).Exec()
 	return
 }
+
+// 获取列表信息根据手机号分组
+func GetActivityVideoHistoryByMobileListCRM_16_5Init(condition string) (items []*CygxActivityVideoHistory, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT mobile,activity_id ,MAX(create_time)  as  create_time  FROM cygx_activity_video_history  WHERE 1 =1  ` + condition + `  GROUP BY mobile ,activity_id `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}

+ 8 - 0
models/activity_voice_history.go

@@ -63,3 +63,11 @@ func UpdateCygxActivityVoiceHistory(wxUser *WxUserItem) (err error) {
 	}
 	return
 }
+
+// 获取列表信息根据手机号分组
+func GetActivityVoiceHistoryByMobileListCRM_16_5Init(condition string) (items []*CygxActivityVoiceHistory, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT mobile,activity_id ,MAX(create_time)  as  create_time  FROM cygx_activity_voice_history  WHERE 1 =1  ` + condition + `  GROUP BY mobile ,activity_id `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}

+ 1 - 1
models/wx_user_rai_label.go

@@ -282,7 +282,7 @@ func GetWxUserRaiLabelLogAll() (items []*WxUserRaiLabelLog, err error) {
 	sql := `SELECT
 			*
 		FROM
-			wx_user_rai_label_log  `
+			wx_user_rai_label_log   ORDER BY create_time DESC   `
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }

+ 271 - 7
services/wx_user_rai_label.go

@@ -852,7 +852,7 @@ func GetArticlelabelArrByArticleId(articleId int) (labelArr []string, sourceType
 
 //func init() {
 //	//fmt.Println(GetArticlelabelArrByArticleId(11037))
-//	//initCrm16_5Article2()
+//	initCrm16_5ActivityVivo()
 //}
 
 func initCrm16_5keyWord() {
@@ -913,9 +913,10 @@ func initCrm16_5keyWord() {
 	if len(items) > 0 {
 		for _, v := range items {
 			itemsAdd = append(itemsAdd, v)
-			if len(items)%2000 == 0 {
+			if len(itemsAdd)%2000 == 0 {
 				err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
 				if err != nil {
+					fmt.Println(err)
 					return
 				}
 				itemsAdd = make([]*models.WxUserRaiLabelLog, 0)
@@ -926,6 +927,7 @@ func initCrm16_5keyWord() {
 	if len(itemsAdd) > 0 {
 		err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
 		if err != nil {
+			fmt.Println(err)
 			return
 		}
 	}
@@ -1104,6 +1106,267 @@ func initCrm16_5Activity() {
 	fmt.Println("endAddWxUserRaiLabelLogMultiInit")
 }
 
+func initCrm16_5ActivityVivo() {
+	var condition string
+	var pars []interface{}
+	condition += ` AND	create_time > '2024-09-01'   `
+	pars = append(pars)
+	//获取提交到会的人员信息
+	ActivityVoiceList, err := models.GetActivityVoiceHistoryByMobileListCRM_16_5Init(condition)
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	ActivityVideoList, err := models.GetActivityVideoHistoryByMobileListCRM_16_5Init(condition)
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	var mobiles []string
+
+	mapMobile := make(map[string]bool)
+
+	for _, v := range ActivityVoiceList {
+		if mapMobile[v.Mobile] || v.Mobile == "" {
+			continue
+		}
+		mapMobile[v.Mobile] = true
+		mobiles = append(mobiles, v.Mobile)
+	}
+
+	for _, v := range ActivityVideoList {
+		if mapMobile[v.Mobile] || v.Mobile == "" {
+			continue
+		}
+		mapMobile[v.Mobile] = true
+		mobiles = append(mobiles, v.Mobile)
+	}
+
+	var activityIds []int
+	mapactivityId := make(map[int]bool)
+	for _, v := range ActivityVoiceList {
+		if mapactivityId[v.ActivityId] {
+			continue
+		}
+		mapactivityId[v.ActivityId] = true
+		activityIds = append(activityIds, v.ActivityId)
+	}
+
+	for _, v := range ActivityVideoList {
+		if mapactivityId[v.ActivityId] {
+			continue
+		}
+		mapactivityId[v.ActivityId] = true
+		activityIds = append(activityIds, v.ActivityId)
+	}
+
+	listUser, err := models.GetWxUserListByMobileArr(mobiles)
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	mapUser := make(map[string]*models.WxUserItem)
+	for _, v := range listUser {
+		mapUser[v.Mobile] = v
+	}
+
+	activityDetailList, e := models.GetAddActivityDetailByActivityIdinitCrm16_5(activityIds)
+	if e != nil {
+		fmt.Println(e)
+		return
+	}
+
+	//sourceTypemap := make(map[int]int)
+	mapLabel := make(map[int]string)
+
+	for _, v := range activityDetailList {
+		//if v.ActivityType == 1 {
+		//	sourceTypemap[v.ActivityId] = 4
+		//} else {
+		//	sourceTypemap[v.ActivityId] = 2
+		//}
+		mapLabel[v.ActivityId] = v.Label
+	}
+
+	//正常的有产业报告
+
+	//建立首页资源表,与产业的关系
+	industrialList, e := models.GetIndustrialActivityGroupManagementListByArticleIds(activityIds)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		fmt.Println(e)
+		return
+	}
+
+	//建立首页资源表,与标的 的关系
+	subjectList, e := models.GetSubjectActivityGroupManagementListByActivityIds(activityIds)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		fmt.Println(e)
+		return
+	}
+
+	var items []*models.WxUserRaiLabelLog
+	for _, v := range ActivityVoiceList {
+		if mapUser[v.Mobile] == nil || v.Mobile == "" {
+			continue
+		}
+		var haseName bool
+		wxUser := mapUser[v.Mobile]
+		for _, vI := range industrialList {
+			if vI.ActivityId != v.ActivityId {
+				continue
+			}
+			haseName = true
+			item := new(models.WxUserRaiLabelLog)
+			item.UserId = wxUser.UserId
+			item.RealName = wxUser.RealName
+			item.Mobile = wxUser.Mobile
+			item.Email = wxUser.Email
+			item.CompanyId = wxUser.CompanyId
+			item.CompanyName = wxUser.CompanyName
+			item.Label = vI.IndustryName
+			item.SourceType = 9
+			item.SourceId = v.ActivityId
+			item.CreateTime = v.CreateTime
+			item.ModifyTime = time.Now()
+			item.TableName = ""
+			//item.RegisterPlatform = v.RegisterPlatform
+			items = append(items, item)
+		}
+
+		for _, vs := range subjectList {
+			if vs.ActivityId != v.ActivityId {
+				continue
+			}
+			haseName = true
+			item := new(models.WxUserRaiLabelLog)
+			item.UserId = wxUser.UserId
+			item.RealName = wxUser.RealName
+			item.Mobile = wxUser.Mobile
+			item.Email = wxUser.Email
+			item.CompanyId = wxUser.CompanyId
+			item.CompanyName = wxUser.CompanyName
+			item.Label = vs.SubjectName
+			item.SourceType = 9
+			item.SourceId = v.ActivityId
+			item.CreateTime = v.CreateTime
+			item.ModifyTime = time.Now()
+			//item.RegisterPlatform = v.RegisterPlatform
+			items = append(items, item)
+		}
+
+		//如果两个标签都没有,就添加临时标签
+		if !haseName {
+			item := new(models.WxUserRaiLabelLog)
+			item.UserId = wxUser.UserId
+			item.RealName = wxUser.RealName
+			item.Mobile = wxUser.Mobile
+			item.Email = wxUser.Email
+			item.CompanyId = wxUser.CompanyId
+			item.CompanyName = wxUser.CompanyName
+			item.Label = mapLabel[v.ActivityId]
+			item.SourceType = 9
+			item.SourceId = v.ActivityId
+			item.CreateTime = v.CreateTime
+			item.ModifyTime = time.Now()
+			//item.RegisterPlatform = v.RegisterPlatform
+			item.TableName = ""
+			items = append(items, item)
+		}
+	}
+
+	for _, v := range ActivityVideoList {
+		if mapUser[v.Mobile] == nil || v.Mobile == "" {
+			continue
+		}
+		var haseName bool
+		wxUser := mapUser[v.Mobile]
+		for _, vI := range industrialList {
+			if vI.ActivityId != v.ActivityId {
+				continue
+			}
+			haseName = true
+			item := new(models.WxUserRaiLabelLog)
+			item.UserId = wxUser.UserId
+			item.RealName = wxUser.RealName
+			item.Mobile = wxUser.Mobile
+			item.Email = wxUser.Email
+			item.CompanyId = wxUser.CompanyId
+			item.CompanyName = wxUser.CompanyName
+			item.Label = vI.IndustryName
+			item.SourceType = 9
+			item.SourceId = v.ActivityId
+			item.CreateTime = v.CreateTime
+			item.ModifyTime = time.Now()
+			item.TableName = ""
+			//item.RegisterPlatform = v.RegisterPlatform
+			items = append(items, item)
+		}
+
+		for _, vs := range subjectList {
+			if vs.ActivityId != v.ActivityId {
+				continue
+			}
+			haseName = true
+			item := new(models.WxUserRaiLabelLog)
+			item.UserId = wxUser.UserId
+			item.RealName = wxUser.RealName
+			item.Mobile = wxUser.Mobile
+			item.Email = wxUser.Email
+			item.CompanyId = wxUser.CompanyId
+			item.CompanyName = wxUser.CompanyName
+			item.Label = vs.SubjectName
+			item.SourceType = 9
+			item.SourceId = v.ActivityId
+			item.CreateTime = v.CreateTime
+			item.ModifyTime = time.Now()
+			//item.RegisterPlatform = v.RegisterPlatform
+			items = append(items, item)
+		}
+
+		//如果两个标签都没有,就添加临时标签
+		if !haseName {
+			item := new(models.WxUserRaiLabelLog)
+			item.UserId = wxUser.UserId
+			item.RealName = wxUser.RealName
+			item.Mobile = wxUser.Mobile
+			item.Email = wxUser.Email
+			item.CompanyId = wxUser.CompanyId
+			item.CompanyName = wxUser.CompanyName
+			item.Label = mapLabel[v.ActivityId]
+			item.SourceType = 9
+			item.SourceId = v.ActivityId
+			item.CreateTime = v.CreateTime
+			item.ModifyTime = time.Now()
+			//item.RegisterPlatform = v.RegisterPlatform
+			item.TableName = ""
+			items = append(items, item)
+		}
+	}
+	fmt.Println("initCrm16_5Activity", len(items))
+	//return
+	var itemsAdd []*models.WxUserRaiLabelLog
+	if len(items) > 0 {
+		for _, v := range items {
+			itemsAdd = append(itemsAdd, v)
+			if len(itemsAdd)%2000 == 0 {
+				err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
+				if err != nil {
+					return
+				}
+				itemsAdd = make([]*models.WxUserRaiLabelLog, 0)
+			}
+
+		}
+	}
+	if len(itemsAdd) > 0 {
+		err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
+		if err != nil {
+			return
+		}
+	}
+	fmt.Println("endAddWxUserRaiLabelLogMultiInit")
+}
+
 func initCrm16_5Article() {
 	var condition string
 	var pars []interface{}
@@ -1250,14 +1513,15 @@ func initCrm16_5Article2() {
 
 }
 
-////func init() {
+//func init() {
 //	//initCrm16_5keyWord()
 //	//initCrm16_5Activity()
+//	////initCrm16_5Article()
 //	//initCrm16_5Article2()
 //	//initCrm16_5ReportHistory()
 //	//initCrm16_5ReportHistory_2()
 //	//initCrm16_5Roadshow()
-//
+//	//initCrm16_5ActivityVivo()
 //	fmt.Println("end RO")
 //
 //	initCrm16_5wx_user_rai_label()
@@ -1671,8 +1935,8 @@ func initCrm16_5wx_user_rai_label() {
 	if len(items) > 0 {
 		for _, v := range items {
 			itemsAdd = append(itemsAdd, v)
-			if len(items)%2000 == 0 {
-				err = models.AddWxUserRaiLabelMultiInit(items)
+			if len(itemsAdd)%2000 == 0 {
+				err = models.AddWxUserRaiLabelMultiInit(itemsAdd)
 				if err != nil {
 					return
 				}
@@ -1687,5 +1951,5 @@ func initCrm16_5wx_user_rai_label() {
 		}
 	}
 
-	fmt.Println("endAddWxUserRaiLabelLogMultiInit")
+	fmt.Println("end initCrm16_5wx_user_rai_label")
 }