@@ -228,6 +228,7 @@ func (this *DocumentController) indexWithPassword() {
228228
229229//阅读文档.
230230func (this * DocumentController ) Read () {
231+
231232 identify := this .Ctx .Input .Param (":key" )
232233 token := this .GetString ("token" )
233234 id := this .GetString (":id" )
@@ -272,6 +273,13 @@ func (this *DocumentController) Read() {
272273 this .Abort404 (bookName , bookLink )
273274 }
274275
276+ // 是否允许阅读
277+ isAllowRead := true
278+ percent := 100
279+ if this .Member .MemberId == 0 {
280+ isAllowRead , percent = doc .IsAllowReadChapter (doc .BookId , doc .DocumentId )
281+ }
282+
275283 bodyText := ""
276284 authHTTPS := strings .ToLower (models .GetOptionValue ("AUTO_HTTPS" , "false" )) == "true"
277285 if doc .Release != "" {
@@ -387,16 +395,22 @@ func (this *DocumentController) Read() {
387395 models .NewBookCounter ().Increase (bookResult .BookId , true )
388396 comments , _ := models .NewComments ().Comments (1 , 1000 , models.CommentOpt {DocId : doc .DocumentId , Status : []int {1 }})
389397
398+ if ! isAllowRead {
399+ doc .Release = ""
400+ }
401+
390402 if this .IsAjax () {
391403 var data struct {
392- Id int `json:"doc_id"`
393- DocTitle string `json:"doc_title"`
394- Body string `json:"body"`
395- Title string `json:"title"`
396- Bookmark bool `json:"bookmark"` //是否已经添加了书签
397- View int `json:"view"`
398- UpdatedAt string `json:"updated_at"`
399- Comments []models.BookCommentsResult `json:"comments"`
404+ Id int `json:"doc_id"`
405+ DocTitle string `json:"doc_title"`
406+ Body string `json:"body"`
407+ Title string `json:"title"`
408+ Bookmark bool `json:"bookmark"` //是否已经添加了书签
409+ View int `json:"view"`
410+ UpdatedAt string `json:"updated_at"`
411+ Comments []models.BookCommentsResult `json:"comments"`
412+ IsAllowRead bool `json:"is_allow_read"`
413+ Percent int `json:"percent"`
400414 }
401415 data .DocTitle = doc .DocumentName
402416 data .Body = doc .Release
@@ -405,9 +419,9 @@ func (this *DocumentController) Read() {
405419 data .Bookmark = existBookmark
406420 data .View = doc .Vcnt
407421 data .UpdatedAt = doc .ModifyTime .Format ("2006-01-02 15:04:05" )
408- //data.Body = doc.Markdown
409422 data .Comments = comments
410-
423+ data .IsAllowRead = isAllowRead
424+ data .Percent = percent
411425 this .JsonResult (0 , "ok" , data )
412426 }
413427
@@ -474,6 +488,8 @@ func (this *DocumentController) Read() {
474488 this .Data ["UpdatedAt" ] = doc .ModifyTime .Format ("2006-01-02 15:04:05" )
475489 this .Data ["ExistWeCode" ] = strings .TrimSpace (models .GetOptionValue ("DOWNLOAD_WECODE" , "" )) != ""
476490 this .Data ["Comments" ] = comments
491+ this .Data ["IsAllowRead" ] = isAllowRead
492+ this .Data ["Percent" ] = percent
477493}
478494
479495//编辑文档.
0 commit comments