Pārlūkot izejas kodu

文章详情页添加文章关注收藏字段

xingzai 3 gadi atpakaļ
vecāks
revīzija
8d08b68cdd

+ 20 - 32
controllers/article.go

@@ -84,37 +84,6 @@ func (this *ArticleController) Detail() {
 			goto Loop
 		} else {
 			hasFree = 1
-			// 原有的权限校验 更改于 2021-05-18
-			//articlePermission, err := models.GetArticlePermission(detail.SubCategoryName)
-			//fmt.Println(articlePermission)
-			//fmt.Println(detail.SubCategoryName)
-			//if err != nil {
-			//	br.Msg = "获取信息失败"
-			//	br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
-			//	return
-			//}
-			//if articlePermission == nil {
-			//	br.Msg = "获取信息失败"
-			//	br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
-			//	return
-			//}
-			//for _, p := range articlePermission {
-			//	if strings.Contains(companyPermission, p.PermissionName) {
-			//		hasPermission = 1
-			//		historyRecord := new(models.CygxArticleHistoryRecord)
-			//		historyRecord.UserId = uid
-			//		historyRecord.ArticleId = articleId
-			//		historyRecord.CreateTime = time.Now()
-			//		historyRecord.Mobile = user.Mobile
-			//		historyRecord.Email = user.Email
-			//		historyRecord.CompanyId = user.CompanyId
-			//		historyRecord.CompanyName = user.CompanyName
-			//		go models.AddCygxArticleHistoryRecord(historyRecord)
-			//		break
-			//	} else { //无该行业权限
-			//		hasPermission = 3
-			//	}
-			//}
 			var articlePermissionPermissionName string
 			if detail.CategoryId > 0 {
 				articlePermission, err := models.GetArticlePermission(detail.CategoryId)
@@ -249,8 +218,27 @@ Loop:
 	if hasPermission != 1 {
 		detail.Body = ""
 		detail.BodyText = ""
+	} else {
+		articleFollowdetail, err := models.GetArticleFollowDetail(articleId, uid)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取关注信息失败,Err:" + err.Error()
+			return
+		}
+		detail.FollowNum = articleFollowdetail.DNum
+		detail.CollectionNum = articleFollowdetail.AcNum
+		if articleFollowdetail.MdNum > 0 {
+			detail.IsFollow = true
+		}
+		if detail.IsSummary == 1 {
+			detail.IsBelongSummary = true
+		}
+		if detail.IsReport == 1 {
+			detail.IsBelongReport = true
+		}
 	}
-	fmt.Println(hasPermission)
+
+	fmt.Println(uid)
 	resp := new(models.ArticleDetailResp)
 	resp.HasPermission = hasPermission
 	resp.HasFree = hasFree

+ 11 - 3
controllers/report.go

@@ -541,6 +541,12 @@ func (this *ReportController) Fllow() {
 		return
 	}
 	resp := new(models.CygxIndustryFllowResp)
+
+	countUser, err := models.GetArticleDepartmentFollowByUid(uid)
+
+	if countUser == 0 {
+		resp.GoFollow = true
+	}
 	if count == 0 {
 		item := new(models.CygxIndustryFllow)
 		item.IndustrialManagementId = industrialManagementId
@@ -558,7 +564,6 @@ func (this *ReportController) Fllow() {
 			br.ErrMsg = "操作失败,Err:" + err.Error()
 			return
 		}
-		resp.GoFollow = true
 		resp.Status = 1
 	} else {
 		var doType int
@@ -629,7 +634,7 @@ func (this *ReportController) IndustryListByDepartment() {
 	total, err := models.GetArticleDepartmentCount(condition)
 	page := paging.GetPaging(currentIndex, pageSize, total)
 	//获取作者信息,并排序
-	list, err := models.GetCygxArticleDepartmentList(startSize, pageSize, condition)
+	list, err := models.GetCygxArticleDepartmentList(startSize, pageSize, condition, uid)
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
@@ -699,6 +704,7 @@ func (this *ReportController) FllowDepartment() {
 		br.ErrMsg = "作者ID不存在:" + strconv.Itoa(departmentId)
 		return
 	}
+	countUser, err := models.GetArticleDepartmentFollowByUid(uid)
 	count, err := models.GetArticleDepartmentFollow(uid, departmentId, condition)
 	if err != nil {
 		br.Msg = "获取数据失败!"
@@ -706,6 +712,9 @@ func (this *ReportController) FllowDepartment() {
 		return
 	}
 	resp := new(models.CygxArticleDepartmentFollowResp)
+	if countUser == 0 {
+		resp.GoFollow = true
+	}
 	if count == 0 {
 		item := new(models.CygxArticleDepartmentFollow)
 		item.DepartmentId = departmentId
@@ -724,7 +733,6 @@ func (this *ReportController) FllowDepartment() {
 			return
 		}
 		resp.Status = 1
-		resp.GoFollow = true
 	} else {
 		var doType int
 		condition = ` AND type = 1`

+ 31 - 2
models/article.go

@@ -110,10 +110,12 @@ type ArticleDetail struct {
 	IsResearch           bool   `description:"是否属于研选"`
 	FileLink             string `description:"下载预览链接"`
 	SellerAndMobile      string `description:"销售和手机号"`
-	IsFollow             int    `description:"是否关注,1是,0否"`
-	IsCollection         int    `description:"是否收藏,1是,0否"`
+	IsFollow             bool   `description:"是否关注,1是,0否"`
+	IsBelongSummary      bool   `description:"是否属于纪要库"`
+	IsBelongReport       bool   `description:"是否属于报告"`
 	FollowNum            int    `description:"关注数量"`
 	CollectionNum        int    `description:"收藏数量"`
+	DepartmentId         int    `description:"作者ID"`
 	SellerList           []*SellerRep
 }
 
@@ -381,3 +383,30 @@ func GetCustomArticleId() (item []*ArticleId, err error) {
 	_, err = o.Raw(sql).QueryRows(&item)
 	return
 }
+
+type ArticleFollowDetail struct {
+	DNum   int `description:"作者被关注的数量"`
+	MdNum  int `description:"本人是否关注这个作者"`
+	AcNum  int `description:"文章被收藏的数量"`
+	MacNum int `description:"本人是否收藏这个文章"`
+}
+
+//获取文章被关注被收藏的详情
+func GetArticleFollowDetail(articleId, uid int) (item *ArticleFollowDetail, err error) {
+	//d_num 作者被关注的数量 、 md_num 本人是否关注这个作者 、ac_num 文章被收藏的数量 、 mac_num 本人是否收藏这个文章
+	o := orm.NewOrm()
+	sql := ` SELECT
+	( SELECT count( 1 ) FROM cygx_article_department_follow AS af WHERE af.department_id = art.department_id AND af.type = 1 ) AS d_num,
+	( SELECT count( 1 ) FROM cygx_article_department_follow AS af WHERE af.department_id = art.department_id AND af.type = 1 AND af.user_id = ? ) AS md_num,
+	( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = art.article_id  ) AS ac_num,
+	( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = art.article_id  AND ac.user_id = ? ) AS mac_num
+FROM
+	cygx_article AS art
+	LEFT JOIN cygx_article_department_follow AS af ON af.department_id = art.department_id
+	LEFT JOIN cygx_article_collect AS ac ON ac.article_id = art.article_id 
+WHERE
+	art.article_id = ?
+	GROUP BY art.article_id `
+	err = o.Raw(sql, uid, uid, articleId).QueryRow(&item)
+	return
+}

+ 3 - 3
models/article_department.go

@@ -61,11 +61,11 @@ func GetArticleDepartmentCount(condition string) (count int, err error) {
 }
 
 //列表
-func GetCygxArticleDepartmentList(startSize, pageSize int, condition string) (items []*CygxArticleDepartmentRep, err error) {
+func GetCygxArticleDepartmentList(startSize, pageSize int, condition string, uid int) (items []*CygxArticleDepartmentRep, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT d.*,
 		( SELECT COUNT( 1 ) FROM cygx_article AS a INNER JOIN cygx_article_history_record as h ON h.article_id = a.article_id WHERE  a.department_id = d.department_id  ) AS art_num,
-		( SELECT COUNT( 1 ) FROM cygx_article_department_follow AS f  WHERE f.department_id = d.department_id AND f.user_id = 51561 ) AS follow_num
+		( SELECT COUNT( 1 ) FROM cygx_article_department_follow AS f  WHERE f.department_id = d.department_id AND f.user_id = ? AND f.type = 1 ) AS follow_num
 		FROM
 		cygx_article_department AS d
 		INNER JOIN cygx_article AS a ON a.department_id = d.department_id
@@ -77,7 +77,7 @@ func GetCygxArticleDepartmentList(startSize, pageSize int, condition string) (it
 	sql += ` GROUP BY
 		d.department_id
 		ORDER BY  art_num DESC  LIMIT ?,?`
-	_, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
+	_, err = o.Raw(sql, uid, startSize, pageSize).QueryRows(&items)
 	return
 }
 

+ 7 - 0
models/article_department_follow.go

@@ -47,3 +47,10 @@ func GetArticleDepartmentFollow(userId, departmentId int, condition string) (cou
 	err = orm.NewOrm().Raw(sql, userId, departmentId).QueryRow(&count)
 	return
 }
+
+//获取数量
+func GetArticleDepartmentFollowByUid(userId int) (count int, err error) {
+	sql := `SELECT COUNT(1) AS count FROM cygx_article_department_follow WHERE user_id=? `
+	err = orm.NewOrm().Raw(sql, userId).QueryRow(&count)
+	return
+}

+ 7 - 0
models/industry_fllow.go

@@ -47,3 +47,10 @@ func GetCountCygxIndustryFllow(userId, industrialManagementId int, condition str
 	err = orm.NewOrm().Raw(sql, userId, industrialManagementId).QueryRow(&count)
 	return
 }
+
+//获取数量
+func GetCountCygxIndustryFllowByUid(userId int) (count int, err error) {
+	sql := `SELECT COUNT(1) AS count FROM cygx_industry_fllow WHERE user_id=? `
+	err = orm.NewOrm().Raw(sql, userId).QueryRow(&count)
+	return
+}