ziwen 1 year ago
parent
commit
0381e597bf
2 changed files with 35 additions and 8 deletions
  1. 15 8
      controllers/home.go
  2. 20 0
      models/article.go

+ 15 - 8
controllers/home.go

@@ -712,22 +712,29 @@ func (this *HomeController) NewList() {
 
 	articleTypesCond := ``
 	if articleTypes != "" {
-		articleTypesCond += ` AND sub_category_name In (`+ activityTypes +`) OR type_name IN (`+ activityTypes +`)  OR article_type_name IN (`+ activityTypes +`) `
-	}
-	activityTypesCond := ``
-	if activityTypes != "" {
-		activityTypesCond += ` AND sub_category_name In (`+ activityTypes +`) `
+		articleTypesCond += ` AND art.sub_category_name In (`+ activityTypes +`) `
 	}
+	//activityTypesCond := ``
+	//if activityTypes != "" {
+	//	activityTypesCond += ` AND sub_category_name In (`+ activityTypes +`) `
+	//}
 	industriesCond := ``
 	if industries != "" {
-		industriesCond += ` AND cygx_industrial_article_group_management In (`+ activityTypes +`) `
+		industriesCond += ` AND sub_category_name In (`+ activityTypes +`) `
 	}
 	subjectNamesCond := ``
 	if subjectNames != "" {
-		subjectNamesCond += ` AND cygx_industrial_article_group_subject In (`+ activityTypes +`) `
+		subjectNamesCond += ` AND sub_category_name In (`+ activityTypes +`) `
+	}
+
+	articleIntIds, err := models.GetCygxCygxArticleListByCondition(articleTypesCond, industriesCond, subjectNamesCond)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取活动权限数据失败,Err:" + err.Error()
+		return
 	}
 
-	//condition += " AND source = 'article' "
+	condition += ` OR (source = 'article' AND source_id IN (` + articleIntIds + `) `
 	//查询近一个月的数据
 	conditionInit = " AND publish_date  >   '" + time.Now().AddDate(0, 0, -30).Format(utils.FormatDateTime) + "'"
 	if user.CompanyId <= 1 || totalRai == 0 {

+ 20 - 0
models/article.go

@@ -753,3 +753,23 @@ 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_subject  AS asm ON asm.cygx_article_id = art.id `
+	}
+	if subjectNamesCond != ""{
+		sql += ` INNER JOIN cygx_industrial_article_group_subject  AS asm ON asm.cygx_article_id = art.id `
+	}
+	sql += ` WHERE 1=1 `
+
+	sql += articleTypesCond + industriesCond + subjectNamesCond
+
+	err = o.Raw(sql).QueryRow(&ids)
+	return
+}