Browse Source

新增报告详情

rdluck 4 years ago
parent
commit
8d97580928
2 changed files with 37 additions and 10 deletions
  1. 24 0
      controllers/article.go
  2. 13 10
      models/article.go

+ 24 - 0
controllers/article.go

@@ -3,6 +3,8 @@ package controllers
 import (
 	"encoding/json"
 	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/utils"
+	"strconv"
 	"time"
 )
 
@@ -28,6 +30,7 @@ func (this *ArticleController) Detail() {
 		br.Ret = 408
 		return
 	}
+	uid := user.UserId
 	articleId, _ := this.GetInt("ArticleId")
 	if articleId <= 0 {
 		br.Msg = "参数错误"
@@ -40,6 +43,27 @@ func (this *ArticleController) Detail() {
 		br.ErrMsg = "获取信息失败"
 		return
 	}
+
+	collectCount, err := models.GetArticleCollectCount(uid, articleId)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "判断是否已收藏失败"
+		br.ErrMsg = "判断是否已收藏失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
+	}
+
+	if collectCount > 0 {
+		detail.IsCollect = true
+	}
+
+	interviewApplyCount, err := models.GetArticleInterviewApplyCount(uid, articleId)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "判断是否已申请访谈失败"
+		br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
+	}
+
+	if interviewApplyCount > 0 {
+		detail.IsInterviewApply = true
+	}
+
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"

+ 13 - 10
models/article.go

@@ -30,16 +30,18 @@ type HomeArticle struct {
 }
 
 type ArticleDetail struct {
-	ArticleId      int    `description:"报告id"`
-	Title           string `description:"标题"`
-	TitleEn         string `description:"英文标题 "`
-	UpdateFrequency string `description:"更新周期"`
-	CreateDate      string `description:"创建时间"`
-	PublishDate     string `description:"发布时间"`
-	Body            string `description:"内容"`
-	Abstract        string `description:"摘要"`
-	CategoryName    string `description:"一级分类"`
-	SubCategoryName string `description:"二级分类"`
+	ArticleId        int    `description:"报告id"`
+	Title            string `description:"标题"`
+	TitleEn          string `description:"英文标题 "`
+	UpdateFrequency  string `description:"更新周期"`
+	CreateDate       string `description:"创建时间"`
+	PublishDate      string `description:"发布时间"`
+	Body             string `description:"内容"`
+	Abstract         string `description:"摘要"`
+	CategoryName     string `description:"一级分类"`
+	SubCategoryName  string `description:"二级分类"`
+	IsCollect        bool   `description:"是否收藏:true,已收藏,false:未收藏"`
+	IsInterviewApply bool   `description:"是否申请访谈:true,已申请,false:未申请"`
 }
 
 func GetArticleDetailById(articleId int) (item *ArticleDetail, err error) {
@@ -55,3 +57,4 @@ func GetArticleDetailByIdStr(articleIdStr string) (items []*ArticleDetail, err e
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
+