-
Notifications
You must be signed in to change notification settings - Fork 0
/
topic.go
143 lines (121 loc) · 3.44 KB
/
topic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Copyright 2013 The StudyGolang Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// http://studygolang.com
// Author: polaris polaris@studygolang.com
package model
import "time"
const (
FlagNoAudit = iota
FlagNormal
FlagAuditDelete
FlagUserDelete
)
const (
// 最多附言条数
AppendMaxNum = 3
)
const (
PermissionPublic = iota // 公开
PermissionLogin // 登录可见
PermissionFollow // 关注可见(暂未实现)
PermissionPay // 知识星球或其他方式付费可见
)
// 社区主题信息
type Topic struct {
Tid int `xorm:"pk autoincr" json:"tid"`
Title string `json:"title"`
Content string `json:"content"`
Nid int `json:"nid"`
Uid int `json:"uid"`
Flag uint8 `json:"flag"`
Lastreplyuid int `json:"lastreplyuid"`
Lastreplytime OftenTime `json:"lastreplytime"`
EditorUid int `json:"editor_uid"`
Top uint8 `json:"top"`
TopTime int64 `json:"top_time"`
Tags string `json:"tags"`
Permission int `json:"permission"`
CloseReply bool `json:"close_reply"`
Ctime OftenTime `json:"ctime" xorm:"created"`
Mtime OftenTime `json:"mtime" xorm:"<-"`
// 为了方便,加上Node(节点名称,数据表没有)
Node string `xorm:"-"`
// 排行榜阅读量
RankView int `json:"rank_view" xorm:"-"`
}
func (*Topic) TableName() string {
return "topics"
}
func (this *Topic) BeforeInsert() {
if this.Tags == "" {
this.Tags = AutoTag(this.Title, this.Content, 4)
}
}
// 社区主题扩展(计数)信息
type TopicEx struct {
Tid int `json:"-"`
View int `json:"view"`
Reply int `json:"reply"`
Like int `json:"like"`
Mtime time.Time `json:"mtime" xorm:"<-"`
}
func (*TopicEx) TableName() string {
return "topics_ex"
}
// 社区主题扩展(计数)信息,用于 incr 更新
type TopicUpEx struct {
Tid int `json:"-" xorm:"pk"`
View int `json:"view"`
Reply int `json:"reply"`
Like int `json:"like"`
Mtime time.Time `json:"mtime" xorm:"<-"`
}
func (*TopicUpEx) TableName() string {
return "topics_ex"
}
type TopicInfo struct {
Topic `xorm:"extends"`
TopicEx `xorm:"extends"`
}
func (*TopicInfo) TableName() string {
return "topics"
}
type TopicAppend struct {
Id int `xorm:"pk autoincr"`
Tid int
Content string
CreatedAt OftenTime `xorm:"<-"`
}
// 社区主题节点信息
type TopicNode struct {
Nid int `json:"nid" xorm:"pk autoincr"`
Parent int `json:"parent"`
Logo string `json:"logo"`
Name string `json:"name"`
Ename string `json:"ename"`
Seq int `json:"seq"`
Intro string `json:"intro"`
ShowIndex bool `json:"show_index"`
Ctime time.Time `json:"ctime" xorm:"<-"`
Level int `json:"-" xorm:"-"`
}
func (*TopicNode) TableName() string {
return "topics_node"
}
// 推荐节点
type RecommendNode struct {
Id int `json:"id" xorm:"pk autoincr"`
Name string `json:"name"`
Parent int `json:"parent"`
Nid int `json:"nid"`
Seq int `json:"seq"`
CreatedAt time.Time `json:"created_at" xorm:"<-"`
}
type NodeInfo struct {
RecommendNode `xorm:"extends"`
TopicNode `xorm:"extends"`
}
func (*NodeInfo) TableName() string {
return "recommend_node"
}