Browse Source

添加标签

k.zhang 2 years ago
parent
commit
175e3741ec

+ 54 - 0
apis/bizhi/apis/label.go

@@ -0,0 +1,54 @@
+package apis
+
+import (
+	"duoduo/apis/bizhi/models"
+	"duoduo/models/bizhi"
+	"duoduo/tools/app"
+	"github.com/gin-gonic/gin"
+)
+
+func LabelList(c *gin.Context) {
+	var outData models.LabelListResponse
+	var outDataList []models.LabelListResponse
+	var sqlData bizhi.Label
+
+	labelData, err := sqlData.GetLabelList()
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+
+	for i := 0; i < len(labelData); i++ {
+		var config models.Config
+		config.Content = labelData[i].Label
+		config.Size = "large"
+		config.FontColor = "#04885c"
+		config.Plain = true
+		config.Select = false
+		config.Shape = "square"
+		outData.Config = append(outData.Config, config)
+	}
+	outData.Title = "标签"
+	outDataList = append(outDataList, outData)
+	app.OK(c, outDataList, app.Success)
+
+}
+
+func LabelInert(c *gin.Context) {
+	var inData models.LabelInsertRequest
+
+	err := c.ShouldBindJSON(&inData)
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+	var sqlData bizhi.Label
+	sqlData.Label = inData.Label
+
+	err = sqlData.Insert()
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+	app.OK(c, nil, app.Success)
+}

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

@@ -30,3 +30,42 @@ func RondPicture(c *gin.Context) {
 	}
 	app.OK(c, outData, app.Success)
 }
+
+func PictureLabel(c *gin.Context) {
+
+	inData := bizhi.PictureLabelRequest{}
+	sqlData := mysqlBz.BiZhi{}
+
+	err := c.ShouldBindJSON(&inData)
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+	outData, err := sqlData.GetBiZhiLabel(inData.Label)
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+	outData.Url = outData.Url + "?imageView/1/w/350/h/467"
+	app.OK(c, outData, app.Success)
+
+}
+
+func PictureLabelUpdate(c *gin.Context) {
+	inData := bizhi.PictureLabelUpdateRequest{}
+	sqlData := mysqlBz.BiZhi{}
+
+	err := c.ShouldBindJSON(&inData)
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+	sqlData.ID = inData.Id
+	err = sqlData.BiZhiLabelUpdate(inData.Label)
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+
+	app.OK(c, nil, app.Success)
+}

+ 23 - 0
apis/bizhi/models/label.go

@@ -0,0 +1,23 @@
+package models
+
+//标签列表返回信息
+type LabelListResponse struct {
+	Title  string   `json:"title"`
+	Config []Config `json:"config"`
+}
+type Config struct {
+	Content   string `json:"content"`
+	Size      string `json:"size"`
+	BgColor   string `json:"bgColor"`
+	FontColor string `json:"fontColor"`
+	Plain     bool   `json:"plain"`
+	Select    bool   `json:"select"`
+	Shape     string `json:"shape"`
+	IconName  string `json:"iconName"`
+	IconSize  string `json:"iconSize"`
+	IconColor string `json:"iconColor"`
+}
+
+type LabelInsertRequest struct {
+	Label string `json:"label"`
+}

+ 11 - 8
apis/bizhi/router.go

