Browse Source

新增热门搜索词接口

rdluck 4 years ago
parent
commit
43c621f826
3 changed files with 64 additions and 1 deletions
  1. 34 0
      controllers/config.go
  2. 24 0
      models/config.go
  3. 6 1
      routers/router.go

+ 34 - 0
controllers/config.go

@@ -0,0 +1,34 @@
+package controllers
+
+import (
+	"hongze/hongze_cygx/models"
+)
+
+type ConfigController struct {
+	BaseAuthController
+}
+
+// @Title 获取搜索推荐词
+// @Description 获取搜索推荐词
+// @Success 200 {object} models.ConfigResp
+// @router /detail [get]
+func (this *ConfigController) BrowseHistoryList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	configCode:="hot_search"
+	detail, err := models.GetConfigByCode(configCode)
+	if err != nil {
+		br.Msg = "获取数据失败"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	resp := new(models.ConfigResp)
+	resp.Item=detail
+	br.Msg = "获取成功!"
+	br.Ret = 200
+	br.Success = true
+	br.Data = resp
+}

+ 24 - 0
models/config.go

@@ -0,0 +1,24 @@
+package models
+
+import (
+	"rdluck_tools/orm"
+	"time"
+)
+
+type CygxConfig struct {
+	ConfigId    int    `json:"-" orm:"column(config_id);pk"`
+	ConfigCode  string `json:"-"`
+	ConfigValue string
+	Remark      string    `json:"-"`
+	CreateTime  time.Time `json:"-"`
+}
+
+func GetConfigByCode(configCode string) (item *CygxConfig, err error) {
+	sql := `SELECT * FROM cygx_config WHERE config_code=? `
+	err = orm.NewOrm().Raw(sql, configCode).QueryRow(&item)
+	return
+}
+
+type ConfigResp struct {
+	Item   *CygxConfig
+}

+ 6 - 1
routers/router.go

@@ -48,6 +48,11 @@ func init() {
 				&controllers.ArticleController{},
 				&controllers.ArticleController{},
 			),
 			),
 		),
 		),
+		beego.NSNamespace("/config",
+			beego.NSInclude(
+				&controllers.ConfigController{},
+			),
+		),
 	)
 	)
 	beego.AddNamespace(ns)
 	beego.AddNamespace(ns)
-}
+}