Browse Source

展示组图

k.zhang 2 years ago
parent
commit
3538d863ef
4 changed files with 57 additions and 0 deletions
  1. 20 0
      apis/bizhi/apis/round_picture.go
  2. 1 0
      apis/bizhi/router.go
  3. 6 0
      models/bizhi/round_picture.go
  4. 30 0
      models/mysqlBz/bizhi.go

+ 20 - 0
apis/bizhi/apis/round_picture.go

@@ -69,3 +69,23 @@ func PictureLabelUpdate(c *gin.Context) {
 
 	app.OK(c, nil, app.Success)
 }
+
+func PictureGroup(c *gin.Context) {
+	inData := bizhi.PictureGroupRequest{}
+	sqlData := mysqlBz.BiZhi{}
+	err := c.ShouldBindJSON(&inData)
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+
+	sqlData.Label = inData.Label
+	sqlData.ID = inData.Id
+	data, err := sqlData.BiZhiGroup(sqlData.Label)
+	if err != nil {
+		app.Error(c, 500, err, err.Error())
+		return
+	}
+	app.OK(c, data, app.Success)
+
+}

+ 1 - 0
apis/bizhi/router.go

@@ -20,5 +20,6 @@ func InitBiZhiRouter(engine *gin.RouterGroup) {
 		v1.POST("/label.list", apis.LabelList)            //标签
 		v1.POST("/label.insert", apis.LabelInert)         //插入标签
 		v1.POST("/bizhi.update", apis.PictureLabelUpdate) //更新标签
+		v1.POST("/bizhi.group", apis.PictureGroup)        //获取组图
 	}
 }

+ 6 - 0
models/bizhi/round_picture.go

@@ -22,3 +22,9 @@ type PictureLabelUpdateRequest struct {
 	Id    int    `json:"id"`
 	Label string `json:"label"`
 }
+
+//图片id
+type PictureGroupRequest struct {
+	Id    int    `json:"id"`
+	Label string `json:"label"`
+}

+ 30 - 0
models/mysqlBz/bizhi.go

@@ -87,3 +87,33 @@ func (o *BiZhi) BiZhiLabelUpdate(label string) error {
 	}
 	return nil
 }
+
+func (o *BiZhi) BiZhiGroup(label string) ([]BiZhi, error) {
+	var doc []BiZhi
+	var data []BiZhi
+	var bizhi BiZhi
+	table := orm.BzMysql.Table("bizhi ").Where("label = ?", label)
+
+	if err := table.Select("*").Order("id desc").Limit(30).Find(&doc).Error; err != nil {
+		return doc, err
+	}
+
+	for i := 0; i < len(doc); i++ {
+		if doc[i].ID == o.ID {
+			bizhi.Url = doc[i].Url
+			bizhi.ID = doc[i].ID
+			bizhi.Label = doc[i].Label
+		}
+	}
+	data = append(data, bizhi)
+	for i := 0; i < len(doc); i++ {
+		if doc[i].ID == o.ID {
+			continue
+		} else {
+			data = append(data, doc[i])
+		}
+
+	}
+
+	return data, nil
+}