@@ -9,13 +9,16 @@ import (
 func InitBiZhiRouter(engine *gin.RouterGroup) {
 	v1 := engine.Group("v1")
 	{
-		v1.POST("/upload", apis.Upload)           //下载图片
-		v1.POST("/round", apis.RondPicture)       //随机图片
-		v1.POST("/set.user", apis.OpenIdSet)      //用户注册
-		v1.POST("/get.score", apis.GetUserScore)  // 校验积分
-		v1.POST("/sub.score", apis.SubUserScore)  //+-积分
-		v1.POST("/score.list", apis.ScoreLogList) //积分消费记录
-		v1.POST("/openid.list", apis.GetUserList) //邀请用户列表
-
+		v1.POST("/upload", apis.Upload)                   //下载图片
+		v1.POST("/round", apis.RondPicture)               //随机图片
+		v1.POST("/set.user", apis.OpenIdSet)              //用户注册
+		v1.POST("/get.score", apis.GetUserScore)          // 校验积分
+		v1.POST("/sub.score", apis.SubUserScore)          //+-积分
+		v1.POST("/score.list", apis.ScoreLogList)         //积分消费记录
+		v1.POST("/openid.list", apis.GetUserList)         //邀请用户列表
+		v1.POST("/bizhi.label", apis.PictureLabel)        //壁纸审核
+		v1.POST("/label.list", apis.LabelList)            //标签
+		v1.POST("/label.insert", apis.LabelInert)         //插入标签
+		v1.POST("/bizhi.update", apis.PictureLabelUpdate) //更新标签
 	}
 }

+ 1 - 2
main.go

@@ -3,7 +3,6 @@ package main
 import (
 	"duoduo/conf"
 	"duoduo/database"
-	"duoduo/report"
 	"duoduo/routers"
 	"fmt"
 	"os"
@@ -20,6 +19,6 @@ func main() {
 
 	}
 	database.Setup()
-	report.SysCronStart()
+	//report.SysCronStart()
 	routers.InitRouter()
 }

+ 33 - 0
models/bizhi/label.go

@@ -0,0 +1,33 @@
+package bizhi
+
+import orm "duoduo/database"
+
+type Label struct {
+	ID    int64  `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"` // 主键
+	Label string `gorm:"column:label;type:varchar(50)" json:"label"`                     // 标签
+}
+
+func (m *Label) TableName() string {
+	return "label"
+}
+
+func (m *Label) GetLabelList() ([]Label, error) {
+	var doc []Label
+
+	table := orm.BzMysql.Table(m.TableName())
+
+	if err := table.Select("*").Order("id desc").Find(&doc).Error; err != nil {
+		return nil, err
+	}
+
+	return doc, nil
+}
+
+func (m *Label) Insert() error {
+	result := orm.BzMysql.Table(m.TableName()).Create(&m)
+	if result.Error != nil {
+		err := result.Error
+		return err
+	}
+	return nil
+}

+ 16 - 4
models/bizhi/round_picture.go

@@ -2,11 +2,23 @@ package bizhi
 
 import "duoduo/models/mysqlBz"
 
+//随机获取图片请求参数
 type RoundPictureResponse struct {
 	mysqlBz.BiZhi
-	Cover1 string `json:"Cover1"`
-	Cover string `json:"Cover"`
+	Cover1      string `json:"Cover1"`
+	Cover       string `json:"Cover"`
 	CoverHeight string `json:"CoverHeight"`
-	CoverWidth string `json:"CoverWidth"`
-	Loaded bool `json:"loaded"`
+	CoverWidth  string `json:"CoverWidth"`
+	Loaded      bool   `json:"loaded"`
+}
+
+//图片标签
+type PictureLabelRequest struct {
+	Label string `json:"label"`
+}
+
+//图片标签更新
+type PictureLabelUpdateRequest struct {
+	Id    int    `json:"id"`
+	Label string `json:"label"`
 }

+ 26 - 0
models/mysqlBz/bizhi.go

@@ -2,6 +2,7 @@ package mysqlBz
 
 import (
 	orm "duoduo/database"
+	"duoduo/tools"
 	"math/rand"
 	"time"
 )
@@ -61,3 +62,28 @@ func (o *BiZhi) GetRoundBiZhi() ([]BiZhi, error) {
 
 	return doc, nil
 }
+
+func (o *BiZhi) GetBiZhiLabel(label string) (BiZhi, error) {
+	var doc BiZhi
+	table := orm.BzMysql.Table("bizhi ")
+	if label == "" {
+		table = table.Where("label = '' or label is null")
+	} else {
+		table = table.Where(" label like '%?%'", label)
+	}
+
+	if err := table.Select("*").Order("id desc").Limit(1).Find(&doc).Error; err != nil {
+		return doc, err
+	}
+	return doc, nil
+}
+
+func (o *BiZhi) BiZhiLabelUpdate(label string) error {
+	if err := orm.BzMysql.Table(o.TableName()).Model(&o).Where("id = ? ", o.ID).Updates(
+		map[string]interface{}{
+			"label":       label,
+			"update_time": tools.GetCurrntTimeStr()}).Error; err != nil {
+		return err
+	}
+	return nil
+}