ziwen 1 vuosi sitten
vanhempi
commit
7ef7b3dbc5
1 muutettua tiedostoa jossa 47 lisäystä ja 10 poistoa
  1. 47 10
      controllers/home.go

+ 47 - 10
controllers/home.go

@@ -639,7 +639,7 @@ func (this *HomeController) ListHomeArtAndChart() {
 
 // @Title 首页列表接口
 // @Description 首页列表接口
-// @Param   TagId   query   int  true       "标签选择"
+// @Param   TagIds   query   string  true       "标签选择"
 // @Param   PageSize   query   int  true       "每页数据条数"
 // @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
 // @Success 200 {object} models.HomeArtAndChartListResp
@@ -659,7 +659,7 @@ func (this *HomeController) NewList() {
 	}
 	pageSize, _ := this.GetInt("PageSize")
 	currentIndex, _ := this.GetInt("CurrentIndex")
-	//tagId, _ := this.GetInt("TagId")
+	tagIds := this.GetString("TagIds")
 
 	var startSize int
 	if pageSize <= 0 {
@@ -682,14 +682,51 @@ func (this *HomeController) NewList() {
 		br.ErrMsg = "GetCountCompanyProductCompanyId,Err:" + err.Error()
 		return
 	}
-	//if tagId > 0 {
-	//	tagInfo, err := models.GetCygxTagByTagId(tagId)
-	//	if err != nil && err.Error() != utils.ErrNoRow() {
-	//		br.Msg = "获取失败"
-	//		br.ErrMsg = "GetCygxTagByTagId,Err:" + err.Error()
-	//		return
-	//	}
-	//}
+	var articleTypes, activityTypes, industries, subjectNames string
+
+	if tagIds != "" {
+		tags := strings.Split(tagIds, ",")
+		for _, tagIdStr := range tags {
+			tagId, err := strconv.Atoi(tagIdStr)
+			if err != nil {
+				br.Msg = "转换失败"
+				br.ErrMsg = "tagid转换失败,Err:" + err.Error()
+				return
+			}
+			tagInfo, err := models.GetCygxTagByTagId(tagId)
+			if err != nil && err.Error() != utils.ErrNoRow() {
+				br.Msg = "获取失败"
+				br.ErrMsg = "GetCygxTagByTagId,Err:" + err.Error()
+				return
+			}
+			activityTypes += tagInfo.ActivityTypes + ","
+			articleTypes += tagInfo.ArticleTypes + ","
+			industries += tagInfo.Industries + ","
+			subjectNames += tagInfo.SubjectNames + ","
+		}
+	}
+	activityTypes = strings.TrimRight(activityTypes,",")
+	articleTypes = strings.TrimRight(articleTypes,",")
+	industries = strings.TrimRight(industries,",")
+	subjectNames = strings.TrimRight(subjectNames,",")
+
+	articleTypesCond := ``
+	if articleTypes != "" {
+		articleTypesCond += ` AND sub_category_name In (`+ activityTypes +`) `
+	}
+	activityTypesCond := ``
+	if activityTypes != "" {
+		activityTypesCond += ` AND sub_category_name In (`+ activityTypes +`) `
+	}
+	industriesCond := ``
+	if industries != "" {
+		industriesCond += ` AND sub_category_name In (`+ activityTypes +`) `
+	}
+	subjectNamesCond := ``
+	if subjectNames != "" {
+		subjectNamesCond += ` AND sub_category_name In (`+ activityTypes +`) `
+	}
+
 	//condition += " AND source = 'article' "
 	//查询近一个月的数据
 	conditionInit = " AND publish_date  >   '" + time.Now().AddDate(0, 0, -30).Format(utils.FormatDateTime) + "'"