Sfoglia il codice sorgente

图表收藏添加来源记录

xingzai 2 anni fa
parent
commit
97cd3ecbee

+ 16 - 0
models/activity_signup.go

@@ -547,3 +547,19 @@ func AddCygxActivityRestrictSignup(item *CygxActivityRestrictSignup) (err error)
 	_, err = o.Insert(item)
 	return
 }
+
+//获取列表信息根据手机号分组
+func GetCygxActivitySignupByMobileList(condition string) (items []*CygxActivitySignup, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_activity_signup  WHERE  1= 1 ` + condition + `  GROUP BY mobile  `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+//修改用户关注作者的相关信息
+func UpdateCygxActivitySignup(wxUser *WxUserItem) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_activity_signup SET email=?,company_id=?,company_name=?,mobile=?,real_name=? WHERE  user_id=? `
+	_, err = o.Raw(sql, wxUser.Email, wxUser.CompanyId, wxUser.CompanyName, wxUser.Mobile, wxUser.RealName, wxUser.UserId).Exec()
+	return
+}

+ 2 - 2
models/article_collect.go

@@ -68,9 +68,9 @@ type ArticleCollectList struct {
 	SubCategoryName string `description:"二级分类"`
 }
 
-func GetCygxArticleCollectList() (items []*CygxArticleCollect, err error) {
+func GetCygxArticleCollectList(condition string) (items []*CygxArticleCollect, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT * FROM cygx_article_collect GROUP BY user_id  `
+	sql := `SELECT * FROM cygx_article_collect  WHERE 1 =1   ` + condition + ` GROUP BY user_id  `
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }

+ 5 - 5
models/article_department_follow.go

@@ -57,17 +57,17 @@ func GetArticleDepartmentFollowByUid(userId int) (count int, err error) {
 }
 
 //获取列表信息根据手机号分组
-func GetArticleDepartmentFollowByMobileList() (items []*CygxArticleDepartmentFollow, err error) {
+func GetArticleDepartmentFollowByMobileList(condition string) (items []*CygxArticleDepartmentFollow, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT * FROM cygx_article_department_follow GROUP BY mobile  `
+	sql := `SELECT * FROM cygx_article_department_follow  WHERE 1 =1  ` + condition + `  GROUP BY user_id  `
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
 
-//修改用户阅读的相关信息
+//修改用户关注作者的相关信息
 func UpdateCygxArticleDepartmentFollow(wxUser *WxUserItem) (err error) {
 	o := orm.NewOrm()
-	sql := `UPDATE cygx_article_department_follow SET real_name=? WHERE mobile=? `
-	_, err = o.Raw(sql, wxUser.RealName, wxUser.Mobile).Exec()
+	sql := `UPDATE cygx_article_department_follow SET email=?,company_id=?,company_name=?,mobile=?,real_name=? WHERE user_id=? `
+	_, err = o.Raw(sql, wxUser.Email, wxUser.CompanyId, wxUser.CompanyName, wxUser.Mobile, wxUser.RealName, wxUser.UserId).Exec()
 	return
 }

+ 57 - 2
models/chart_collect.go

@@ -17,11 +17,50 @@ type CygxChartCollect struct {
 	RealName    string    `description:"用户实际名称"`
 	SellerName  string    `description:"所属销售"`
 }
+type CygxChartCollectByCygx struct {
+	Id          int       `orm:"column(id);pk"`
+	ChartId     int       `description:"图表ID"`
+	UserId      int       `description:"用户ID"`
+	CreateTime  time.Time `description:"创建时间"`
+	Mobile      string    `description:"手机号"`
+	Email       string    `description:"邮箱"`
+	CompanyId   int       `description:"公司id"`
+	CompanyName string    `description:"公司名称"`
+	RealName    string    `description:"用户实际名称"`
+	SellerName  string    `description:"所属销售"`
+}
 
 //添加收藏信息
 func AddCygxChartCollect(item *CygxChartCollect) (lastId int64, err error) {
-	o := orm.NewOrm()
+	o, err := orm.NewOrm().Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err == nil {
+			o.Commit()
+		} else {
+			o.Rollback()
+		}
+	}()
 	lastId, err = o.Insert(item)
+	if err != nil {
+		return
+	}
+	//添加查研观向来源的记录
+	itemCygx := new(CygxChartCollectByCygx)
+	itemCygx.ChartId = item.ChartId
+	itemCygx.UserId = item.UserId
+	itemCygx.RealName = item.RealName
+	itemCygx.CreateTime = time.Now()
+	itemCygx.Mobile = item.Mobile
+	itemCygx.Email = item.Email
+	itemCygx.CompanyId = item.CompanyId
+	itemCygx.CompanyName = item.CompanyName
+	lastId, err = o.Insert(itemCygx)
+	if err != nil {
+		return
+	}
 	return
 }
 
@@ -30,10 +69,26 @@ type ChartCollectResp struct {
 	CollectCount int `description:"收藏总数"`
 }
 
+//移除
 func RemoveChartCollect(userId, ChartId int) (err error) {
-	o := orm.NewOrm()
+	o, err := orm.NewOrm().Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err == nil {
+			o.Commit()
+		} else {
+			o.Rollback()
+		}
+	}()
 	sql := `DELETE FROM cygx_chart_collect WHERE user_id=? AND chart_id=? `
 	_, err = o.Raw(sql, userId, ChartId).Exec()
+	if err != nil {
+		return
+	}
+	sql = `DELETE FROM cygx_chart_collect_by_cygx WHERE user_id=? AND chart_id=? `
+	_, err = o.Raw(sql, userId, ChartId).Exec()
 	return
 }
 

