Browse Source

Merge branch 'banner_mark'

zwxi 11 months ago
parent
commit
63972fad2e
4 changed files with 62 additions and 6 deletions
  1. 43 4
      controller/public.go
  2. 8 0
      models/response/banner.go
  3. 10 2
      models/tables/banner/query.go
  4. 1 0
      routers/public.go

+ 43 - 4
controller/public.go

@@ -356,7 +356,6 @@ func GetTelAreaList(c *gin.Context) {
 	response.OkData("获取成功", respList, c)
 }
 
-
 // BannerMark banner图埋点
 // @Tags 公共模块
 // @Summary  banner图埋点
@@ -395,7 +394,6 @@ func BannerMark(c *gin.Context) {
 		response.FailMsg("参数有误", "Id错误", c)
 	}
 
-
 	item, err := banner.GetBannerById(req.Id)
 	if err != nil {
 		fmt.Println("GetByUserId:", err.Error())
@@ -444,7 +442,6 @@ func BannerMark(c *gin.Context) {
 	response.Ok("成功", c)
 }
 
-
 // BannerList banner图列表
 // @Tags 公共模块
 // @Summary  banner图列表
@@ -457,11 +454,53 @@ func BannerMark(c *gin.Context) {
 // @Failure 400 {string} string 请输入邮箱地址
 // @Router /banner/list [get]
 func BannerList(c *gin.Context) {
-	list, err := banner.GetBannerList()
+	isHomepage, _ := strconv.Atoi(c.Query("is_homepage"))
+	page, _ := strconv.Atoi(c.Query("page"))
+	limit, _ := strconv.Atoi(c.Query("limit"))
+	cond := " enable = 1 "
+
+	if isHomepage != 1 {
+		cond += " AND id <> 9999"
+	}
+
+	list, err := banner.GetBannerList(cond, page, limit)
 	if err != nil {
 		response.FailMsg("获取失败", "获取banner失败, Err: "+err.Error(), c)
 		return
 	}
 
 	response.OkData("获取成功", list, c)
+}
+
+// BannerHistoryList banner历史图列表
+// @Tags 公共模块
+// @Summary  banner图列表
+// @Description banner图列表
+// @Security ApiKeyAuth
+// @securityDefinitions.basic BasicAuth
+// @Accept  json
+// @Product json
+// @Success 200 {string} string 获取验证码成功
+// @Failure 400 {string} string 请输入邮箱地址
+// @Router /banner_history/list [get]
+func BannerHistoryList(c *gin.Context) {
+	page, _ := strconv.Atoi(c.Query("page"))
+	limit, _ := strconv.Atoi(c.Query("limit"))
+	cond := ""
+	cond += " enable = 0 "
+
+	total, err := banner.GetBannerListCount(cond)
+	if err != nil {
+		response.FailMsg("获取失败", "获取banner总数失败, Err: "+err.Error(), c)
+		return
+	}
+	list, err := banner.GetBannerList(cond, page, limit)
+	if err != nil {
+		response.FailMsg("获取失败", "获取banner失败, Err: "+err.Error(), c)
+		return
+	}
+	var resp respond.BannerRespItem
+	resp.Paging = respond.GetPaging(page, limit, int(total))
+	resp.List = list
+	response.OkData("获取成功", resp, c)
 }

+ 8 - 0
models/response/banner.go

@@ -0,0 +1,8 @@
+package response
+
+import "hongze/hongze_yb/models/tables/banner"
+
+type BannerRespItem struct {
+	List   []*banner.Banner `json:"list"`
+	Paging *PagingItem      `json:"paging"`
+}

+ 10 - 2
models/tables/banner/query.go

@@ -3,8 +3,8 @@ package banner
 import "hongze/hongze_yb/global"
 
 // GetBannerList
-func GetBannerList() (list []*Banner, err error) {
-	err = global.DEFAULT_MYSQL.Where(" enable=1 ").Find(&list).Error
+func GetBannerList(cond string, page, limit int) (list []*Banner, err error) {
+	err = global.DEFAULT_MYSQL.Where(cond).Limit(limit).Offset((page - 1) * limit).Find(&list).Error
 	return
 }
 
@@ -12,4 +12,12 @@ func GetBannerList() (list []*Banner, err error) {
 func GetBannerById(id int) (item *Banner, err error) {
 	err = global.DEFAULT_MYSQL.Where(" id=? ",id).First(&item).Error
 	return
+}
+
+// GetBannerListCount
+func GetBannerListCount(cond string) (total int64, err error) {
+	err = global.DEFAULT_MYSQL.Model(Banner{}).
+		Where(cond).
+		Count(&total).Error
+	return
 }

+ 1 - 0
routers/public.go

@@ -30,6 +30,7 @@ func initPublic(r *gin.Engine) {
 		rGroup.POST("/view_log/update", controller.UpdateViewLog)
 		rGroup.POST("/banner/mark", controller.BannerMark)
 		rGroup.GET("/banner/list", controller.BannerList)
+		rGroup.GET("/banner_history/list", controller.BannerHistoryList)
 	}
 
 	rGroup2 := r.Group("api/public")