Browse Source

分类置顶

xingzai 3 years ago
parent
commit
eb55dd093a
5 changed files with 69 additions and 45 deletions
  1. 55 40
      controllers/report.go
  2. 2 2
      models/cygx_industry_top.go
  3. 3 3
      models/db.go
  4. 8 0
      models/industrial_management.go
  5. 1 0
      models/report.go

+ 55 - 40
controllers/report.go

@@ -4,6 +4,7 @@ import (
 	"encoding/json"
 	"fmt"
 	"hongze/hongze_cygx/models"
+	"strings"
 	"time"
 )
 
@@ -70,6 +71,7 @@ func (this *ReportController) IndustryList() {
 		return
 	}
 	for k, v := range list {
+		var analystStr string
 		analystList, err := models.GetIndustrialAnalystAll(v.IndustrialManagementId)
 		if err != nil {
 			br.Msg = "获取信息失败"
@@ -84,6 +86,13 @@ func (this *ReportController) IndustryList() {
 			return
 		}
 		list[k].IndustrialSubjectList = industrialSubjectList
+		if len(analystList) > 0 {
+			for _, v2 := range analystList {
+				analystStr += v2.AnalystName + "/"
+			}
+			analystStr = strings.TrimRight(analystStr, "/")
+		}
+		list[k].Analyst = analystStr
 	}
 	resp := new(models.IndustrialManagementList)
 	resp.List = list
@@ -93,9 +102,9 @@ func (this *ReportController) IndustryList() {
 	br.Data = resp
 }
 
-// @Title 收藏/取消收藏
-// @Description 收藏
-// @Param	request	body webuser.ArticleCollectReq true "type json string"
+// @Title 置顶/取消置顶
+// @Description 置顶
+// @Param	request	body models.CygxIndustryTopRep true "type json string"
 // @Success 200
 // @router /top [post]
 func (this *ReportController) ArticleCollect() {
@@ -111,7 +120,6 @@ func (this *ReportController) ArticleCollect() {
 		return
 	}
 	uid := user.UserId
-	fmt.Println(uid)
 	var req models.CygxIndustryTopRep
 	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
 	if err != nil {
@@ -119,42 +127,49 @@ func (this *ReportController) ArticleCollect() {
 		br.ErrMsg = "参数解析失败,Err:" + err.Error()
 		return
 	}
-	//articleInfo, _ := models.GetArticleInfoById(int64(req.ArticleId))
-	//if articleInfo == nil {
-	//	br.Msg = "文章信息不存在!"
-	//	return
-	//}
-	//count, err := models.GetArticleCollectCount(uid, req.ArticleId)
-	//if err != nil {
-	//	br.Msg = "获取数据失败!"
-	//	br.ErrMsg = "获取数据失败,Err:" + err.Error()
-	//	return
-	//}
-	//resp := new(models.ArticleCollectResp)
-	//if count <= 0 {
-	//	item := new(webuser.AdvisoryArticleCollect)
-	//	item.ArticleId = req.ArticleId
-	//	item.UserId = uid
-	//	item.CreateTime = time.Now()
-	//	_, err = webuser.AddAdvisoryArticleCollect(item)
-	//	if err != nil {
-	//		br.Msg = "收藏失败"
-	//		br.ErrMsg = "收藏失败,Err:" + err.Error()
-	//		return
-	//	}
-	//	br.Msg = "收藏成功"
-	//	resp.Status = 1
-	//} else {
-	//	err = webuser.RemoveArticleCollect(uid, req.ArticleId)
-	//	if err != nil {
-	//		br.Msg = "取消收藏失败"
-	//		br.ErrMsg = "取消收藏失败,Err:" + err.Error()
-	//		return
-	//	}
-	//	br.Msg = "已取消收藏"
-	//	resp.Status = 2
-	//}
-
+	industrialManagementId := req.IndustrialManagementId
+	fmt.Println(industrialManagementId)
+	countIndustrial, err := models.GetIndustrialManagementCount(industrialManagementId)
+	if err != nil {
+		br.Msg = "获取数据失败!"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	if countIndustrial == 0 {
+		br.Msg = "产业不存在!"
+		br.ErrMsg = "产业不存在"
+		return
+	}
+	count, err := models.GetCygxIndustryTop(uid, industrialManagementId)
+	if err != nil {
+		br.Msg = "获取数据失败!"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	resp := new(models.ArticleCollectResp)
+	if count <= 0 {
+		item := new(models.CygxIndustryTop)
+		item.IndustrialManagementId = req.IndustrialManagementId
+		item.UserId = uid
+		item.CreateTime = time.Now()
+		_, err = models.AddCygxIndustryTop(item)
+		if err != nil {
+			br.Msg = "置顶失败"
+			br.ErrMsg = "置顶失败,Err:" + err.Error()
+			return
+		}
+		br.Msg = "置顶成功"
+		resp.Status = 1
+	} else {
+		err = models.RemoveCygxIndustryTop(uid, industrialManagementId)
+		if err != nil {
+			br.Msg = "取消置顶失败"
+			br.ErrMsg = "取消置顶失败,Err:" + err.Error()
+			return
+		}
+		br.Msg = "已取消置顶"
+		resp.Status = 2
+	}
 	br.Ret = 200
 	br.Success = true
 	br.Data = resp

+ 2 - 2
models/cygx_industry_top.go

@@ -36,8 +36,8 @@ func RemoveCygxIndustryTop(userId, industrialManagementId int) (err error) {
 }
 
 //判断这篇文章是否被用户收藏
-func GetCygxIndustryTop(userId, articleId int) (count int, err error) {
+func GetCygxIndustryTop(userId, industrialManagementId int) (count int, err error) {
 	sql := `SELECT COUNT(1) AS count FROM cygx_industry_top WHERE user_id=? AND industrial_management_id=? `
-	err = orm.NewOrm().Raw(sql, userId, articleId).QueryRow(&count)
+	err = orm.NewOrm().Raw(sql, userId, industrialManagementId).QueryRow(&count)
 	return
 }

+ 3 - 3
models/db.go

@@ -1,8 +1,8 @@
 package models
 
 import (
-	"hongze/hongze_cygx/utils"
 	_ "github.com/go-sql-driver/mysql"
+	"hongze/hongze_cygx/utils"
 	"time"
 
 	"rdluck_tools/orm"
@@ -14,7 +14,6 @@ func init() {
 	orm.SetMaxIdleConns("default", 50)
 	orm.SetMaxOpenConns("default", 100)
 
-
 	db, _ := orm.GetDB("default")
 	db.SetConnMaxLifetime(10 * time.Minute)
 
@@ -29,7 +28,7 @@ func init() {
 	orm.SetMaxIdleConns("tactics", 50)
 	orm.SetMaxOpenConns("tactics", 100)
 
-	tacticsDb,_:=orm.GetDB("tactics")
+	tacticsDb, _ := orm.GetDB("tactics")
 	tacticsDb.SetConnMaxLifetime(10 * time.Minute)
 
 	//注册对象
@@ -49,5 +48,6 @@ func init() {
 		new(CygxArticleHistoryRecord),
 		new(CygxSearchKeyWord),
 		new(UserRecord),
+		new(CygxIndustryTop),
 	)
 }

+ 8 - 0
models/industrial_management.go

@@ -31,3 +31,11 @@ func GetIndustrialAnalystAll(IndustrialManagementId int) (items []*IndustrialAna
 	_, err = o.Raw(sql, IndustrialManagementId).QueryRows(&items)
 	return
 }
+
+//获取产业数量
+func GetIndustrialManagementCount(IndustrialManagementId int) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_industrial_management WHERE industrial_management_id=? `
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, IndustrialManagementId).QueryRow(&count)
+	return
+}

+ 1 - 0
models/report.go

@@ -13,6 +13,7 @@ type IndustrialManagement struct {
 	IsRed                  bool                 `description:"是否标记红点"`
 	IsTop                  bool                 `description:"是否置顶"`
 	AnalystList            []*IndustrialAnalyst `description:"分析师列表"`
+	Analyst                string               `description:"分析师"`
 	IndustrialSubjectList  []*IndustrialSubject `description:"标的列表"`
 }