xingzai 3 жил өмнө
parent
commit
9a2fa36f50

+ 70 - 0
controllers/report.go

@@ -1,7 +1,10 @@
 package controllers
 
 import (
+	"encoding/json"
+	"fmt"
 	"hongze/hongze_cygx/models"
+	"time"
 )
 
 //报告
@@ -89,3 +92,70 @@ func (this *ReportController) IndustryList() {
 	br.Msg = "获取成功"
 	br.Data = resp
 }
+
+// @Title 收藏/取消收藏
+// @Description 收藏
+// @Param	request	body webuser.ArticleCollectReq true "type json string"
+// @Success 200
+// @router /top [post]
+func (this *ReportController) ArticleCollect() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请重新登录"
+		br.Ret = 408
+		return
+	}
+	uid := user.UserId
+	fmt.Println(uid)
+	var req models.CygxIndustryTopRep
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		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
+	//}
+
+	br.Ret = 200
+	br.Success = true
+	br.Data = resp
+}

+ 43 - 0
models/cygx_industry_top.go

@@ -0,0 +1,43 @@
+package models
+
+import (
+	"rdluck_tools/orm"
+	"time"
+)
+
+type CygxIndustryTop struct {
+	Id                     int       `orm:"column(id);pk"`
+	IndustrialManagementId int       `description:"产业D"`
+	UserId                 int       `description:"用户ID"`
+	CreateTime             time.Time `description:"创建时间"`
+}
+
+type CygxIndustryTopRep struct {
+	IndustrialManagementId int `description:"产业D"`
+}
+
+//添加收藏信息
+func AddCygxIndustryTop(item *CygxIndustryTop) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+type CygxIndustryTopResp struct {
+	Status       int `description:"1:收藏,2:取消收藏"`
+	CollectCount int `description:"收藏总数"`
+}
+
+func RemoveCygxIndustryTop(userId, industrialManagementId int) (err error) {
+	o := orm.NewOrm()
+	sql := `DELETE FROM cygx_industry_top WHERE user_id=? AND industrial_management_id=? `
+	_, err = o.Raw(sql, userId, industrialManagementId).Exec()
+	return
+}
+
+//判断这篇文章是否被用户收藏
+func GetCygxIndustryTop(userId, articleId 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)
+	return
+}

+ 1 - 0
models/report.go

@@ -11,6 +11,7 @@ type IndustrialManagement struct {
 	LayoutTime             string               `description:"布局时间"`
 	UpdateTime             string               `description:"更新时间"`
 	IsRed                  bool                 `description:"是否标记红点"`
+	IsTop                  bool                 `description:"是否置顶"`
 	AnalystList            []*IndustrialAnalyst `description:"分析师列表"`
 	IndustrialSubjectList  []*IndustrialSubject `description:"标的列表"`
 }