Browse Source

报告详情接口新增权限字段

hsun 11 hours ago
parent
commit
2247718524
4 changed files with 42 additions and 3 deletions
  1. 26 0
      controllers/base_common.go
  2. 14 2
      controllers/report.go
  3. 1 0
      models/report.go
  4. 1 1
      models/response/report.go

+ 26 - 0
controllers/base_common.go

@@ -14,6 +14,8 @@ import (
 
 type BaseCommonController struct {
 	web.Controller
+	User    *models.UsersItem
+	Session *models.WxSession
 }
 
 func (c *BaseCommonController) Prepare() {
@@ -25,6 +27,30 @@ func (c *BaseCommonController) Prepare() {
 		requestBody, _ = url.QueryUnescape(string(c.Ctx.Input.RequestBody))
 	}
 
+	if method == "POST" || method == "GET" {
+		authorization := c.Ctx.Input.Header("authorization")
+		if authorization == "" {
+			authorization = c.Ctx.Input.Header("Authorization")
+		}
+		if authorization != "" {
+			token := authorization
+			session, _ := models.GetWxSessionByAccessToken(token)
+			if session != nil {
+				usersOb := new(models.Users)
+				{
+					cond := fmt.Sprintf(` AND %s = ?`, usersOb.Cols().OpenId)
+					pars := make([]interface{}, 0)
+					pars = append(pars, session.OpenId)
+					users, _ := usersOb.GetItemByCondition(cond, pars, "")
+					if users != nil {
+						c.User = users.Format2Item()
+					}
+				}
+				c.Session = session
+			}
+		}
+	}
+
 	ip := c.Ctx.Input.IP()
 	utils.ApiLog.Info("uri:%s, requestBody:%s, ip:%s", c.Ctx.Input.URI(), requestBody, ip)
 }

+ 14 - 2
controllers/report.go

@@ -182,6 +182,13 @@ func (this *ReportOpenController) Detail() {
 		br.Msg = "参数有误"
 		return
 	}
+	resp := new(response.ReportDetailResp)
+
+	// 报告权限
+	users := this.User
+	if users != nil {
+		resp.Status = users.AuthStatus
+	}
 
 	report, err := models.GetReportById(reportId)
 	if err != nil {
@@ -253,7 +260,6 @@ func (this *ReportOpenController) Detail() {
 		}
 	}
 
-	resp := new(response.ReportDetailResp)
 	report.ChapterContent = chapters
 	resp.Report = report
 
@@ -275,6 +281,8 @@ func (this *ReportOpenController) OutsideDetail() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
+	users := this.User
+
 	reportId, _ := this.GetInt("ReportId")
 	if reportId <= 0 {
 		br.Msg = "参数有误"
@@ -290,8 +298,12 @@ func (this *ReportOpenController) OutsideDetail() {
 		br.ErrMsg = fmt.Sprintf("获取外部报告失败, %v", e)
 		return
 	}
+	resp := outsideReport.Format2Item()
+	if users != nil {
+		resp.Status = users.AuthStatus
+	}
 
-	br.Data = outsideReport.Format2Item()
+	br.Data = resp
 	br.Ret = 200
 	br.Msg = "获取成功"
 	br.Success = true

+ 1 - 0
models/report.go

@@ -311,6 +311,7 @@ type OutsideReportItem struct {
 	ReportFile      string `description:"报告附件"`
 	CreateTime      string `description:"创建时间"`
 	ModifyTime      string `description:"修改时间"`
+	Status          int    `description:"报告权限:0-无权限;1-有权限"`
 }
 
 func (m *OutsideReport) Format2Item() (item *OutsideReportItem) {

+ 1 - 1
models/response/report.go

@@ -12,7 +12,7 @@ type ReportList struct {
 
 type ReportDetailResp struct {
 	Report *models.ReportDetail `description:"报告"`
-	Status int                  `description:"报告状态"`
+	Status int                  `description:"报告状态:0-无权限;1-有权限"`
 }
 
 type ReportReadRecordResp struct {