Browse Source

更新用户互动数据改为通过手机号来进行关联同步的方式

xingzai 2 years ago
parent
commit
0ab515c89c

+ 3 - 3
models/activity_signup.go

@@ -556,10 +556,10 @@ func GetCygxActivitySignupByMobileList(condition string) (items []*CygxActivityS
 	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()
+	sql := `UPDATE cygx_activity_signup SET email=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE  mobile=? `
+	_, err = o.Raw(sql, wxUser.Email, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Mobile).Exec()
 	return
 }

+ 8 - 2
models/article_collect.go

@@ -78,7 +78,13 @@ func GetCygxArticleCollectList(condition string) (items []*CygxArticleCollect, e
 //修改用户收藏文章的相关信息
 func UpdateCygxArticleCollect(wxUser *WxUserItem) (err error) {
 	o := orm.NewOrm()
-	sql := `UPDATE cygx_article_collect 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()
+	var sql string
+	if wxUser.Mobile != "" {
+		sql = `UPDATE cygx_article_collect SET email=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE mobile=? `
+		_, err = o.Raw(sql, wxUser.Email, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Mobile).Exec()
+	} else if wxUser.Email != "" {
+		sql = `UPDATE cygx_article_collect SET user_id=?,company_id=?,company_name=?,mobile=?,real_name=? WHERE email=? `
+		_, err = o.Raw(sql, wxUser.UserId, wxUser.CompanyId, wxUser.CompanyName, wxUser.Mobile, wxUser.RealName, wxUser.Email).Exec()
+	}
 	return
 }

+ 9 - 2
models/article_department_follow.go

@@ -67,7 +67,14 @@ func GetArticleDepartmentFollowByMobileList(condition string) (items []*CygxArti
 //修改用户关注作者的相关信息
 func UpdateCygxArticleDepartmentFollow(wxUser *WxUserItem) (err error) {
 	o := orm.NewOrm()
-	sql := `UPDATE cygx_article_department_follow SET email=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE mobile=? `
-	_, err = o.Raw(sql, wxUser.Email, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Mobile).Exec()
+	var sql string
+	if wxUser.Mobile != "" {
+		sql = `UPDATE cygx_article_department_follow SET email=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE mobile=? `
+		_, err = o.Raw(sql, wxUser.Email, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Mobile).Exec()
+	} else if wxUser.Email != "" {
+		sql = `UPDATE cygx_article_department_follow SET mobile=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE email=? `
+		_, err = o.Raw(sql, wxUser.Mobile, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Email).Exec()
+	}
+
 	return
 }

+ 8 - 2
models/article_history_record_newpv.go

@@ -170,7 +170,13 @@ func GetArticleHistoryRecordAllByMobileList(condition string) (items []*CygxArti
 //修改用户阅读的相关信息
 func UpdateCygxArticleHistoryRecordAll(wxUser *WxUserItem) (err error) {
 	o := orm.NewOrm()
-	sql := `UPDATE cygx_article_history_record_all SET email=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE mobile=? `
-	_, err = o.Raw(sql, wxUser.Email, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Mobile).Exec()
+	var sql string
+	if wxUser.Mobile != "" {
+		sql = `UPDATE cygx_article_history_record_all SET email=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE mobile=? `
+		_, err = o.Raw(sql, wxUser.Email, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Mobile).Exec()
+	} else if wxUser.Email != "" {
+		sql = `UPDATE cygx_article_history_record_all SET mobile=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE email=? `
+		_, err = o.Raw(sql, wxUser.Mobile, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Email).Exec()
+	}
 	return
 }

+ 8 - 2
models/industry_fllow.go

@@ -67,7 +67,13 @@ func GetCygxIndustryFllowList(condition string) (items []*CygxIndustryFllow, err
 //修改用户关注的相关信息
 func UpdateCygxIndustryFllow(wxUser *WxUserItem) (err error) {
 	o := orm.NewOrm()
-	sql := `UPDATE cygx_industry_fllow SET email=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE mobile=? `
-	_, err = o.Raw(sql, wxUser.Email, wxUser.CompanyId, wxUser.CompanyName, wxUser.Mobile, wxUser.RealName, wxUser.UserId).Exec()
+	var sql string
+	if wxUser.Mobile != "" {
+		sql = `UPDATE cygx_industry_fllow SET email=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE mobile=? `
+		_, err = o.Raw(sql, wxUser.Email, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Mobile).Exec()
+	} else if wxUser.Email != "" {
+		sql = `UPDATE cygx_industry_fllow SET mobile=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE mobile=? `
+		_, err = o.Raw(sql, wxUser.Mobile, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Email).Exec()
+	}
 	return
 }

+ 8 - 2
models/search_key_word.go

@@ -50,7 +50,13 @@ func GetCygxSearchKeyWordList(condition string) (items []*CygxSearchKeyWord, err
 //修改用户收藏文章的相关信息
 func UpdateCygxSearchKeyWord(wxUser *WxUserItem) (err error) {
 	o := orm.NewOrm()
-	sql := `UPDATE cygx_search_key_word 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()
+	var sql string
+	if wxUser.Mobile != "" {
+		sql = `UPDATE cygx_search_key_word SET email=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE mobile=? `
+		_, err = o.Raw(sql, wxUser.Email, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Mobile).Exec()
+	} else if wxUser.Email != "" {
+		sql = `UPDATE cygx_search_key_word SET mobile=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE email=? `
+		_, err = o.Raw(sql, wxUser.Mobile, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Email).Exec()
+	}
 	return
 }

+ 1 - 1
models/send_company_user.go

@@ -233,7 +233,7 @@ func GetWxUserOpLog(createTime string) (items []*WxUserOpLogResp, err error) {
 //获取指定时间内被移动的用户
 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','add') AND create_time >=  '` + createTime + `' AND company_id > 1 GROUP BY user_id `
+	sql := ` SELECT company_id,user_id,mobile FROM wx_user_op_log WHERE  log_type IN ('move','add') AND create_time >=  '` + createTime + `'   GROUP BY user_id `
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }

+ 5 - 2
services/article.go

@@ -628,9 +628,12 @@ func GetArticleListByApi(cont context.Context) (err error) {
 		return err
 	}
 	for _, v := range listUpdateArticle {
-		go HandleArticleListByApi(v.ArticleId, v.Id)
+		// 这里直接go出去会出现并发,导致文章md5ID唯一索引限制报错
+		err = HandleArticleListByApi(v.ArticleId, v.Id)
+		if err != nil {
+			go utils.SendAlarmMsg("同步策略平台数据到本地数据库失败"+err.Error()+strconv.Itoa(v.ArticleId), 2)
+		}
 	}
-
 	return
 }
 

+ 2 - 2
services/wx_user.go

@@ -123,8 +123,8 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 		//如果用户ID不为空那么就处理这些用户的记录信息
 		if userIds != "" {
 			var condition string
-			condition = ` AND user_id IN (` + userIds + `)`
-
+			//condition = ` AND user_id IN (` + userIds + `)`
+			condition = ` AND mobile IN (` + mobiles + `)`
 			//处理用户的文章收藏
 			listCollect, err := models.GetCygxArticleCollectList(condition)
 			if err != nil && err.Error() != utils.ErrNoRow() {