Bläddra i källkod

查询图表收藏列表接口

xyxie 3 månader sedan
förälder
incheckning
e86c204ffd
2 ändrade filer med 151 tillägg och 0 borttagningar
  1. 142 0
      controllers/chart_collect.go
  2. 9 0
      routers/commentsRouter.go

+ 142 - 0
controllers/chart_collect.go

@@ -3,7 +3,11 @@ package controllers
 import (
 	"eta/eta_forum_hub/models"
 	"eta/eta_forum_hub/models/chart_collect"
+	"eta/eta_forum_hub/services"
 	"eta/eta_forum_hub/utils"
+	"github.com/rdlucklib/rdluck_tools/paging"
+	"strconv"
+	"strings"
 )
 
 // 我的图库
@@ -96,3 +100,141 @@ func (this *ChartCollectController) ClassifyList() {
 	br.Msg = "获取成功"
 	br.Data = resp
 }
+
+// ChartList
+// @Title 收藏-列表接口
+// @Description 收藏-列表接口
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   ChartCollectClassifyIds   query   int  true       "收藏分类id"
+// @Success 200 {object} chart_collect.MyChartListResp
+// @router /chart/list [get]
+func (this *ChartCollectController) ChartList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	collectClassifyIds := this.GetString("CollectClassifyIds")
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	keyword := this.GetString("Keyword")
+
+	userMobile := this.GetString("UserMobile")
+	businessCode := this.GetString("BusinessCode")
+	userTelAreaCode := this.GetString("UserTelAreaCode")
+
+	if userMobile == "" {
+		br.Msg = "请选择用户"
+		return
+	}
+
+	if businessCode == "" {
+		br.Msg = "请选择商户"
+		return
+	}
+
+	// 获取当前的客户信息
+	sysUser, err := models.GetUserByBusinessCodeAndMobile(businessCode, userMobile, userTelAreaCode)
+	if err != nil {
+		if err.Error() == utils.ErrNoRow() {
+			br.Msg = "用户不存在"
+			return
+		}
+		br.Msg = "获取用户信息失败"
+		br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
+		return
+	}
+	var total int64
+
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = paging.StartIndex(currentIndex, pageSize)
+
+	var condition string
+	var pars []interface{}
+
+	chartAdminId := sysUser.UserId
+
+	if collectClassifyIds != "" {
+		classifyIds := strings.Split(collectClassifyIds, ",")
+		if len(classifyIds) == 0 {
+			br.Msg = "请选择正确的分类"
+			return
+		}
+		classifyIdSlice := make([]int, 0)
+		for _, id := range classifyIds {
+			tmp, e := strconv.Atoi(id)
+			if e != nil {
+				br.Msg = "请选择正确的分类"
+				return
+			}
+			classifyIdSlice = append(classifyIdSlice, tmp)
+		}
+		condition += "  AND a.collect_classify_id in (" + utils.GetOrmInReplace(len(classifyIdSlice)) + ") "
+		pars = append(pars, classifyIdSlice)
+	}
+	if keyword != "" {
+		/*if this.Lang == utils.LANG_EN {
+			condition += " AND (b.chart_name_en like ?) "
+		} else {*/
+		condition += " AND (b.chart_name like ?) "
+		//}
+		pars = append(pars, "%"+keyword+"%")
+	}
+
+	condition += " AND (a.user_id = ?)"
+	pars = append(pars, chartAdminId)
+
+	// 获取有权限的分类ID
+	permissionClassifyIds, err := services.GetPermissionClassifyIdByUserId(sysUser.UserId)
+	if err != nil {
+		br.Msg = "获取有权限的分类信息失败"
+		br.ErrMsg = "获取有权限的分类信息失败,Err:" + err.Error()
+		return
+	}
+
+	lenPermissionClassifyIds := len(permissionClassifyIds)
+	if lenPermissionClassifyIds > 0 {
+		condition += ` AND b.chart_classify_id in (` + utils.GetOrmInReplace(lenPermissionClassifyIds) + `) `
+		pars = append(pars, permissionClassifyIds)
+	}
+	total, err = chart_collect.GetChartCollectCountByCondition(condition, pars)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取收藏数据总数失败,Err:" + err.Error()
+		return
+	}
+	page := paging.GetPaging(currentIndex, pageSize, int(total))
+	//获取图表信息
+	list, err := chart_collect.GetChartCollectPageByCondition(condition, pars, startSize, pageSize)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Success = true
+		br.Msg = "获取图表信息失败"
+		br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
+		return
+	}
+	resp := new(chart_collect.ChartCollectListResp)
+	if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
+		items := make([]*chart_collect.ChartCollectView, 0)
+		resp.Paging = page
+		resp.List = items
+		br.Ret = 200
+		br.Success = true
+		br.Data = resp
+		br.Msg = "获取成功"
+		return
+	}
+
+	resp.Paging = page
+	resp.List = list
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 9 - 0
routers/commentsRouter.go

@@ -34,6 +34,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_forum_hub/controllers:ChartCollectController"] = append(beego.GlobalControllerRouter["eta/eta_forum_hub/controllers:ChartCollectController"],
+        beego.ControllerComments{
+            Method: "ChartList",
+            Router: `/chart/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_forum_hub/controllers:ChartCollectController"] = append(beego.GlobalControllerRouter["eta/eta_forum_hub/controllers:ChartCollectController"],
         beego.ControllerComments{
             Method: "ClassifyList",