ziwen 2 лет назад
Родитель
Сommit
69dabf23a1
4 измененных файлов с 233 добавлено и 8 удалено
  1. 29 0
      models/activity_appointment.go
  2. 11 0
      models/user_record.go
  3. 12 2
      models/wx_user_code.go
  4. 181 6
      services/article.go

+ 29 - 0
models/activity_appointment.go

@@ -195,3 +195,32 @@ func GetCygxAppointmentSummaryListBySubjectId(subjectIds string) (item []*CygxAp
 	_, err = o.Raw(sql).QueryRows(&item)
 	return
 }
+
+type CygxAppointment struct {
+	Mobile         string `description:"手机号"`
+	UserId         int `description:"userId"`
+	ActivityName   string `description:"所属销售"`
+	ActivityTypeId int    `description:"活动类型"`
+}
+
+//通过活动ID获取预约纪要的人数列表
+func GetCygxAppointmentSummaryBySubjectId(subjectIds string) (item []*CygxAppointment, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			ap.user_id,
+			ap.mobile,
+			ap.activity_id,
+			a.activity_name 
+		FROM
+			cygx_activity_appointment AS ap
+			INNER JOIN cygx_activity AS a ON a.activity_id = ap.activity_id
+			INNER JOIN cygx_industrial_activity_group_subject AS sg ON sg.activity_id = a.activity_id 
+		WHERE
+			a.active_state = 3
+			AND sg.industrial_subject_id IN (` + subjectIds + `) 
+		GROUP BY
+			ap.mobile,
+			ap.activity_id `
+	_, err = o.Raw(sql).QueryRows(&item)
+	return
+}

+ 11 - 0
models/user_record.go

@@ -152,3 +152,14 @@ func GetOpenIdDetailByMobile(platform int, bindAccount string) (item *OpenIdList
 	err = o.Raw(sql, platform, bindAccount).QueryRow(&item)
 	return
 }
+
+func GetOpenIdByUserIds(ids string) (item []*OpenIdList, err error) {
+	o := orm.NewOrm()
+	var sql string
+	sql = `SELECT cr.open_id,wu.user_id FROM user_record  as u 
+			INNER JOIN cygx_user_record AS cr ON cr.union_id = u.union_id 
+			INNER JOIN wx_user AS wu ON wu.mobile = u.bind_account 
+			WHERE create_platform=4 AND u.user_id IN (`+ids+`)`
+	_,err = o.Raw(sql).QueryRows(&item)
+	return
+}

+ 12 - 2
models/wx_user_code.go

@@ -100,8 +100,7 @@ func GetCygxUserFllowCeLueOpenid(categoryId int) (items []*OpenIdList, err error
 		WHERE
 			r.create_platform = 4
 			AND s.is_refuse = 0
-			AND s.is_subjective = 1
-			AND s.is_objective = 1
+			AND (s.is_subjective = 1 OR s.is_objective = 1)
 			AND f.category_id = ?`
 	_, err = o.Raw(sql, categoryId).QueryRows(&items)
 	return
@@ -129,3 +128,14 @@ func GetCygxXzsChooseSend() (items []*CygxXzsChooseSend, err error) {
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
+
+
+//获取提交过推送规则用户的userId
+func GetCygxXzsChooseSendOpenIdByUserIds(idStr string) (items []*OpenIdList, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT ur.user_id, cr.open_id FROM user_record AS ur
+INNER JOIN cygx_user_record AS cr
+WHERE ur.user_id IN (` + idStr + `) AND create_platform=4 AND ur.union_id=cr.union_id `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}

+ 181 - 6
services/article.go

@@ -1235,9 +1235,23 @@ func DoArticleOnenIdWxTemplateMsg(articleId int) (err error) {
 	}
 	//获取提交过推送规则的用户的 openid
 	mapUserIdChooseSend := make(map[int]int)
+	mapUserIdChooseSendTypeNoPermission := make(map[int]int)
 	chooseSendtList, err := models.GetCygxXzsChooseSend()
 	for _, v := range chooseSendtList {
 		mapUserIdChooseSend[v.UserId] = v.UserId
+		if v.IsRefuse == 1 {
+			continue
+		}
+		//获取选择主客观赛道的用户
+		if reportMapDetail.PermissionType == 1 {
+			if v.IsSubjective == 1 {
+				mapUserIdChooseSendTypeNoPermission[v.UserId] = v.UserId
+			}
+		} else {
+			if v.IsObjective == 1 {
+				mapUserIdChooseSendTypeNoPermission[v.UserId] = v.UserId
+			}
+		}
 	}
 	//已经推送了的openid
 	mapOpenidPushed := make(map[int]string)
@@ -1258,6 +1272,7 @@ func DoArticleOnenIdWxTemplateMsg(articleId int) (err error) {
 	keyword2 := articleInfo.Title
 	keyword3 := articleInfo.PublishDate
 	keyword4 := articleInfo.Abstract
+	mapAlreadySend := make(map[int]int)
 	//如果是策略就按照策略的推送方式来写
 	if reportMapDetail.ChartPermissionName == utils.CE_LUE_NAME {
 		//获取提交过推送规则的用户的 openid
@@ -1278,12 +1293,61 @@ func DoArticleOnenIdWxTemplateMsg(articleId int) (err error) {
 			openIditem.OpenId = v
 			first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
 			keyword1 := "所属赛道:" + industryName
+			mapActivityUserId := make(map[int]string)
+			if articleInfo.IsSummary == 1 {
+				sliceSubjectId, _ := models.GetSubjectIds(articleId)
+				if sliceSubjectId != ""{
+					appointmentList, err := models.GetCygxAppointmentSummaryBySubjectId(sliceSubjectId)
+					if err != nil {
+						fmt.Println("GetCygxAppointmentSummaryListBySubjectId Err:", err.Error())
+						return err
+					}
+					var userIds []string
+					if len(appointmentList) > 0 {
+						for _, v := range appointmentList {
+							//fmt.Println("mapActivityUserId:", v.UserId)
+							userIds = append(userIds, strconv.Itoa(v.UserId))
+							mapActivityUserId[v.UserId] += v.ActivityName + ","
+						}
+						userIdstr := strings.Join(userIds, ",")
+						openIdLists, err := models.GetOpenIdByUserIds(userIdstr)
+						if err != nil {
+							fmt.Println("GetOpenIdByUserIds Err:", err.Error())
+							return err
+						}
+						for _, item := range openIdLists {
+							first := "您预约的调研,有关联的纪要发布/更新了1"
+							keyword1 := industryName
+							openIditem := new(models.OpenIdList)
+							openIditem.OpenId = item.OpenId
+							openIditem.UserId = item.UserId
+							if _, ok := mapAlreadySend[openIditem.UserId]; !ok{
+								SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
+								delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
+								fmt.Println("AlreadySend:", openIditem.UserId)
+								mapAlreadySend[openIditem.UserId] = openIditem.UserId
+							}
+						}
+					}
+				}
+				//fmt.Println("openIditem.UserId:", openIditem.UserId)
+				//if _,ok := mapActivityUserId[openIditem.UserId]; ok{
+				//	first = "您预约的调研,有关联的纪要发布/更新了"
+				//	keyword1 = industryName
+				//	SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
+				//	delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
+				//	mapAlreadySend[openIditem.UserId] = openIditem.UserId
+				//}
+			}
+			_, ok := mapAlreadySend[openIditem.UserId]
 			//如果有权限而且小助手没有提交过信息的 就做正常推送
-			if mapUserIdChooseSend[openIditem.UserId] == 0 {
+			if mapUserIdChooseSend[openIditem.UserId] == 0  && !ok {
+				fmt.Println("1:", articleId)
 				SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
 			}
 			//如果小助手勾选了对应的权限信息 就做正常推送
-			if mapUserIdChooseSend[openIditem.UserId] != 0 && mapUserFllowCeLue[openIditem.UserId] != "" {
+			if mapUserIdChooseSend[openIditem.UserId] != 0 && mapUserFllowCeLue[openIditem.UserId] != ""  && !ok {
+				fmt.Println("2:", articleId)
 				SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
 			}
 		}
@@ -1306,8 +1370,12 @@ func DoArticleOnenIdWxTemplateMsg(articleId int) (err error) {
 					if v.IsSubjective == 1 {
 						mapUserIdChooseSendType[v.UserId] = v.UserId
 					}
-				} else {
-					if v.IsSubjective == 1 {
+				} else if reportMapDetail.PermissionType == 2 {
+					if v.IsObjective == 1 {
+						mapUserIdChooseSendType[v.UserId] = v.UserId
+					}
+				}else {
+					if v.IsSubjective == 1 || v.IsObjective == 1 {
 						mapUserIdChooseSendType[v.UserId] = v.UserId
 					}
 				}
@@ -1317,13 +1385,120 @@ func DoArticleOnenIdWxTemplateMsg(articleId int) (err error) {
 			openIditem.OpenId = v
 			first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
 			keyword1 := "所属赛道:" + industryName
+			mapActivityUserId := make(map[int]string)
+			if articleInfo.IsSummary == 1 {
+				sliceSubjectId, _ := models.GetSubjectIds(articleId)
+				if sliceSubjectId != ""{
+					appointmentList, err := models.GetCygxAppointmentSummaryBySubjectId(sliceSubjectId)
+					if err != nil {
+						fmt.Println("GetCygxAppointmentSummaryListBySubjectId Err:", err.Error())
+						return err
+					}
+					var userIds []string
+					if len(appointmentList) > 0 {
+						for _, v := range appointmentList {
+							//fmt.Println("mapActivityUserId:", v.UserId)
+							userIds = append(userIds, strconv.Itoa(v.UserId))
+							mapActivityUserId[v.UserId] += v.ActivityName + ","
+						}
+						userIdstr := strings.Join(userIds, ",")
+						openIdLists, err := models.GetOpenIdByUserIds(userIdstr)
+						if err != nil {
+							fmt.Println("GetOpenIdByUserIds Err:", err.Error())
+							return err
+						}
+						for _, item := range openIdLists {
+							first := "您预约的调研,有关联的纪要发布/更新了1"
+							keyword1 := industryName
+							openIditem := new(models.OpenIdList)
+							openIditem.OpenId = item.OpenId
+							openIditem.UserId = item.UserId
+							if _, ok := mapAlreadySend[openIditem.UserId]; !ok{
+								SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
+								delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
+								fmt.Println("AlreadySend:", openIditem.UserId)
+								mapAlreadySend[openIditem.UserId] = openIditem.UserId
+							}
+						}
+					}
+				}
+				//fmt.Println("openIditem.UserId:", openIditem.UserId)
+				//if _,ok := mapActivityUserId[openIditem.UserId]; ok{
+				//	first = "您预约的调研,有关联的纪要发布/更新了"
+				//	keyword1 = industryName
+				//	SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
+				//	delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
+				//	mapAlreadySend[openIditem.UserId] = openIditem.UserId
+				//}
+			}
+			
 			//如果有权限而且小助手没有提交过信息的 就做正常推送
-			if mapUserIdChooseSend[openIditem.UserId] == 0 {
+			_, ok := mapAlreadySend[openIditem.UserId]
+			if mapUserIdChooseSend[openIditem.UserId] == 0 && !ok {
 				SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
+				delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
+				mapAlreadySend[openIditem.UserId] = openIditem.UserId
 			}
 			//如果小助手勾选了对应的权限信息 就做正常推送
-			if mapUserIdChooseSend[openIditem.UserId] != 0 && mapOpenidFllow[openIditem.UserId] != "" && mapUserIdChooseSendType[openIditem.UserId] > 0 {
+			if mapUserIdChooseSend[openIditem.UserId] != 0 && mapOpenidFllow[openIditem.UserId] != "" && mapUserIdChooseSendType[openIditem.UserId] > 0 && !ok {
 				SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
+				delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
+				mapAlreadySend[openIditem.UserId] = openIditem.UserId
+			}
+		}
+
+		//获取提交过推送规则的用户的 openid 并推送模版消息
+		openIditem := new(models.OpenIdList)
+		first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
+		keyword1 := "所属赛道:" + industryName
+		//mapActivityUserId := make(map[int]string)
+		//if articleInfo.IsSummary == 1 {
+		//	sliceSubjectId, _ := models.GetSubjectIds(articleId)
+		//	if sliceSubjectId != ""{
+		//		appointmentList, err := models.GetCygxAppointmentSummaryBySubjectId(sliceSubjectId)
+		//		if err != nil {
+		//			fmt.Println("GetCygxAppointmentSummaryListBySubjectId Err:", err.Error())
+		//			return err
+		//		}
+		//		if len(appointmentList) > 0 {
+		//			for _, v := range appointmentList {
+		//				fmt.Println("mapActivityUserId:", v.UserId)
+		//				mapActivityUserId[v.UserId] += v.ActivityName + ","
+		//				first = "您预约的调研,有关联的纪要发布/更新了"
+		//				keyword1 = industryName
+		//				if _, ok := mapAlreadySend[openIditem.UserId]; !ok{
+		//					SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
+		//					delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
+		//					mapAlreadySend[openIditem.UserId] = openIditem.UserId
+		//				}
+		//			}
+		//		}
+		//	}
+		//	//fmt.Println("openIditem.UserId:", openIditem.UserId)
+		//	//if _,ok := mapActivityUserId[openIditem.UserId]; ok{
+		//	//	first = "您预约的调研,有关联的纪要发布/更新了"
+		//	//	keyword1 = industryName
+		//	//	SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
+		//	//	delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
+		//	//	mapAlreadySend[openIditem.UserId] = openIditem.UserId
+		//	//}
+		//}
+		var ids []string
+		for k, _ := range mapUserIdChooseSendTypeNoPermission {
+			ids = append(ids, strconv.Itoa(k))
+		}
+		if len(ids) > 0 {
+			idStr := strings.Join(ids, ",")
+			openidIlist, err := models.GetCygxXzsChooseSendOpenIdByUserIds(idStr)
+			if err != nil {
+				return err
+			}
+			for _, item := range openidIlist {
+				openIditem.OpenId = item.OpenId
+				openIditem.UserId = item.UserId
+				if _, ok := mapAlreadySend[openIditem.UserId]; !ok{
+					SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
+				}
 			}
 		}
 	}