Browse Source

Merge branch 'crm/crm_16.5' of http://8.136.199.33:3000/hongze/hongze_cygx into debug

zhangchuanxing 2 months ago
parent
commit
3cbcbfda3c

+ 9 - 0
models/activity.go

@@ -285,6 +285,15 @@ func GetAddActivityInfoByActivityId(ActivityId int) (item *ActivityDetail, err e
 	return
 }
 
+// 获取活动详情
+func GetAddActivityDetailByActivityId(ActivityId int) (item *ActivityDetail, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT a.*,t.activity_type, FROM cygx_activity AS a 
+			INNER JOIN cygx_activity_type  as t ON t.activity_type_id = a.activity_type_id  WHERE activity_id=?  `
+	err = o.Raw(sql, ActivityId).QueryRow(&item)
+	return
+}
+
 // 通过活动名称获取活动详情
 func GetAddActivityInfoByTitle(title, startDate, endDate string) (item *ActivityDetail, err error) {
 	o := orm.NewOrm()

+ 14 - 0
models/industrial_activity_group_management.go

@@ -93,3 +93,17 @@ func GetCygxIndustrialActivityGroupManagementList(condition string, pars []inter
 	_, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
 	return
 }
+
+// 列表
+func GetIndustrialActivityGroupManagementListByArticleId(activityId int) (items []*IndustrialActivityGroupManagementRep, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			m.industry_name 
+			FROM
+			cygx_industrial_management AS m
+			INNER JOIN cygx_industrial_activity_group_management AS am ON m.industrial_management_id = am.industrial_management_id
+			WHERE
+			am.activity_id = ? AND m.source = 1 `
+	_, err = o.Raw(sql, activityId).QueryRows(&items)
+	return
+}

+ 14 - 0
models/industrial_activity_group_subject.go

@@ -32,3 +32,17 @@ func GetCygxIndustrialActivityGroupSubjectList(condition string, pars []interfac
 	_, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
 	return
 }
