rdluck hace 4 años
padre
commit
5939f50d4d
Se han modificado 3 ficheros con 41 adiciones y 16 borrados
  1. 31 14
      controllers/article.go
  2. 5 2
      controllers/base_auth.go
  3. 5 0
      models/article.go

+ 31 - 14
controllers/article.go

@@ -5,6 +5,7 @@ import (
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/utils"
 	"strconv"
+	"strings"
 	"time"
 )
 
@@ -15,7 +16,7 @@ type ArticleController struct {
 // @Title 获取报告详情
 // @Description 获取报告详情接口
 // @Param   ArticleId   query   int  true       "报告ID"
-// @Success 200 {object} models.ArticleDetail
+// @Success 200 {object} models.ArticleDetailResp
 // @router /detail [get]
 func (this *ArticleController) Detail() {
 	br := new(models.BaseResponse).Init()
@@ -65,33 +66,49 @@ func (this *ArticleController) Detail() {
 	if interviewApplyCount > 0 {
 		detail.IsInterviewApply = true
 	}
-	var status int
-
-
+	hasPermission := 2
+	articlePermission, err := models.GetArticlePermission(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:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
+		return
+	}
 	//GetCompanyPermission
-	companyPermission,err:=models.GetCompanyPermission(user.CompanyId)
-	if err!=nil {
+	companyPermission, err := models.GetCompanyPermission(user.CompanyId)
+	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
 		return
 	}
-
-	//新增浏览记录
-	{
+	if strings.Contains(companyPermission, articlePermission.PermissionName) {
+		hasPermission = 1
+	}
+	if hasPermission == 1 {
+		//新增浏览记录
 		record := new(models.CygxArticleViewRecord)
 		record.UserId = uid
 		record.ArticleId = articleId
 		record.CreateTime = time.Now()
-		record.Mobile=user.Mobile
-		record.Email=user.Email
-		record.CompanyId=user.CompanyId
-		record.CompanyName=user.CompanyName
+		record.Mobile = user.Mobile
+		record.Email = user.Email
+		record.CompanyId = user.CompanyId
+		record.CompanyName = user.CompanyName
 		go models.AddCygxArticleViewRecord(record)
+	} else {
+		detail.Body = ""
 	}
+	resp := new(models.ArticleDetailResp)
+	resp.HasPermission = hasPermission
+	resp.Detail = detail
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"
-	br.Data = detail
+	br.Data = resp
 }
 
 // @Title 收藏

+ 5 - 2
controllers/base_auth.go

@@ -22,7 +22,7 @@ func init() {
 
 type BaseAuthController struct {
 	beego.Controller
-	User *models.WxUserItem
+	User  *models.WxUserItem
 	Token string
 }
 
@@ -34,7 +34,10 @@ func (this *BaseAuthController) Prepare() {
 	if method != "HEAD" {
 		if method == "POST" || method == "GET" {
 			authorization := this.Ctx.Input.Header("Authorization")
-			this.Token=authorization
+			if authorization == "" {
+				authorization = this.GetString("Authorization")
+			}
+			this.Token = authorization
 			if authorization == "" {
 				this.JSON(models.BaseResponse{Ret: 408, Msg: "请重新授权!", ErrMsg: "请重新授权:Token is empty or account is empty"}, false, false)
 				this.StopRun()

+ 5 - 0
models/article.go

@@ -67,3 +67,8 @@ func GetArticlePermission(categoryName string) (item *ChartPermission, err error
 	err = o.Raw(sql, categoryName).QueryRow(&item)
 	return
 }
+
+type ArticleDetailResp struct {
+	Detail        *ArticleDetail
+	HasPermission int `description:"1:有权限,2:无权限"`
+}