ziwen vor 1 Jahr
Ursprung
Commit
307ba6838a
2 geänderte Dateien mit 80 neuen und 2 gelöschten Zeilen
  1. 58 2
      controllers/home.go
  2. 22 0
      models/article.go

+ 58 - 2
controllers/home.go

@@ -265,7 +265,7 @@ func (this *MobileHomeController) NewList() {
 	//uid := user.UserId
 	pageSize, _ := this.GetInt("PageSize")
 	currentIndex, _ := this.GetInt("CurrentIndex")
-	//tagIds := this.GetString("TagIds")
+	tagIds := this.GetString("TagIds")
 
 	var startSize int
 	if pageSize <= 0 {
@@ -282,6 +282,62 @@ func (this *MobileHomeController) NewList() {
 	var pars []interface{}
 	var total int
 	resp := new(models.HomeResourceDataListNewResp)
+
+	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 art.sub_category_name In (`+ articleTypes +`) `
+	}
+	//activityTypesCond := ``
+	//if activityTypes != "" {
+	//	activityTypesCond += ` AND sub_category_name In (`+ activityTypes +`) `
+	//}
+	industriesCond := ``
+	if industries != "" {
+		industriesCond += ` AND im.industry_name In (`+ industries +`) `
+	}
+	subjectNamesCond := ``
+	if subjectNames != "" {
+		subjectNamesCond += ` AND is.subject_name In (`+ subjectNames +`) `
+	}
+
+	articleIntIds, err := models.GetCygxCygxArticleListByCondition(articleTypesCond, industriesCond, subjectNamesCond)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取活动权限数据失败,Err:" + err.Error()
+		return
+	}
+
+	condition += ` OR (source = 'article' AND source_id IN (` + articleIntIds + `) `
+
 	//查询近一个月的数据
 	conditionInit = " AND publish_date  >   '" + time.Now().AddDate(0, 0, -30).Format(utils.FormatDateTime) + "'"
 	//conditionInit += `  AND source IN ('newchart')`
@@ -335,7 +391,7 @@ func (this *MobileHomeController) NewList() {
 			pars = append(pars, activityspecialIds)
 		}
 	}
-	total, err := models.GetResourceDataCount(condition, pars)
+	total, err = models.GetResourceDataCount(condition, pars)
 	if err != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取数据失败,Err:" + err.Error()

+ 22 - 0
models/article.go

@@ -325,3 +325,25 @@ func GetCygxArticleCount(condition string, pars []interface{}) (count int, err e
 	err = o.Raw(sqlCount, pars).QueryRow(&count)
 	return
 }
+
+// 列表
+func GetCygxCygxArticleListByCondition(articleTypesCond, industriesCond, subjectNamesCond string) (ids string, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT GROUP_CONCAT(DISTINCT art.article_id SEPARATOR ',') AS ids FROM cygx_article as art `
+
+
+	if industriesCond != ""{
+		sql += ` INNER JOIN cygx_industrial_article_group_management  AS iam ON iam.cygx_article_id = art.id 
+				INNER JOIN cygx_industrial_management AS im ON im.industrial_management_id=iam.industrial_management_id  `
+	}
+	if subjectNamesCond != ""{
+		sql += ` INNER JOIN cygx_industrial_article_group_subject  AS ias ON ias.cygx_article_id = art.id 
+				INNER JOIN cygx_industrial_subject AS is ON is.industrial_subject_id=ias.industrial_subject_id  `
+	}
+	sql += ` WHERE 1=1 `
+
+	sql += articleTypesCond + industriesCond + subjectNamesCond
+
+	err = o.Raw(sql).QueryRow(&ids)
+	return
+}