zwxi 11 ay önce
ebeveyn
işleme
caccd3c899

+ 42 - 1
controller/public.go

@@ -453,11 +453,52 @@ 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"))
+	cond := " enable=1 "
+	if isHomepage != 1 {
+		cond = " AND id <> 9999"
+	}
+	list, err := banner.GetBannerList(cond)
 	if err != nil {
 		response.FailMsg("获取失败", "获取banner失败, Err: "+err.Error(), c)
 		return
 	}
 
 	response.OkData("获取成功", list, c)
+}
+
+// BannerList 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_collection/list [get]
+func BannerCollectionList(c *gin.Context) {
+	cond := " id <> 9999"
+	list, err := banner.GetBannerList(cond)
+	if err != nil {
+		response.FailMsg("获取失败", "获取banner失败, Err: "+err.Error(), c)
+		return
+	}
+	resp := make([]*respond.BannerRespItem,0)
+	nowitem := respond.BannerRespItem{
+		Enable: 1,
+	}
+	historyitem := respond.BannerRespItem{
+		Enable: 0,
+	}
+	for _, v := range list {
+		if v.Enable == 1 {
+			nowitem.List = append(nowitem.List, v)
+		} else {
+			historyitem.List = append(historyitem.List, v)
+		}
+	}
+	resp = append(resp, &nowitem, &historyitem)
+	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
+	Enable int
+}

+ 2 - 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) (list []*Banner, err error) {
+	err = global.DEFAULT_MYSQL.Where(cond).Find(&list).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_collection/list", controller.BannerCollectionList)
 	}
 
 	rGroup2 := r.Group("api/public")