Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3fa7710

Browse files
committed
支持推荐节点
1 parent 5c844c4 commit 3fa7710

33 files changed

+915
-50
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@ welcome.png
4343

4444
.DS_Store
4545
/env.ini
46+
ssl

config/db.sql

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ CREATE TABLE IF NOT EXISTS `topics` (
3030
`nid` int unsigned NOT NULL COMMENT '节点id',
3131
`uid` int unsigned NOT NULL COMMENT '帖子作者',
3232
`lastreplyuid` int unsigned NOT NULL DEFAULT 0 COMMENT '最后回复者',
33-
`lastreplytime` timestamp NOT NULL DEFAULT 0 COMMENT '最后回复时间',
33+
`lastreplytime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '最后回复时间',
3434
`flag` tinyint NOT NULL DEFAULT 0 COMMENT '审核标识,0-未审核;1-已审核;2-审核删除;3-用户自己删除',
3535
`editor_uid` int unsigned NOT NULL DEFAULT 0 COMMENT '最后编辑人',
3636
`top` tinyint unsigned NOT NULL DEFAULT '0' COMMENT '置顶,0否,1置顶',
3737
`tags` varchar(63) NOT NULL DEFAULT '' COMMENT 'tag,逗号分隔',
38-
`ctime` timestamp NOT NULL DEFAULT 0,
38+
`ctime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
3939
`mtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
4040
PRIMARY KEY (`tid`),
4141
KEY `uid` (`uid`),
@@ -64,6 +64,16 @@ CREATE TABLE IF NOT EXISTS `topics_node` (
6464
INDEX `idx_ename` (`ename`)
6565
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '帖子节点表';
6666

67+
CREATE TABLE IF NOT EXISTS `recommend_node` (
68+
`id` int unsigned NOT NULL AUTO_INCREMENT,
69+
`name` varchar(20) NOT NULL DEFAULT '' COMMENT '虚拟节点名',
70+
`parent` int unsigned NOT NULL DEFAULT 0 COMMENT '父节点id,无父节点为0',
71+
`nid` int unsigned NOT NULL COMMENT 'topics_node nid,虚拟节点为0',
72+
`seq` smallint(6) NOT NULL DEFAULT '0' COMMENT '节点排序,小的在前',
73+
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
74+
PRIMARY KEY (`id`)
75+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '导航推荐节点';
76+
6777
CREATE TABLE IF NOT EXISTS `comments` (
6878
`cid` int unsigned NOT NULL AUTO_INCREMENT,
6979
`objid` int unsigned NOT NULL COMMENT '对象id,属主(评论给谁)',
@@ -138,7 +148,7 @@ CREATE TABLE IF NOT EXISTS `user_info` (
138148
`dau_auth` int unsigned NOT NULL DEFAULT 0 COMMENT '控制用户权限,如能否发文章等',
139149
`status` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '用户账号状态。0-默认;1-已审核;2-拒绝;3-冻结;4-停号',
140150
`is_root` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '是否超级用户,不受权限控制:1-是',
141-
`ctime` timestamp NOT NULL DEFAULT 0,
151+
`ctime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
142152
`mtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
143153
PRIMARY KEY (`uid`),
144154
UNIQUE KEY (`username`),
@@ -161,7 +171,7 @@ CREATE TABLE IF NOT EXISTS `role` (
161171
`roleid` int unsigned NOT NULL AUTO_INCREMENT,
162172
`name` varchar(128) NOT NULL DEFAULT '' COMMENT '角色名',
163173
`op_user` varchar(20) NOT NULL DEFAULT '' COMMENT '操作人',
164-
`ctime` timestamp NOT NULL DEFAULT 0,
174+
`ctime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
165175
`mtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
166176
PRIMARY KEY (`roleid`),
167177
UNIQUE KEY (`name`)
@@ -174,7 +184,7 @@ CREATE TABLE IF NOT EXISTS `authority` (
174184
`menu2` int unsigned NOT NULL DEFAULT 0 COMMENT '所属二级菜单,本身为二级菜单,则为0',
175185
`route` varchar(128) NOT NULL DEFAULT '' COMMENT '路由(权限)',
176186
`op_user` varchar(20) NOT NULL COMMENT '操作人',
177-
`ctime` timestamp NOT NULL DEFAULT 0,
187+
`ctime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
178188
`mtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
179189
PRIMARY KEY (`aid`),
180190
KEY (`route`)
@@ -245,9 +255,9 @@ CREATE TABLE IF NOT EXISTS `resource` (
245255
`uid` int unsigned NOT NULL COMMENT '作者',
246256
`catid` int unsigned NOT NULL COMMENT '所属类别',
247257
`lastreplyuid` int unsigned NOT NULL DEFAULT 0 COMMENT '最后回复者',
248-
`lastreplytime` timestamp NOT NULL DEFAULT 0 COMMENT '最后回复时间',
258+
`lastreplytime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '最后回复时间',
249259
`tags` varchar(63) NOT NULL DEFAULT '' COMMENT 'tag,逗号分隔',
250-
`ctime` timestamp NOT NULL DEFAULT 0,
260+
`ctime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
251261
`mtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
252262
PRIMARY KEY (`id`),
253263
KEY (`url`)
@@ -289,12 +299,12 @@ CREATE TABLE IF NOT EXISTS `articles` (
289299
`cmtnum` int unsigned NOT NULL DEFAULT 0 COMMENT '评论数',
290300
`likenum` int unsigned NOT NULL DEFAULT 0 COMMENT '赞数',
291301
`lastreplyuid` int unsigned NOT NULL DEFAULT 0 COMMENT '最后回复者',
292-
`lastreplytime` timestamp NOT NULL DEFAULT 0 COMMENT '最后回复时间',
302+
`lastreplytime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '最后回复时间',
293303
`top` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '置顶,0否,1置顶',
294304
`markdown` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '是否是markwon格式:0-否,1-是',
295305
`status` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '状态:0-初始抓取;1-已上线;2-下线(审核拒绝)',
296306
`op_user` varchar(20) NOT NULL DEFAULT '' COMMENT '操作人',
297-
`ctime` timestamp NOT NULL DEFAULT 0,
307+
`ctime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
298308
`mtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
299309
PRIMARY KEY (`id`),
300310
UNIQUE KEY (`url`),
@@ -393,9 +403,9 @@ CREATE TABLE IF NOT EXISTS `open_project` (
393403
`cmtnum` int unsigned NOT NULL DEFAULT 0 COMMENT '评论数',
394404
`likenum` int unsigned NOT NULL DEFAULT 0 COMMENT '赞数',
395405
`lastreplyuid` int unsigned NOT NULL DEFAULT 0 COMMENT '最后回复者',
396-
`lastreplytime` timestamp NOT NULL DEFAULT 0 COMMENT '最后回复时间',
406+
`lastreplytime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '最后回复时间',
397407
`status` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '状态:0-新建;1-已上线;2-下线(审核拒绝)',
398-
`ctime` timestamp NOT NULL DEFAULT 0 COMMENT '加入时间',
408+
`ctime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '加入时间',
399409
`mtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
400410
PRIMARY KEY (`id`),
401411
KEY (`uri`)
@@ -572,7 +582,7 @@ CREATE TABLE IF NOT EXISTS `feed` (
572582
`author` varchar(31) NOT NULL DEFAULT '' COMMENT '外站作者',
573583
`nid` int unsigned NOT NULL DEFAULT 0 COMMENT '主题的nid或资源的catid',
574584
`lastreplyuid` int unsigned NOT NULL DEFAULT 0 COMMENT '最后回复者',
575-
`lastreplytime` timestamp NOT NULL DEFAULT 0 COMMENT '最后回复时间',
585+
`lastreplytime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '最后回复时间',
576586
`tags` varchar(63) NOT NULL DEFAULT '' COMMENT 'tag,逗号分隔',
577587
`cmtnum` int unsigned NOT NULL DEFAULT 0 COMMENT '评论数',
578588
`top` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '置顶,0否,1置顶',

src/http/controller/admin/node.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Copyright 2014 The StudyGolang Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
// http://studygolang.com
5+
// Author: polaris [email protected]
6+
7+
package admin
8+
9+
import (
10+
"logic"
11+
"model"
12+
13+
"github.com/labstack/echo"
14+
"github.com/polaris1119/goutils"
15+
)
16+
17+
type NodeController struct{}
18+
19+
// 注册路由
20+
func (self NodeController) RegisterRoute(g *echo.Group) {
21+
g.GET("/community/node/list", self.List)
22+
g.Match([]string{"GET", "POST"}, "/community/node/modify", self.Modify)
23+
g.Post("/community/node/modify_seq", self.ModifySeq)
24+
}
25+
26+
// List 所有主题节点
27+
func (NodeController) List(ctx echo.Context) error {
28+
treeNodes := logic.DefaultNode.FindParallelTree(ctx)
29+
30+
nidMap := make(map[int]int)
31+
keySlice := make([]int, len(treeNodes))
32+
33+
for i, node := range treeNodes {
34+
nidMap[node.Nid] = i + 1
35+
36+
if node.Parent > 0 {
37+
keySlice[i] = nidMap[node.Parent]
38+
} else {
39+
keySlice[i] = 0
40+
}
41+
}
42+
43+
data := map[string]interface{}{
44+
"nodes": treeNodes,
45+
"key_slice": keySlice,
46+
}
47+
48+
return render(ctx, "topic/node.html", data)
49+
}
50+
51+
func (NodeController) Modify(ctx echo.Context) error {
52+
if ctx.FormValue("submit") == "1" {
53+
err := logic.DefaultNode.Modify(ctx, ctx.FormParams())
54+
if err != nil {
55+
return fail(ctx, 1, err.Error())
56+
}
57+
return success(ctx, nil)
58+
}
59+
60+
treeNodes := logic.DefaultNode.FindParallelTree(ctx)
61+
62+
data := map[string]interface{}{
63+
"nodes": treeNodes,
64+
}
65+
66+
nid := goutils.MustInt(ctx.QueryParam("nid"))
67+
parent := goutils.MustInt(ctx.QueryParam("parent"))
68+
if nid == 0 && parent == 0 {
69+
// 新增
70+
data["node"] = &model.TopicNode{}
71+
} else if nid > 0 {
72+
data["node"] = logic.DefaultNode.FindOne(nid)
73+
} else if parent > 0 {
74+
data["node"] = &model.TopicNode{}
75+
}
76+
data["parent"] = parent
77+
78+
return render(ctx, "topic/node_modify.html", data)
79+
}
80+
81+
func (NodeController) ModifySeq(ctx echo.Context) error {
82+
nid := goutils.MustInt(ctx.FormValue("nid"))
83+
seq := goutils.MustInt(ctx.FormValue("seq"))
84+
err := logic.DefaultNode.ModifySeq(ctx, nid, seq)
85+
if err != nil {
86+
return fail(ctx, 1, err.Error())
87+
}
88+
return success(ctx, nil)
89+
90+
}

src/http/controller/admin/routes.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import "github.com/labstack/echo"
1111
func RegisterRoutes(g *echo.Group) {
1212
new(AuthorityController).RegisterRoute(g)
1313
new(UserController).RegisterRoute(g)
14+
new(TopicController).RegisterRoute(g)
15+
new(NodeController).RegisterRoute(g)
1416
new(ArticleController).RegisterRoute(g)
1517
new(ProjectController).RegisterRoute(g)
1618
new(RuleController).RegisterRoute(g)

src/http/controller/admin/topic.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Copyright 2014 The StudyGolang Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
// http://studygolang.com
5+
// Author: polaris [email protected]
6+
7+
package admin
8+
9+
import (
10+
"logic"
11+
"model"
12+
"net/http"
13+
14+
"github.com/labstack/echo"
15+
)
16+
17+
type TopicController struct{}
18+
19+
// 注册路由
20+
func (self TopicController) RegisterRoute(g *echo.Group) {
21+
g.GET("/community/topic/list", self.List)
22+
g.POST("/community/topic/query.html", self.Query)
23+
g.Match([]string{"GET", "POST"}, "/community/topic/modify", self.Modify)
24+
}
25+
26+
// List 所有主题(分页)
27+
func (TopicController) List(ctx echo.Context) error {
28+
curPage, limit := parsePage(ctx)
29+
topics, total := logic.DefaultTopic.FindByPage(ctx, nil, curPage, limit)
30+
31+
if topics == nil {
32+
return ctx.HTML(http.StatusInternalServerError, "500")
33+
}
34+
35+
data := map[string]interface{}{
36+
"datalist": topics,
37+
"total": total,
38+
"totalPages": (total + limit - 1) / limit,
39+
"page": curPage,
40+
"limit": limit,
41+
}
42+
43+
return render(ctx, "topic/list.html,topic/query.html", data)
44+
}
45+
46+
// Query
47+
func (TopicController) Query(ctx echo.Context) error {
48+
curPage, limit := parsePage(ctx)
49+
conds := parseConds(ctx, []string{"tid", "title", "uid"})
50+
51+
articles, total := logic.DefaultTopic.FindByPage(ctx, conds, curPage, limit)
52+
53+
if articles == nil {
54+
return ctx.HTML(http.StatusInternalServerError, "500")
55+
}
56+
57+
data := map[string]interface{}{
58+
"datalist": articles,
59+
"total": total,
60+
"totalPages": (total + limit - 1) / limit,
61+
"page": curPage,
62+
"limit": limit,
63+
}
64+
65+
return renderQuery(ctx, "topic/query.html", data)
66+
}
67+
68+
// Modify
69+
func (self TopicController) Modify(ctx echo.Context) error {
70+
var data = make(map[string]interface{})
71+
72+
if ctx.FormValue("submit") == "1" {
73+
user := ctx.Get("user").(*model.Me)
74+
errMsg, err := logic.DefaultArticle.Modify(ctx, user, ctx.FormParams())
75+
if err != nil {
76+
return fail(ctx, 1, errMsg)
77+
}
78+
return success(ctx, nil)
79+
}
80+
article, err := logic.DefaultArticle.FindById(ctx, ctx.QueryParam("id"))
81+
if err != nil {
82+
return ctx.Redirect(http.StatusSeeOther, ctx.Echo().URI(echo.HandlerFunc(self.List)))
83+
}
84+
85+
data["article"] = article
86+
data["statusSlice"] = model.ArticleStatusSlice
87+
data["langSlice"] = model.LangSlice
88+
89+
return render(ctx, "topic/modify.html", data)
90+
}

src/http/controller/topic.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,23 @@ func (TopicController) Create(ctx echo.Context) error {
178178
if title == "" || ctx.Request().Method() != "POST" {
179179
hotNodes := logic.DefaultTopic.FindHotNodes(ctx)
180180

181-
return render(ctx, "topics/new.html", map[string]interface{}{
182-
"nodes": logic.GenNodes(),
181+
data := map[string]interface{}{
183182
"activeTopics": "active",
184183
"nid": nid,
185184
"tab_list": hotNodes,
186-
})
185+
}
186+
hadRecommend := false
187+
if len(logic.AllRecommendNodes) > 0 {
188+
hadRecommend = true
189+
190+
data["nodes"] = logic.DefaultNode.FindAll(ctx)
191+
} else {
192+
data["nodes"] = logic.GenNodes()
193+
}
194+
195+
data["had_recommend"] = hadRecommend
196+
197+
return render(ctx, "topics/new.html", data)
187198
}
188199

189200
me := ctx.Get("user").(*model.Me)

0 commit comments

Comments
 (0)