+
+// 列表
+func GetSubjectActivityGroupManagementListByActivityId(activityId int) (items []*SubjectActivityGroupManagementRep, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			s.subject_name
+			FROM
+			cygx_industrial_subject  AS s
+			INNER JOIN cygx_industrial_activity_group_subject AS ag ON s.industrial_subject_id = ag.industrial_subject_id 
+			WHERE
+			ag.activity_id = ?`
+	_, err = o.Raw(sql, activityId).QueryRows(&items)
+	return
+}

+ 7 - 0
services/activity_signup_detail.go

@@ -214,6 +214,13 @@ func AddctivitySignupDetailByJmcjNew(itemsDetail []*models.CygxActivityAttendanc
 			YanXuanActivityPointsBillSubmitMeeting(v, 0)
 		}
 	}
+
+	//添加到Redis队列消息中,处理用户标签
+	for _, v := range itemsAdd {
+		if v.UserId > 0 {
+			ActivityWxUserRaiLabelRedisAdd(v.ActivityId, v.UserId, v.CreateTime)
+		}
+	}
 	return err
 }
 

+ 137 - 16
services/wx_user_rai_label.go

@@ -67,6 +67,25 @@ func ReportSelectionWxUserRaiLabelRedisAdd(sourceId, uid int, createTime time.Ti
 	return
 }
 
+// 添加用户参加活动标签到Redis
+func ActivityWxUserRaiLabelRedisAdd(sourceId, uid int, createTime time.Time) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			msg := fmt.Sprint("sourceId:", sourceId, "userId:", uid)
+			go utils.SendAlarmMsg("添加用户参加活动标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
+		}
+	}()
+	log := &models.WxUserRaiLabelRedis{UserId: uid, SourceId: sourceId, SourceType: 2, CreateTime: createTime, RegisterPlatform: utils.REGISTER_PLATFORM}
+	if utils.Re == nil {
+		err := utils.Rc.LPush(utils.WX_USER_RAI_LABEL_KEY, log)
+		if err != nil {
+			fmt.Println("ActivityWxUserRaiLabelRedisAdd LPush Err:" + err.Error())
+		}
+	}
+	return
+}
+
 func UpdateWxUserRaiLabelRedis() (err error) {
 	for {
 		//	SourceType       int       `description:"来源1:搜索关键字标签、2:产业/个股标签(线下活动)、3:产业/个股标签(线下路演)、4:产业/个股标签(线上活动)、5:产业/个股标签(线上路演)、6:销售输入标签、7:产业/个股标签(报告)、8:报告类型标签"`
@@ -83,22 +102,11 @@ func UpdateWxUserRaiLabelRedis() (err error) {
 					go KeyWordsWxUserRaiLabelRedisAddReduce(log)
 					fmt.Println("搜索关键词")
 					break
-				//case 2:
-				//	go IndustryFllowUserLabelLogReduce(log)
-				//	fmt.Println("2产业关注")
-				//	break
-				//case 3:
-				//	go ActivityUserLabelLogReduce(log)
-				//	fmt.Println("活动到会")
-				//	break
-				//case 4:
-				//	go CategoryFllowUserLabelLogReduce(log)
-				//	fmt.Println("4系列关注")
-				//	break
-				//case 5:
-				//	go ActivitySpecialUserLabelLogReduce(log)
-				//	fmt.Println("5专项调研活动到会")
-				//	break
+				case 2, 4:
+					go ActivityWxUserRaiLabelRedisAddReduce(log)
+					fmt.Println("2产业关注")
+					break
+
 				default:
 					fmt.Println(string(b))
 					go utils.SendAlarmMsg("用户更新相关标签处理Redis队列消息失败:"+string(b), 2)
@@ -160,6 +168,119 @@ func KeyWordsWxUserRaiLabelRedisAddReduce(log models.WxUserRaiLabelRedis) (err e
 	return
 }
 
+// 2:产业/个股标签(线下活动)、 4:产业/个股标签(线上活动)
+// 用户参加活动,相关标签
+func ActivityWxUserRaiLabelRedisAddReduce(log models.WxUserRaiLabelRedis) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg("用户参加活动,相关标签,处理Redis队列消息失败:ActivityWxUserRaiLabelRedisAddReduce"+err.Error()+fmt.Sprint("SourceId", log.SourceId, "userId", log.UserId), 2)
+		}
+	}()
+	userId := log.UserId
+	sourceId := log.SourceId
+	wxUser, e := models.GetWxUserItemByUserId(userId)
+	if e != nil {
+		err = errors.New("GetWxUserItemByUserId" + e.Error())
+		return
+	}
+	activityDetail, e := models.GetAddActivityDetailByActivityId(sourceId)
+	if e != nil {
+		err = errors.New("GetArticleDetailTestById" + e.Error())
+		return
+	}
+
+	var sourceType int
+	if activityDetail.ActivityType == 1 {
+		sourceType = 4
+	} else {
+		sourceType = 2
+	}
+
+	//正常的有产业报告
+	var labelArr []string
+	//建立首页资源表,与产业的关系
+	industrialList, e := models.GetIndustrialActivityGroupManagementListByArticleId(sourceId)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetIndustrialArticleGroupManagementListByArticleId, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
+		return
+	}
+
+	var items []*models.WxUserRaiLabel
+	for _, v := range industrialList {
+		item := new(models.WxUserRaiLabel)
+		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 = v.IndustryName
+		item.SourceType = sourceType
+		item.SourceId = sourceId
+		item.CreateTime = log.CreateTime
+		item.ModifyTime = time.Now()
+		item.RegisterPlatform = log.RegisterPlatform
+		item.TableName = ""
+		items = append(items, item)
+		labelArr = append(labelArr, v.IndustryName)
+	}
+
+	//建立首页资源表,与标的 的关系
+	subjectList, e := models.GetSubjectArticleGroupManagementListByArtcileId(sourceId)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetSubjectArticleGroupManagementListByArtcileId, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
+		return
+	}
+
+	for _, v := range subjectList {
+		item := new(models.WxUserRaiLabel)
+		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 = v.SubjectName
+		item.SourceType = sourceType
+		item.SourceId = sourceId
+		item.CreateTime = log.CreateTime
+		item.ModifyTime = time.Now()
+		item.RegisterPlatform = log.RegisterPlatform
+		item.TableName = ""
+		items = append(items, item)
+		labelArr = append(labelArr, v.SubjectName)
+	}
+
+	//如果两个标签都没有,就添加临时标签
+	if len(labelArr) == 0 {
+		item := new(models.WxUserRaiLabel)
+		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 = activityDetail.Label
+		item.SourceType = sourceType
+		item.SourceId = sourceId
+		item.CreateTime = log.CreateTime
+		item.ModifyTime = time.Now()
+		item.RegisterPlatform = log.RegisterPlatform
+		item.TableName = ""
+		items = append(items, item)
+		labelArr = append(labelArr, activityDetail.Label)
+	}
+
+	e = models.AddWxUserRaiLabelMulti(items, labelArr, userId)
+	if e != nil {
+		err = errors.New("AddWxUserRaiLabelMulti" + e.Error())
+		return
+	}
+
+	return
+}
+
 // 7:产业/个股标签(报告)、8:报告类型标签
 func ArticleWxUserRaiLabelRedisAddReduce(log models.WxUserRaiLabelRedis) (err error) {
 	defer func() {