mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-04-30 17:48:03 +08:00
增加阅读次数
This commit is contained in:
parent
5b274ce836
commit
323378c0ae
@ -109,7 +109,6 @@ func RegisterModel() {
|
|||||||
new(models.TeamMember),
|
new(models.TeamMember),
|
||||||
new(models.TeamRelationship),
|
new(models.TeamRelationship),
|
||||||
new(models.Itemsets),
|
new(models.Itemsets),
|
||||||
new(models.DocumentViewCount),
|
|
||||||
)
|
)
|
||||||
gob.Register(models.Blog{})
|
gob.Register(models.Blog{})
|
||||||
gob.Register(models.Document{})
|
gob.Register(models.Document{})
|
||||||
|
@ -143,8 +143,8 @@ func (c *DocumentController) Read() {
|
|||||||
doc.AttachList = attach
|
doc.AttachList = attach
|
||||||
}
|
}
|
||||||
|
|
||||||
view_count := models.NewDocumentViewCount().IncrViewCount(doc.DocumentId)
|
doc.IncrViewCount(doc.DocumentId)
|
||||||
c.Data["ViewCount"] = view_count
|
c.Data["ViewCount"] = doc.ViewCount + 1
|
||||||
|
|
||||||
if c.IsAjax() {
|
if c.IsAjax() {
|
||||||
var data struct {
|
var data struct {
|
||||||
@ -158,7 +158,7 @@ func (c *DocumentController) Read() {
|
|||||||
data.Body = doc.Release
|
data.Body = doc.Release
|
||||||
data.Title = doc.DocumentName + " - Powered by MinDoc"
|
data.Title = doc.DocumentName + " - Powered by MinDoc"
|
||||||
data.Version = doc.Version
|
data.Version = doc.Version
|
||||||
data.ViewCount = view_count
|
data.ViewCount = doc.ViewCount + 1
|
||||||
|
|
||||||
c.JsonResult(0, "ok", data)
|
c.JsonResult(0, "ok", data)
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@ type Document struct {
|
|||||||
Version int64 `orm:"column(version);type(bigint);" json:"version"`
|
Version int64 `orm:"column(version);type(bigint);" json:"version"`
|
||||||
//是否展开子目录:0 否/1 是 /2 空间节点,单击时展开下一级
|
//是否展开子目录:0 否/1 是 /2 空间节点,单击时展开下一级
|
||||||
IsOpen int `orm:"column(is_open);type(int);default(0)" json:"is_open"`
|
IsOpen int `orm:"column(is_open);type(int);default(0)" json:"is_open"`
|
||||||
|
ViewCount int `orm:"column(view_count);type(int)" json:"view_count"`
|
||||||
AttachList []*Attachment `orm:"-" json:"attach"`
|
AttachList []*Attachment `orm:"-" json:"attach"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -384,3 +385,11 @@ func (item *Document) Processor() *Document {
|
|||||||
}
|
}
|
||||||
return item
|
return item
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 增加阅读次数
|
||||||
|
func (item *Document) IncrViewCount(id int) {
|
||||||
|
o := orm.NewOrm()
|
||||||
|
o.QueryTable(item.TableNameWithPrefix()).Filter("document_id", id).Update(orm.Params{
|
||||||
|
"view_count": orm.ColValue(orm.ColAdd, 1),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -1,44 +0,0 @@
|
|||||||
package models
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/astaxie/beego/orm"
|
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
|
||||||
)
|
|
||||||
|
|
||||||
type DocumentViewCount struct {
|
|
||||||
DocumentId int `orm:"pk;column(document_id);type(int)" json:"doc_id"`
|
|
||||||
ViewCount int `orm:"column(view_count);type(int)" json:"view_count"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// TableName 获取对应数据库表名.
|
|
||||||
func (v *DocumentViewCount) TableName() string {
|
|
||||||
return "document_viewcount"
|
|
||||||
}
|
|
||||||
|
|
||||||
// TableEngine 获取数据使用的引擎.
|
|
||||||
func (v *DocumentViewCount) TableEngine() string {
|
|
||||||
return "INNODB"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *DocumentViewCount) TableNameWithPrefix() string {
|
|
||||||
return conf.GetDatabasePrefix() + v.TableName()
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewDocumentViewCount() *DocumentViewCount {
|
|
||||||
return &DocumentViewCount{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *DocumentViewCount) IncrViewCount(id int) int {
|
|
||||||
o := orm.NewOrm()
|
|
||||||
num, _ := o.QueryTable(v.TableNameWithPrefix()).Filter("document_id", id).Update(orm.Params{
|
|
||||||
"view_count": orm.ColValue(orm.ColAdd, 1),
|
|
||||||
})
|
|
||||||
if 0 == num {
|
|
||||||
v.DocumentId = id
|
|
||||||
v.ViewCount = 1
|
|
||||||
num, _ = o.Insert(v)
|
|
||||||
} else {
|
|
||||||
o.QueryTable(v.TableNameWithPrefix()).Filter("document_id", id).One(v)
|
|
||||||
}
|
|
||||||
return v.ViewCount
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user