Преглед изворни кода

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

zhangchuanxing пре 2 месеци
родитељ
комит
eaba18ca58
6 измењених фајлова са 170 додато и 0 уклоњено
  1. 1 0
      models/db.go
  2. 61 0
      models/wx_user_rai_label.go
  3. 1 0
      services/keyword.go
  4. 1 0
      services/task.go
  5. 105 0
      services/wx_user_rai_label.go
  6. 1 0
      utils/constants.go

+ 1 - 0
models/db.go

@@ -196,6 +196,7 @@ func init() {
 		new(CygxActivitySpecialPermissionPoints),
 		new(time_line.CygxGushouTimeLineHistory),
 		new(CygxXzsChooseSend),
+		new(WxUserRaiLabel),
 	)
 
 	initOrder()      // 订单模块

+ 61 - 0
models/wx_user_rai_label.go

@@ -0,0 +1,61 @@
+package models
+
+import (
+	"fmt"
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type WxUserRaiLabelRedis struct {
+	UserId           int       `description:"用户ID"`
+	SourceId         int       `description:"资源ID"`
+	Label            string    `description:"标签内容"`
+	SourceType       int       `description:"来源1:搜索关键字标签、2:产业/个股标签(线下活动)、3:产业/个股标签(线下路演)、4:产业/个股标签(线上活动)、5:产业/个股标签(线上路演)、6:销售输入标签、7:产业/个股标签(报告)、8:报告类型标签"`
+	CreateTime       time.Time `description:"创建时间"`
+	RegisterPlatform int       `description:"来源 1小程序,2:网页"`
+}
+
+type WxUserRaiLabel struct {
+	RaiLabelId       int       `orm:"column(rai_label_id);pk"`
+	UserId           int       `description:"用户ID"`
+	RealName         string    `description:"用户实际名称"`
+	Mobile           string    `description:"手机号"`
+	Email            string    `description:"邮箱"`
+	CompanyId        int       `description:"公司id"`
+	CompanyName      string    `description:"公司名称"`
+	Label            string    `description:"标签内容"`
+	SourceId         int       `description:"来源ID"`
+	SourceType       int       `description:"来源1:搜索关键字标签、2:产业/个股标签(线下活动)、3:产业/个股标签(线下路演)、4:产业/个股标签(线上活动)、5:产业/个股标签(线上路演)、6:销售输入标签、7:产业/个股标签(报告)、8:报告类型标签"`
+	SysUserId        int       `description:"创建人id"`
+	SysUserRealName  string    `description:"创建人名称"`
+	CreateTime       time.Time `description:"创建时间"`
+	ModifyTime       time.Time `description:"更新时间"`
+	RegisterPlatform int       `description:"来源 1小程序,2:网页"`
+	TableName        string    `description:"数据来源的表名"`
+}
+
+// 添加
+func AddWxUserRaiLabel(item *WxUserRaiLabel) (err error) {
+	o, err := orm.NewOrm().Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		fmt.Println(err)
+		if err == nil {
+			o.Commit()
+		} else {
+			o.Rollback()
+		}
+	}()
+
+	//删除原有数据
+	sql := ` DELETE FROM wx_user_rai_label WHERE user_id = ? AND label = ?  `
+	_, err = o.Raw(sql, item.UserId, item.Label).Exec()
+	if err != nil {
+		return
+	}
+
+	_, err = o.Insert(item)
+	return
+}

+ 1 - 0
services/keyword.go

@@ -35,6 +35,7 @@ func AddSearchKeyWord(user *models.WxUserItem, keyWord string, source int) (err
 	_, err = models.AddSearchKeyWord(keyWordItem)
 	go AddUserSearchLog(user, keyWord, source)
 	go SearchKeywordUserRmind(user, keyWord)
+	go KeyWordsWxUserRaiLabelRedisAdd(0, user.UserId, keyWord)
 	////一分钟之内的相同搜索词不重复记录
 	//setNX := utils.Rc.SetNX(cacheKey, keyWord, time.Minute*1)
 	//if !setNX {

+ 1 - 0
services/task.go

@@ -183,6 +183,7 @@ func Task() {
 	go YanXuanActivityPointsBillReduce()                    // 处理研选活动扣点
 	go UpdateArticleByRedis()                               // 处理策略平台同步过来的文章
 	go UpdateIndustrialManagementTimeLineDateList3ByRedis() // 处理产业管理时间线相关内容的数据
+	go UpdateWxUserRaiLabelRedis()                          // 处理用户标签队列消息CRM_16.5
 
 	//GetCygxActivityAttendanceDetail()
 	//CreateIndexNameArticleHistory()

+ 105 - 0
services/wx_user_rai_label.go

@@ -0,0 +1,105 @@
+package services
+
+import (
+	"encoding/json"
+	"errors"
+	"fmt"
+	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/utils"
+	"time"
+)
+
+// 添加用户搜索标签到Redis
+func KeyWordsWxUserRaiLabelRedisAdd(sourceId, uid int, label string) (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, Label: label, CreateTime: time.Now(), 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专项调研活动到会。"`
+		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)
+			}
+		})
+	}
+}
+
+// 1:搜索关键词
+func KeyWordsWxUserRaiLabelRedisAddReduce(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
+	label := log.Label
+	if userId == 0 {
+		return
+	}
+	wxUser, e := models.GetWxUserItemByUserId(userId)
+	if e != nil {
+		err = errors.New("GetWxUserItemByUserId" + e.Error())
+		return
+	}
+	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 = label
+	item.SourceType = log.SourceType
+	item.CreateTime = log.CreateTime
+	item.ModifyTime = time.Now()
+	item.RegisterPlatform = log.RegisterPlatform
+	err = models.AddWxUserRaiLabel(item)
+	if e != nil {
+		err = errors.New("AddWxUserRaiLabel" + e.Error())
+		return
+	}
+	return
+}

+ 1 - 0
utils/constants.go

@@ -143,6 +143,7 @@ const (
 
 const (
 	SHANG_HAI_CRM_API_TOKEN = "SHANG_HAI_CRM_API_TOKEN"
+	WX_USER_RAI_LABEL_KEY   = "WX_USER_RAI_LABEL_KEY" //用户列表标签key
 )
 
 // 邀请机构标识