+ 1 - 0
models/db.go

@@ -107,6 +107,7 @@ func init() {
 		new(CygxActivityAppointment),
 		new(UserTemplateRecord),
 		new(CygxUserInteractionNum),
+		new(CygxChartCollectByCygx),
 	)
 	// 记录ORM查询日志
 	orm.Debug = true

+ 5 - 5
models/industry_fllow.go

@@ -57,17 +57,17 @@ func GetCountCygxIndustryFllowByUid(userId int) (count int, err error) {
 }
 
 //获取列表信息根据手机号分组
-func GetCygxIndustryFllowList() (items []*CygxIndustryFllow, err error) {
+func GetCygxIndustryFllowList(condition string) (items []*CygxIndustryFllow, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT * FROM cygx_industry_fllow GROUP BY mobile  `
+	sql := `SELECT * FROM cygx_industry_fllow  WHERE 1 =1   ` + condition + `  GROUP BY user_id  `
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
 
-//修改用户阅读的相关信息
+//修改用户关注的相关信息
 func UpdateCygxIndustryFllow(wxUser *WxUserItem) (err error) {
 	o := orm.NewOrm()
-	sql := `UPDATE cygx_industry_fllow SET real_name=? WHERE mobile=? `
-	_, err = o.Raw(sql, wxUser.RealName, wxUser.Mobile).Exec()
+	sql := `UPDATE cygx_industry_fllow SET email=?,company_id=?,company_name=?,mobile=?,real_name=? WHERE user_id=? `
+	_, err = o.Raw(sql, wxUser.Email, wxUser.CompanyId, wxUser.CompanyName, wxUser.Mobile, wxUser.RealName, wxUser.UserId).Exec()
 	return
 }

+ 2 - 2
models/search_key_word.go

@@ -40,9 +40,9 @@ func GetSearchKeyWordTop() (items []*CygxSearchKeyWord, err error) {
 	return
 }
 
-func GetCygxSearchKeyWordList() (items []*CygxSearchKeyWord, err error) {
+func GetCygxSearchKeyWordList(condition string) (items []*CygxSearchKeyWord, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT * FROM cygx_search_key_word GROUP BY user_id  `
+	sql := `SELECT * FROM cygx_search_key_word   WHERE 1 = 1 ` + condition + `  GROUP BY user_id  `
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }

+ 11 - 1
models/send_company_user.go

@@ -217,7 +217,9 @@ func GetSendUserList(condition string) (items []*UserJson, err error) {
 }
 
 type WxUserOpLogResp struct {
-	CompanyId int `description:"客户ID"`
+	CompanyId int    `description:"客户ID"`
+	UserId    int    `description:"用户ID"`
+	Mobile    string `description:"用户ID"`
 }
 
 //获取指定时间内更新的用户
@@ -227,3 +229,11 @@ func GetWxUserOpLog(createTime string) (items []*WxUserOpLogResp, err error) {
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
+
+//获取指定时间内被移动的用户
+func GetWxUserOpLogList(createTime string) (items []*WxUserOpLogResp, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT company_id,user_id,mobile FROM wx_user_op_log WHERE  log_type IN ('move') AND create_time >=  '` + createTime + `' AND company_id > 1 GROUP BY user_id `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}

+ 1 - 1
services/task.go

@@ -76,7 +76,7 @@ func Task() {
 		getArticleListByApi := task.NewTask("getArticleListByApi", "0 */60 * * * *", GetArticleListByApi) //通过三方接口获取策略平台上的文章
 		task.AddTask("getArticleListByApi", getArticleListByApi)
 	}
-
+	//UpdateWxUserLabel()
 	//DoCompany()
 	//ActivityAttendanceDetail()
 	//SynchronizationArthistory()//同步原有的阅读记录

+ 169 - 11
services/wx_user.go

@@ -24,7 +24,6 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 		fmt.Println("GetUserRegisterList Err", err)
 		return err
 	}
-	var userIds string
 
 	var interactionNum int //  互动量
 	mapComapnyInteractionNum := make(map[int]int)
@@ -33,7 +32,7 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 	{
 		var chartMobile string
 		var chartItems []*models.CygxChartCollect
-		for k, vUser := range listUser {
+		for _, vUser := range listUser {
 			if vUser.Mobile != "" {
 				mobile := vUser.Mobile
 				chartMobile += mobile + ","
@@ -48,11 +47,8 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 						chartItems = append(chartItems, item)
 					}
 				}
-				fmt.Println(mobile, "长度", len(listChart), "条数", k)
 			}
 		}
-
-		fmt.Println("总长度", len(chartItems))
 		chartMobile = strings.TrimRight(chartMobile, ",")
 		err = models.RemoveChartCollectByMobile(chartMobile)
 		if err != nil {
@@ -65,12 +61,11 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 
 		//处理图表关注后的用户
 		{
-			fmt.Println("处理图表关注后的用户")
+
 			listChartCollect, err := models.GetCygxChartCollectByMobileList()
 			if err != nil {
 				fmt.Println("GetCygxChartCollectByMobileList ,Err" + err.Error())
 			}
-			fmt.Println("长度", len(listChartCollect))
 			for k, v := range listChartCollect {
 				if v.Mobile != "" {
 					user, err := models.GetWxUserItemByMobile(v.Mobile)
@@ -89,6 +84,170 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 		}
 	}
 
+	{
+		//处理 前一天移动之后的用户的公司记录信息
+		updateTime := time.Now().Add(-time.Hour * 25).Format("2006-01-02 15:04:05")
+		listUpdateUser, err := models.GetWxUserOpLogList(updateTime)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			return err
+		}
+		var userIds string
+		var mobiles string
+		if len(listUpdateUser) > 0 {
+			for _, v := range listUpdateUser {
+				userIds += strconv.Itoa(v.UserId) + ","
+				mobiles += "'" + v.Mobile + "',"
+			}
+		}
+		userIds = strings.TrimRight(userIds, ",")
+		mobiles = strings.TrimRight(mobiles, ",")
+
+		//如果用户ID不为空那么就处理这些用户的记录信息
+		if userIds != "" {
+			var condition string
+			condition = ` AND user_id IN (` + userIds + `)`
+
+			//处理用户的文章收藏
+			listCollect, err := models.GetCygxArticleCollectList(condition)
+			if err != nil && err.Error() != utils.ErrNoRow() {
+				fmt.Println("GetAddCygxArticleCollectList ,Err" + err.Error())
+			}
+			if len(listCollect) > 0 {
+				for _, v := range listCollect {
+					user, err := models.GetWxUserItemByUserId(v.UserId)
+					if err != nil && err.Error() != utils.ErrNoRow() {
+						fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
+					}
+					if user != nil {
+						fmt.Println(user.RealName)
+						err = models.UpdateCygxArticleCollect(user)
+						if err != nil {
+							fmt.Println("UpdateCygxArticleCollect ,Err" + err.Error())
+						}
+					}
+				}
+			}
+			//处理用户的文章收藏 end
+
+			//修改用户关注的产业
+			listIndustryFllow, err := models.GetCygxIndustryFllowList(condition)
+			if err != nil {
+				fmt.Println("GetCygxIndustryFllowList ,Err" + err.Error())
+			}
+			fmt.Println("修改用户关注的产业长度", len(listIndustryFllow))
+			for k, v := range listIndustryFllow {
+				if v.Mobile != "" {
+					user, err := models.GetWxUserItemByUserId(v.UserId)
+					if err != nil && err.Error() != utils.ErrNoRow() {
+						fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
+					}
+					if user != nil {
+						fmt.Println(user.RealName, k)
+						err = models.UpdateCygxIndustryFllow(user)
+						if err != nil {
+							fmt.Println("UpdateCygxIndustryFllow ,Err" + err.Error())
+						}
+					}
+				}
+			}
+			//修改用户产业关注的产业end
+
+			//修改用户的阅读记录
+			listArticlePv, err := models.GetArticleHistoryRecordAllByMobileList(condition)
+			if err != nil {
+				fmt.Println("GetArticleHistoryRecordAllByMobileList ,Err" + err.Error())
+			}
+			fmt.Println("修改用户的阅读记录长度", len(listArticlePv))
+			for k, v := range listArticlePv {
+				if v.Mobile != "" {
+					user, err := models.GetWxUserItemByMobile(v.Mobile)
+					if err != nil && err.Error() != utils.ErrNoRow() {
+						fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
+					}
+					if user != nil {
+						fmt.Println(user.RealName, k)
+						err = models.UpdateCygxArticleHistoryRecordAll(user)
+						if err != nil {
+							fmt.Println("UpdateCygxArticleCollect ,Err" + err.Error())
+						}
+					}
+				}
+			}
+			//修改用户的阅读记录end
+
+			//处理用户的搜索记录
+			listSearch, err := models.GetCygxSearchKeyWordList(condition)
+			if err != nil {
+				fmt.Println("GetArticleHistoryRecordAllByMobileList ,Err" + err.Error())
+			}
+
+			for k, v := range listSearch {
+				if v.Mobile != "" {
+					user, err := models.GetWxUserItemByUserId(v.UserId)
+					if err != nil && err.Error() != utils.ErrNoRow() {
+						fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
+					}
+					if user != nil {
+						fmt.Println(user.RealName, k)
+						err = models.UpdateCygxSearchKeyWord(user)
+						if err != nil {
+							fmt.Println("UpdateCygxSearchKeyWord ,Err" + err.Error())
+						}
+					}
+				}
+			}
+
+			// 处理用户的作者关注
+			lisDepartmentF, err := models.GetArticleDepartmentFollowByMobileList(condition)
+			if err != nil {
+				fmt.Println("GetArticleDepartmentFollowByMobileList ,Err" + err.Error())
+				return err
+			}
+			for k, v := range lisDepartmentF {
+				if v.Mobile != "" {
+					user, err := models.GetWxUserItemByUserId(v.UserId)
+					if err != nil && err.Error() != utils.ErrNoRow() {
+						fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
+					}
+					if user != nil {
+						fmt.Println(user.RealName, k)
+						err = models.UpdateCygxArticleDepartmentFollow(user)
+						if err != nil {
+							fmt.Println("UpdateCygxArticleDepartmentFollow ,Err" + err.Error())
+						}
+					}
+				}
+			}
+			// 处理用户的作者关注end
+
+			//如果手机号不为空,则更新用户的报名信息
+			if mobiles != "" {
+				condition = ` AND mobile IN (` + mobiles + `)`
+				listSingUp, err := models.GetCygxActivitySignupByMobileList(condition)
+				if err != nil {
+					fmt.Println("GetCygxChartCollectByMobileList ,Err" + err.Error())
+				}
+				//fmt.Println("更新用户的报名信息长度", len(listSingUp))
+				for _, v := range listSingUp {
+					if v.Mobile != "" {
+						user, err := models.GetWxUserItemByMobile(v.Mobile)
+						if err != nil && err.Error() != utils.ErrNoRow() {
+							fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
+						}
+						if user != nil {
+							err = models.UpdateCygxActivitySignup(user)
+							if err != nil {
+								fmt.Println("UpdateCygxActivitySignup ,Err" + err.Error())
+								//return err
+							}
+						}
+					}
+				}
+			}
+
+		}
+	}
+
 	// 处理用户标签
 	for _, vUser := range listUser {
 		labels, err := models.GetCygxCompanyUserListSplit(strconv.Itoa(vUser.UserId))
@@ -257,6 +416,7 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 
 	//处理用户、机构互动量数据
 	{
+		var userIds string
 		var itemsInteraction []*models.CygxUserInteractionNum
 		mapUserInteraction := make(map[int]int)
 		//获取已经处理记录的用户并记录切片
@@ -326,7 +486,7 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 				fmt.Println("GetCygxCompanyUserUserInteraction Err", err)
 				return err
 			}
-			fmt.Println("处理用户剩余的")
+			//fmt.Println("处理用户剩余的")
 			//处理用户的互动量
 			if len(userUserInteractionList) > 0 {
 				for _, vsplit := range userUserInteractionList {
@@ -341,7 +501,7 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 
 						itemInteraction := new(models.CygxUserInteractionNum)
 						itemInteraction.UserId = int(vsplit.UserId)
-						itemInteraction.ArticleCountNum = vsplit.HistoryNum
+						itemInteraction.ArticleHistoryNum = vsplit.HistoryNum
 						itemInteraction.ArticleCountNum = vsplit.CountNum
 						itemInteraction.ChartCountNum = vsplit.ChartCountNum
 						itemInteraction.IndustryFllowNum = vsplit.IndustryFllowNum
@@ -362,12 +522,10 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 				}
 			}
 		}
-
 		//修改机构互动量信息
 		if len(mapComapnyInteractionNum) > 0 {
 			for k, v := range mapComapnyInteractionNum {
 				err = models.UpdateComapanyInteractionNum(v, k)
-				fmt.Println(k, "修改", v)
 			}
 		}
 		// 批量添加用户互动量信息