rdluck 4 жил өмнө
parent
commit
99b8c3a226

+ 26 - 4
controllers/home.go

@@ -40,11 +40,35 @@ func (this *HomeController) ListHome() {
 	var condition string
 	var pars []interface{}
 
-	if chartPermissionId > 0 {
+	if chartPermissionId <= 0 {
+		br.Msg = "参数错误"
+		br.Msg = "参数错误,chartPermissionId"
+		return
+	}
+
+	categoryId, err := models.GetCategoryId(chartPermissionId)
 
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.Msg = "获取分类权限信息失败,Err:" + err.Error()
+		return
 	}
+	var total int
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	resp := new(models.HomeListResp)
+	if categoryId == "" {
+		list := make([]*models.HomeArticle, 0)
+		resp.List = list
+		resp.Paging = page
+		br.Ret = 200
+		br.Success = true
+		br.Msg = "获取成功"
+		br.Data = resp
+		return
+	}
+	condition = ` AND category_id IN(` + categoryId + `)`
 
-	total, err := models.GetHomeCount(condition, pars)
+	total, err = models.GetHomeCount(condition, pars)
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.Msg = "获取帖子总数失败,Err:" + err.Error()
@@ -60,8 +84,6 @@ func (this *HomeController) ListHome() {
 	for i := 0; i < lenList; i++ {
 		list[i].Body, _ = services.GetReportContentTextSub(list[i].Body)
 	}
-	page := paging.GetPaging(currentIndex, pageSize, total)
-	resp := new(models.HomeListResp)
 	resp.List = list
 	resp.Paging = page
 	br.Ret = 200

+ 0 - 0
models/cygx_apply_record.go → models/apply_record.go


+ 10 - 0
models/chart_permission.go

@@ -16,4 +16,14 @@ func GetChartPermissionAll() (items []*ChartPermission, err error) {
 	sql:=`SELECT * FROM chart_permission WHERE product_id=2 ORDER BY sort ASC `
 	_,err=o.Raw(sql).QueryRows(&items)
 	return
+}
+
+func GetCategoryId(chartPermissionId int)(categoryId string,err error) {
+	o:=orm.NewOrm()
+	sql:=` SELECT GROUP_CONCAT(a.category_id)AS category_id 
+			FROM cygx_permission_mapping AS a
+			WHERE a.chart_permission_id=? 
+			GROUP BY a.chart_permission_id `
+	_,err=o.Raw(sql,chartPermissionId).QueryRows(&categoryId)
+	return
 }