Browse Source

fix:修改模板消息发送人群,不展示未绑定品种的研报

zqbao 9 months ago
parent
commit
fb1fbb2fbb
4 changed files with 36 additions and 11 deletions
  1. 20 10
      controllers/wechat.go
  2. 4 0
      models/chart_permission.go
  3. 4 1
      models/report.go
  4. 8 0
      models/user.go

+ 20 - 10
controllers/wechat.go

@@ -81,18 +81,18 @@ func (this *WeChatController) SendTemplateMsg() {
 			break
 		}
 	}
-	userList, err := models.GetUserBySubscribe()
-	if err != nil {
-		br.Msg = "获取用户列表失败"
-		br.ErrMsg = "获取用户列表失败,Err:" + err.Error()
-		return
-	}
-	userUnionMap := make(map[int]string)
-	for _, v := range userList {
-		userUnionMap[v.UserId] = v.UnionId
-	}
 	var openIds []*services.OpenIdList
 	if IsPublic {
+		userList, err := models.GetUserBySubscribe()
+		if err != nil {
+			br.Msg = "获取用户列表失败"
+			br.ErrMsg = "获取用户列表失败,Err:" + err.Error()
+			return
+		}
+		userUnionMap := make(map[int]string)
+		for _, v := range userList {
+			userUnionMap[v.UserId] = v.UnionId
+		}
 		var unionIds []string
 		for _, v := range userList {
 			unionIds = append(unionIds, v.UnionId)
@@ -113,6 +113,16 @@ func (this *WeChatController) SendTemplateMsg() {
 	} else {
 		// 给指定用户,发送模板消息
 		// 报告所属的二级品种分类
+		userList, err := models.GetUserBySubscribeAndFormatUser()
+		if err != nil {
+			br.Msg = "获取用户列表失败"
+			br.ErrMsg = "获取用户列表失败,Err:" + err.Error()
+			return
+		}
+		userUnionMap := make(map[int]string)
+		for _, v := range userList {
+			userUnionMap[v.UserId] = v.UnionId
+		}
 		var permissionIds []int
 		for _, v := range reportChartPermissionIdStrs {
 			vv, _ := strconv.Atoi(v)

+ 4 - 0
models/chart_permission.go

@@ -68,6 +68,10 @@ func GetChildChartPermissionListById(id int) (items []*ChartPermission, err erro
 
 // GetChartPermissionListByIds 根据品种ids获取品种权限列表
 func GetChartPermissionIdsByIds(chartPermissionIds []string) (items []*ChartPermission, err error) {
+	// 没有品种权限就返回空
+	if len(chartPermissionIds) == 0 {
+		return
+	}
 	o := orm.NewOrmUsingDB("rddp")
 	sql := `SELECT * FROM chart_permission WHERE enabled=1 `
 	if len(chartPermissionIds) > 0 {

+ 4 - 1
models/report.go

@@ -53,7 +53,10 @@ func GetReportDailyList(startSize, pageSize int) (items []*ReportList, err error
             CASE WHEN DATE(a.modify_time)=DATE(NOW()) THEN 1 ELSE 0 END AS is_current_date
             FROM report AS a
 			INNER JOIN  classify AS b ON a.classify_id_second=b.id
-			WHERE (a.state=2 OR a.state=6) AND DATE(a.modify_time)=DATE(NOW()) 
+			WHERE (a.state=2 OR a.state=6) AND DATE(a.modify_time)=DATE(NOW()) AND a.classify_id_second IN (
+				SELECT DISTINCT classify_id
+				FROM chart_permission_search_key_word_mapping
+			)
 			ORDER BY  a.publish_time DESC LIMIT ?,?  `
 	_, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
 	return

+ 8 - 0
models/user.go

@@ -68,6 +68,14 @@ func GetUserBySubscribe() (user []*User, err error) {
 	return
 }
 
+// GetUserBySubscribeAndFormatUser 查询已经注册和关注公众号的正式用户
+func GetUserBySubscribeAndFormatUser() (user []*User, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM user WHERE is_subscribed=1 AND is_registered=1 AND union_id IS NOT NULL AND status=2`
+	_, err = o.Raw(sql).QueryRows(&user)
+	return
+}
+
 func GetUserById(userId int) (item *User, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT * FROM user WHERE user_id=? `