瀏覽代碼

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

zhangchuanxing 2 月之前
父節點
當前提交
430e27b190
共有 4 個文件被更改,包括 114 次插入27 次删除
  1. 2 2
      models/article.go
  2. 1 0
      models/wx_user_rai_label.go
  3. 1 0
      services/article_history.go
  4. 110 25
      services/wx_user_rai_label.go

+ 2 - 2
models/article.go

@@ -248,7 +248,7 @@ func GetArticleDetailByIdStr(articleIdStr string) (items []*ArticleDetail, err e
 	return
 }
 
-func GetArticlePermission(companyId int) (item *ChartPermissionItemResp, err error) {
+func GetArticlePermission(categoryId int) (item *ChartPermissionItemResp, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT
 			a.chart_permission_name as  permission_name,a.match_type_name
@@ -256,7 +256,7 @@ func GetArticlePermission(companyId int) (item *ChartPermissionItemResp, err err
 			cygx_report_mapping AS a
 			WHERE
 			a.category_id = ? LIMIT  1 `
-	err = o.Raw(sql, companyId).QueryRow(&item)
+	err = o.Raw(sql, categoryId).QueryRow(&item)
 	//_, err = o.Raw(sql, companyId).QueryRows(&item)
 	return
 }

+ 1 - 0
models/wx_user_rai_label.go

@@ -13,6 +13,7 @@ type WxUserRaiLabelRedis struct {
 	SourceType       int       `description:"来源1:搜索关键字标签、2:产业/个股标签(线下活动)、3:产业/个股标签(线下路演)、4:产业/个股标签(线上活动)、5:产业/个股标签(线上路演)、6:销售输入标签、7:产业/个股标签(报告)、8:报告类型标签"`
 	CreateTime       time.Time `description:"创建时间"`
 	RegisterPlatform int       `description:"来源 1小程序,2:网页"`
+	TableName        string    `description:"数据来源的表名"`
 }
 
 type WxUserRaiLabel struct {

+ 1 - 0
services/article_history.go

@@ -155,6 +155,7 @@ func ArticleHistoryStopTime(articleId, stopTime, outType int, user *models.WxUse
 		recordRedis.OutId = int(newId)
 		//recordRedis.CreateTime = time.Now()
 		go PushViewRecordNewRedisData(recordRedis, user.CompanyId)
+		go ArticleWxUserRaiLabelRedisAdd(articleId, user.UserId, record.CreateTime)
 		utils.Rc.Put(key, 1, 2*time.Second)
 	}
 	go ArticleHistoryUserLabelLogAdd(articleId, uid)

+ 110 - 25
services/wx_user_rai_label.go

@@ -28,40 +28,69 @@ func KeyWordsWxUserRaiLabelRedisAdd(sourceId, uid int, label string) (err error)
 	return
 }
 
+// 添加用户阅读文章标签到Redis
+func ArticleWxUserRaiLabelRedisAdd(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: 1, TableName: utils.CYGX_OBJ_ARTICLE, 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("WxUserRaiLabelRedis LPush Err:" + err.Error())
+		}
+	}
+	return
+}
+
 func UpdateWxUserRaiLabelRedis() (err error) {
 	for {
-		//SourceType int       `description:"1:文章阅读、 2产业关注、3:活动到会、4系列关注、5专项调研活动到会。"`
+		//	SourceType       int       `description:"来源1:搜索关键字标签、2:产业/个股标签(线下活动)、3:产业/个股标签(线下路演)、4:产业/个股标签(线上活动)、5:产业/个股标签(线上路演)、6:销售输入标签、7:产业/个股标签(报告)、8:报告类型标签"`
 		utils.Rc.Brpop(utils.WX_USER_RAI_LABEL_KEY, func(b []byte) {
 			var log models.WxUserRaiLabelRedis
 			if err := json.Unmarshal(b, &log); err != nil {
 				fmt.Println("json unmarshal wrong!")
 				go utils.SendAlarmMsg("用户更新相关标签处理Redis队列消息失败:"+err.Error()+string(b), 2)
 			}
-			switch log.SourceType {
-			case 1:
-				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
-			default:
-				fmt.Println(string(b))
-				go utils.SendAlarmMsg("用户更新相关标签处理Redis队列消息失败:"+string(b), 2)
+
+			if log.TableName == "" {
+				switch log.SourceType {
+				case 1:
+					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
+				default:
+					fmt.Println(string(b))
+					go utils.SendAlarmMsg("用户更新相关标签处理Redis队列消息失败:"+string(b), 2)
+				}
+			} else {
+				switch log.TableName {
+				case utils.CYGX_OBJ_ARTICLE:
+					go ArticleWxUserRaiLabelRedisAddReduce(log)
+					fmt.Println("阅读文章")
+				}
 			}
+
 		})
 	}
 }
@@ -103,3 +132,59 @@ func KeyWordsWxUserRaiLabelRedisAddReduce(log models.WxUserRaiLabelRedis) (err e
 	}
 	return
 }
+
+// 7:产业/个股标签(报告)、8:报告类型标签
+func ArticleWxUserRaiLabelRedisAddReduce(log models.WxUserRaiLabelRedis) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg("用户文章阅读更新相关标签,处理Redis队列消息失败:"+err.Error()+fmt.Sprint("articleId", 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
+	}
+	articleDetail, e := models.GetArticleDetailTestById(sourceId)
+	if e != nil {
+		err = errors.New("GetArticleDetailTestById" + e.Error())
+		return
+	}
+	articlePermission, e := models.GetArticlePermission(articleDetail.CategoryId)
+	if e != nil {
+		err = errors.New("GetArticlePermission" + e.Error())
+		return
+	}
+	if articlePermission == nil {
+		err = errors.New("报告权限不存在" + e.Error())
+		return
+	}
+	articlePermissionName := articlePermission.PermissionName
+	matchTypeName := articlePermission.MatchTypeName
+
+	if articlePermissionName == utils.CE_LUE_NAME || articlePermissionName == utils.GU_SHOU_NAME { // 策略、固收的所有报告,以报告类型做标签
+		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 = matchTypeName
+		item.SourceType = 8
+		item.CreateTime = log.CreateTime
+		item.ModifyTime = time.Now()
+		item.RegisterPlatform = log.RegisterPlatform
+		item.TableName = "cygx_article"
+		err = models.AddWxUserRaiLabel(item)
+		if e != nil {
+			err = errors.New("AddWxUserRaiLabel" + e.Error())
+			return
+		}
+	}
+
+	return
+}