Browse Source

过滤禁用的分类

xyxie 11 months ago
parent
commit
94c1204cd9
2 changed files with 21 additions and 8 deletions
  1. 8 4
      controllers/classify.go
  2. 13 4
      models/classify.go

+ 8 - 4
controllers/classify.go

@@ -719,8 +719,6 @@ func (this *ClassifyController) FindByIdClassify() {
 
 // @Title 获取分类列表
 // @Description 获取分类列表
-// @Param   PageSize   query   int  true       "每页数据条数"
-// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
 // @Param   KeyWord   query   string  true       "检索关键词"
 // @Param   CompanyType   query   string  false       "产品类型,枚举值:'ficc','权益';不传默认返回全部"
 // @Param   HideDayWeek   query   int  false       "是否隐藏晨周报"
@@ -736,12 +734,18 @@ func (this *ClassifyController) ListClassify() {
 	keyWord := this.GetString("KeyWord")
 	companyType := this.GetString("CompanyType")
 	hideDayWeek, _ := this.GetInt("HideDayWeek")
+
+	reqEnabled, _ := this.GetInt("Enabled", -1)
 	// 商家不隐藏晨周报
 	if utils.BusinessCode != utils.BusinessCodeRelease {
 		hideDayWeek = 0
 	}
+	enabled := -1
+	if reqEnabled == 1 {
+		enabled = reqEnabled
+	}
 
-	list, err := models.GetClassifyList(keyWord, companyType, hideDayWeek)
+	list, err := models.GetClassifyList(keyWord, companyType, hideDayWeek, enabled)
 	if err != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取失败,Err:" + err.Error()
@@ -784,7 +788,7 @@ func (this *ClassifyController) ListClassify() {
 	}
 
 	// 获取子分类
-	children, e := models.GetClassifyChildByParentIds(parentIds, keyWord)
+	children, e := models.GetClassifyChildByParentIds(parentIds, keyWord, enabled)
 	if e != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取子分类失败"

+ 13 - 4
models/classify.go

@@ -213,7 +213,7 @@ type ClassifyPermissionListResp struct {
 }
 
 // 获取分类列表
-func GetClassifyList(keyWord, companyType string, hideDayWeek int) (items []*ClassifyList, err error) {
+func GetClassifyList(keyWord, companyType string, hideDayWeek, enabled int) (items []*ClassifyList, err error) {
 	sql := ``
 	companyTypeSqlStr := ``
 	if companyType == "ficc" {
@@ -221,6 +221,9 @@ func GetClassifyList(keyWord, companyType string, hideDayWeek int) (items []*Cla
 	} else if companyType == "权益" {
 		companyTypeSqlStr = " AND (id = 40 or parent_id = 40)  "
 	}
+	if enabled == 1 {
+		companyTypeSqlStr += ` AND enabled = 1 `
+	}
 	pars := make([]interface{}, 0)
 	if keyWord != "" {
 		sql = `SELECT * FROM (
@@ -238,6 +241,7 @@ func GetClassifyList(keyWord, companyType string, hideDayWeek int) (items []*Cla
 		if hideDayWeek == 1 {
 			sql += ` AND classify_name <> '晨报' AND classify_name <> '周报' `
 		}
+
 		sql += ` ORDER BY sort ASC, create_time ASC`
 	}
 	pars = append(pars)
@@ -318,7 +322,7 @@ func GetClassifyChild(parentId int, keyWord string) (items []*Classify, err erro
 	return
 }
 
-func GetClassifyChildByParentIds(parentId []int, keyWord string) (items []*Classify, err error) {
+func GetClassifyChildByParentIds(parentId []int, keyWord string, enabled int) (items []*Classify, err error) {
 	parentIdLen := len(parentId)
 	if parentIdLen == 0 {
 		return
@@ -328,11 +332,16 @@ func GetClassifyChildByParentIds(parentId []int, keyWord string) (items []*Class
 	pars := make([]interface{}, 0)
 	pars = append(pars, parentId)
 	if keyWord != "" {
-		sql = `SELECT * FROM classify WHERE parent_id IN (` + utils.GetOrmInReplace(parentIdLen) + `) AND classify_name LIKE ? ORDER BY create_time ASC `
+		sql = `SELECT * FROM classify WHERE parent_id IN (` + utils.GetOrmInReplace(parentIdLen) + `) AND classify_name LIKE ? `
 		pars = append(pars, utils.GetLikeKeyword(keyWord))
 	} else {
-		sql = `SELECT * FROM classify WHERE parent_id IN (` + utils.GetOrmInReplace(parentIdLen) + `) ORDER BY create_time ASC `
+		sql = `SELECT * FROM classify WHERE parent_id IN (` + utils.GetOrmInReplace(parentIdLen) + `) `
+	}
+
+	if enabled == 1 {
+		sql += ` AND enabled=1 `
 	}
+	sql += ` ORDER BY create_time ASC `
 	_, err = o.Raw(sql, pars...).QueryRows(&items)
 
 	return