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

Skip to content

Commit cfa392f

Browse files
authored
Merge pull request studygolang#1 from studygolang/master
Update
2 parents a8030eb + 0f2c82d commit cfa392f

File tree

19 files changed

+164
-59
lines changed

19 files changed

+164
-59
lines changed

config/db.sql

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ CREATE TABLE IF NOT EXISTS `topics` (
3636
`top` tinyint unsigned NOT NULL DEFAULT '0' COMMENT '置顶,0否,1置顶',
3737
`top_time` int unsigned NOT NULL DEFAULT 0 COMMENT '置顶时间',
3838
`tags` varchar(63) NOT NULL DEFAULT '' COMMENT 'tag,逗号分隔',
39-
`permission` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '访问权限:0-公开;1-登录用户可见;2-关注的人可见',
39+
`permission` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '访问权限:0-公开;1-登录用户可见;2-关注的人可见;3-付费用户可见',
4040
`ctime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
4141
`mtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
4242
PRIMARY KEY (`tid`),
@@ -73,7 +73,7 @@ CREATE TABLE IF NOT EXISTS `topics_node` (
7373
`show_index` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '主题是否在首页显示',
7474
`ctime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
7575
PRIMARY KEY (`nid`),
76-
INDEX `idx_ename` (`ename`)
76+
KEY `idx_ename` (`ename`)
7777
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '帖子节点表';
7878

7979
CREATE TABLE IF NOT EXISTS `recommend_node` (
@@ -138,7 +138,7 @@ CREATE TABLE IF NOT EXISTS `bind_user` (
138138
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
139139
PRIMARY KEY (`id`),
140140
UNIQUE KEY `uniq_user_type` (`username`,`type`),
141-
INDEX idx_uid (`uid`)
141+
KEY idx_uid (`uid`)
142142
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '第三方绑定表';
143143

144144
CREATE TABLE IF NOT EXISTS `user_info` (
@@ -159,6 +159,8 @@ CREATE TABLE IF NOT EXISTS `user_info` (
159159
`is_third` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '是否通过第三方账号注册',
160160
`balance` int unsigned NOT NULL DEFAULT 0 COMMENT '财富余额(铜币)',
161161
`dau_auth` int unsigned NOT NULL DEFAULT 0 COMMENT '控制用户权限,如能否发文章等',
162+
`is_vip` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '是否是VIP付费用户',
163+
`vip_expire` int unsigned NOT NULL DEFAULT 0 COMMENT 'VIP到期日期,格式20200301',
162164
`status` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '用户账号状态。0-默认;1-已审核;2-拒绝;3-冻结;4-停号',
163165
`is_root` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '是否超级用户,不受权限控制:1-是',
164166
`ctime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
@@ -561,7 +563,7 @@ CREATE TABLE IF NOT EXISTS `user_balance_detail` (
561563
`desc` varchar(1022) NOT NULL DEFAULT '' COMMENT '具体原因,支持html格式',
562564
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
563565
PRIMARY KEY (`id`),
564-
INDEX `idx_uid`(`uid`)
566+
KEY `idx_uid`(`uid`)
565567
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '用户余额明细';
566568

567569
CREATE TABLE IF NOT EXISTS `mission` (
@@ -595,7 +597,7 @@ CREATE TABLE IF NOT EXISTS `user_recharge` (
595597
`remark` varchar(255) NOT NULL DEFAULT '' COMMENT '充值备注',
596598
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '充值时间',
597599
PRIMARY KEY (`id`),
598-
INDEX `idx_uid`(`uid`)
600+
KEY `idx_uid`(`uid`)
599601
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '用户充值记录表';
600602

601603
CREATE TABLE IF NOT EXISTS `feed` (
@@ -616,7 +618,7 @@ CREATE TABLE IF NOT EXISTS `feed` (
616618
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
617619
PRIMARY KEY (`id`),
618620
UNIQUE KEY `uniq_objid_type` (`objid`, `objtype`),
619-
INDEX `idx_updated_at` (`updated_at`)
621+
KEY `idx_updated_at` (`updated_at`)
620622
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='网站关键资源动态表';
621623

622624
CREATE TABLE `view_record` (
@@ -627,7 +629,7 @@ CREATE TABLE `view_record` (
627629
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
628630
PRIMARY KEY (`id`),
629631
UNIQUE KEY `uniq_obj_uid` (`objid`,`objtype`,`uid`),
630-
INDEX `idx_uid` (`uid`)
632+
KEY `idx_uid` (`uid`)
631633
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '用户浏览记录表';
632634

633635
CREATE TABLE `view_source` (
@@ -679,8 +681,8 @@ CREATE TABLE `user_exchange_record` (
679681
`expire_time` int unsigned NOT NULL DEFAULT 0 COMMENT '过期时间',
680682
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
681683
PRIMARY KEY (`id`),
682-
INDEX `idx_gid` (`gift_id`),
683-
INDEX `idx_uid` (`uid`)
684+
KEY `idx_gid` (`gift_id`),
685+
KEY `idx_uid` (`uid`)
684686
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '物品用户兑换记录';
685687

686688
CREATE TABLE IF NOT EXISTS `gctt_user` (
@@ -697,7 +699,7 @@ CREATE TABLE IF NOT EXISTS `gctt_user` (
697699
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
698700
PRIMARY KEY (`id`),
699701
UNIQUE KEY (`username`),
700-
INDEX idx_uid (`uid`)
702+
KEY idx_uid (`uid`)
701703
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT 'GCTT 用户表';
702704

703705
CREATE TABLE IF NOT EXISTS `gctt_git` (
@@ -713,7 +715,7 @@ CREATE TABLE IF NOT EXISTS `gctt_git` (
713715
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
714716
PRIMARY KEY (`id`),
715717
UNIQUE KEY (`md5`),
716-
INDEX (`username`)
718+
KEY (`username`)
717719
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT 'GCTT github 文章翻译信息表';
718720

719721

@@ -736,7 +738,7 @@ CREATE TABLE IF NOT EXISTS `gctt_issue` (
736738
`state` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0-opened;1-closed',
737739
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
738740
PRIMARY KEY (`id`),
739-
INDEX (`label`)
741+
KEY (`label`)
740742
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT 'GCTT github 选题 issue 列表';
741743

742744

@@ -784,7 +786,7 @@ CREATE TABLE IF NOT EXISTS `subject_follower` (
784786
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
785787
PRIMARY KEY (`id`),
786788
UNIQUE KEY (`sid`,`uid`),
787-
INDEX (`uid`)
789+
KEY (`uid`)
788790
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '专栏关注者';
789791

790792
CREATE TABLE IF NOT EXISTS `download` (

src/http/controller/admin/user.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ func (UserController) Modify(ctx echo.Context) error {
7575
amount := goutils.MustInt(ctx.FormValue("amount"))
7676
if amount > 0 {
7777
logic.DefaultUserRich.Recharge(ctx, uid, ctx.FormParams())
78-
} else {
79-
logic.DefaultUser.SetDauAuth(ctx, uid, ctx.FormParams())
8078
}
79+
logic.DefaultUser.AdminUpdateUser(ctx, uid, ctx.FormParams())
80+
8181
return success(ctx, nil)
8282
}
8383

src/http/controller/app/topic.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,20 @@ func (TopicController) Detail(ctx echo.Context) error {
108108
return fail(ctx, "服务器异常")
109109
}
110110

111+
me, ok := ctx.Get("user").(*model.Me)
112+
113+
permission := topic["permission"].(int)
114+
switch permission {
115+
case model.PermissionLogin:
116+
if !ok {
117+
topic["content"] = "登录用户可见!"
118+
}
119+
case model.PermissionPay:
120+
if !ok || !me.IsVip || !me.IsRoot {
121+
topic["content"] = "付费用户可见!"
122+
}
123+
}
124+
111125
logic.Views.Incr(Request(ctx), model.TypeTopic, tid)
112126

113127
data := map[string]interface{}{

src/http/controller/article.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ func (ArticleController) ReadList(ctx echo.Context) error {
6666

6767
num := len(articles)
6868
if num == 0 {
69-
if curPage == int(total) {
70-
return render(ctx, "articles/list.html", map[string]interface{}{"articles": articles, "activeArticles": "active"})
71-
}
72-
return ctx.Redirect(http.StatusSeeOther, "/articles")
69+
return render(ctx, "articles/list.html", map[string]interface{}{"articles": articles, "activeArticles": "active"})
7370
}
7471

7572
// 获取当前用户喜欢对象信息

src/http/controller/download.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func (DownloadController) AddNewDownload(ctx echo.Context) error {
127127
}
128128

129129
if selector == "" {
130-
selector = "toggleVisible"
130+
selector = ".toggleVisible"
131131
}
132132

133133
err := logic.DefaultDownload.AddNewDownload(ctx, version, selector)

src/http/controller/project.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,7 @@ func (ProjectController) ReadList(ctx echo.Context) error {
5454

5555
num := len(projects)
5656
if num == 0 {
57-
if curPage == int(total) {
58-
return render(ctx, "projects/list.html", map[string]interface{}{"projects": projects, "activeProjects": "active"})
59-
} else {
60-
return ctx.Redirect(http.StatusSeeOther, "/projects")
61-
}
57+
return render(ctx, "projects/list.html", map[string]interface{}{"projects": projects, "activeProjects": "active"})
6258
}
6359

6460
// 获取当前用户喜欢对象信息

src/http/controller/topic.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,23 @@ func (TopicController) Detail(ctx echo.Context) error {
156156
"topic": topic,
157157
"replies": replies,
158158
"appends": []*model.TopicAppend{},
159+
"can_view": true,
159160
}
160161

161162
me, ok := ctx.Get("user").(*model.Me)
162-
if topic["permission"] == 0 || (topic["permission"] == 1 && ok) {
163+
// 当前用户是否对付费内容可见
164+
if topic["permission"] == model.PermissionPay {
165+
if !ok || (!me.IsVip && !me.IsRoot && topic["uid"].(int) != me.Uid) {
166+
data["can_view"] = false
167+
}
168+
}
169+
170+
if topic["permission"] == model.PermissionPublic ||
171+
(topic["permission"] == model.PermissionLogin && ok) ||
172+
(topic["permission"] == model.PermissionPay && ok && (me.IsVip || me.IsRoot)) {
163173
data["appends"] = logic.DefaultTopic.FindAppend(ctx, tid)
164174
}
175+
165176
if ok {
166177
tid := topic["tid"].(int)
167178
data["likeflag"] = logic.DefaultLike.HadLike(ctx, me.Uid, tid, model.TypeTopic)

src/logic/article.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"strings"
1919
"time"
2020

21+
"github.com/go-xorm/xorm"
2122
"github.com/polaris1119/slices"
2223

2324
"github.com/PuerkitoBio/goquery"
@@ -556,7 +557,7 @@ func (self ArticleLogic) FindByUser(ctx context.Context, username string, limit
556557
objLog := GetLogger(ctx)
557558

558559
articles := make([]*model.Article, 0)
559-
err := MasterDB.Where("author_txt=?", username).OrderBy("id DESC").Limit(limit).Find(&articles)
560+
err := MasterDB.Where("author_txt=? AND status<?", username, model.ArticleStatusOffline).OrderBy("id DESC").Limit(limit).Find(&articles)
560561
if err != nil {
561562
objLog.Errorln("ArticleLogic FindByUser Error:", err)
562563
return nil
@@ -619,6 +620,7 @@ func (self ArticleLogic) FindAll(ctx context.Context, paginator *Paginator, orde
619620
if querystring != "" {
620621
session.Where(querystring, args...)
621622
}
623+
self.addStatusWhere(session)
622624
err := session.Limit(paginator.PerPage(), paginator.Offset()).Find(&articles)
623625
if err != nil {
624626
objLog.Errorln("ArticleLogic FindAll error:", err)
@@ -633,14 +635,15 @@ func (self ArticleLogic) FindAll(ctx context.Context, paginator *Paginator, orde
633635
func (ArticleLogic) Count(ctx context.Context, querystring string, args ...interface{}) int64 {
634636
objLog := GetLogger(ctx)
635637

638+
session := MasterDB.Where("status<?", model.ArticleStatusOffline)
636639
var (
637640
total int64
638641
err error
639642
)
640643
if querystring == "" {
641-
total, err = MasterDB.Count(new(model.Article))
644+
total, err = session.Count(new(model.Article))
642645
} else {
643-
total, err = MasterDB.Where(querystring, args...).Count(new(model.Article))
646+
total, err = session.Where(querystring, args...).Count(new(model.Article))
644647
}
645648

646649
if err != nil {
@@ -1057,6 +1060,10 @@ func (ArticleLogic) getOwner(id int) int {
10571060
return 0
10581061
}
10591062

1063+
func (ArticleLogic) addStatusWhere(session *xorm.Session) {
1064+
session.Where("status<?", model.ArticleStatusOffline)
1065+
}
1066+
10601067
// 博文评论
10611068
type ArticleComment struct{}
10621069

@@ -1086,6 +1093,9 @@ func (self ArticleComment) SetObjinfo(ids []int, commentMap map[int][]*model.Com
10861093
}
10871094

10881095
for _, article := range articles {
1096+
if article.Status >= model.ArticleStatusOffline {
1097+
continue
1098+
}
10891099
objinfo := make(map[string]interface{})
10901100
objinfo["title"] = article.Title
10911101
objinfo["uri"] = model.PathUrlMap[model.TypeArticle]

src/logic/comment.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func (self CommentLogic) FindRecent(ctx context.Context, uid, objtype, limit int
192192
self.fillObjinfos(cmts, cmtObjs[cmtType])
193193
}
194194

195-
return comments
195+
return self.filterDelObjectCmt(comments)
196196
}
197197

198198
// Publish 发表评论(或回复)。
@@ -417,7 +417,8 @@ func (self CommentLogic) FindAll(ctx context.Context, paginator *Paginator, orde
417417
for cmtType, cmts := range cmtMap {
418418
self.fillObjinfos(cmts, cmtObjs[cmtType])
419419
}
420-
return comments
420+
421+
return self.filterDelObjectCmt(comments)
421422
}
422423

423424
// Count 获取用户全部评论数
@@ -440,3 +441,13 @@ func (CommentLogic) Count(ctx context.Context, querystring string, args ...inter
440441

441442
return total
442443
}
444+
445+
func (CommentLogic) filterDelObjectCmt(comments []*model.Comment) []*model.Comment {
446+
resultCmts := make([]*model.Comment, 0, len(comments))
447+
for _, comment := range comments {
448+
if comment.Objinfo != nil && len(comment.Objinfo) > 0 {
449+
resultCmts = append(resultCmts, comment)
450+
}
451+
}
452+
return resultCmts
453+
}

src/logic/topic.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
. "db"
2020

2121
"github.com/fatih/structs"
22+
"github.com/go-xorm/xorm"
2223
"github.com/polaris1119/goutils"
2324
"github.com/polaris1119/logger"
2425
"github.com/polaris1119/set"
@@ -308,6 +309,7 @@ func (self TopicLogic) FindAll(ctx context.Context, paginator *Paginator, orderB
308309
if querystring != "" {
309310
session.Where(querystring, args...)
310311
}
312+
self.addFlagWhere(session)
311313
err := session.OrderBy(orderBy).Limit(paginator.PerPage(), paginator.Offset()).Find(&topicInfos)
312314
if err != nil {
313315
objLog.Errorln("TopicLogic FindAll error:", err)
@@ -326,11 +328,12 @@ func (TopicLogic) FindLastList(beginTime string, limit int) ([]*model.Topic, err
326328
}
327329

328330
// FindRecent 获得最近的主题(uids[0],则获取某个用户最近的主题)
329-
func (TopicLogic) FindRecent(limit int, uids ...int) []*model.Topic {
331+
func (self TopicLogic) FindRecent(limit int, uids ...int) []*model.Topic {
330332
dbSession := MasterDB.OrderBy("ctime DESC").Limit(limit)
331333
if len(uids) > 0 {
332334
dbSession.Where("uid=?", uids[0])
333335
}
336+
self.addFlagWhere(dbSession)
334337

335338
topics := make([]*model.Topic, 0)
336339
if err := dbSession.Find(&topics); err != nil {
@@ -347,7 +350,7 @@ func (TopicLogic) FindByNid(ctx context.Context, nid, curTid string) []*model.To
347350
objLog := GetLogger(ctx)
348351

349352
topics := make([]*model.Topic, 0)
350-
err := MasterDB.Where("nid=? AND tid!=?", nid, curTid).Limit(10).Find(&topics)
353+
err := MasterDB.Where("nid=? AND tid!=? AND flag<?", nid, curTid, model.FlagAuditDelete).Limit(10).Find(&topics)
351354
if err != nil {
352355
objLog.Errorln("TopicLogic FindByNid Error:", err)
353356
}
@@ -628,14 +631,15 @@ func (TopicLogic) JSEscape(topics []*model.Topic) []*model.Topic {
628631
func (TopicLogic) Count(ctx context.Context, querystring string, args ...interface{}) int64 {
629632
objLog := GetLogger(ctx)
630633

634+
session := MasterDB.Where("flag<?", model.FlagAuditDelete)
631635
var (
632636
total int64
633637
err error
634638
)
635639
if querystring == "" {
636-
total, err = MasterDB.Count(new(model.Topic))
640+
total, err = session.Count(new(model.Topic))
637641
} else {
638-
total, err = MasterDB.Where(querystring, args...).Count(new(model.Topic))
642+
total, err = session.Where(querystring, args...).Count(new(model.Topic))
639643
}
640644

641645
if err != nil {
@@ -664,6 +668,10 @@ func (TopicLogic) decodeTopicContent(ctx context.Context, topic *model.Topic) st
664668
return parseAtUser(ctx, content)
665669
}
666670

671+
func (TopicLogic) addFlagWhere(session *xorm.Session) {
672+
session.Where("flag<?", model.FlagAuditDelete)
673+
}
674+
667675
// 话题回复(评论)
668676
type TopicComment struct{}
669677

@@ -710,6 +718,9 @@ func (self TopicComment) SetObjinfo(ids []int, commentMap map[int][]*model.Comme
710718
}
711719

712720
for _, topic := range topics {
721+
if topic.Flag > model.FlagNormal {
722+
continue
723+
}
713724
objinfo := make(map[string]interface{})
714725
objinfo["title"] = topic.Title
715726
objinfo["uri"] = model.PathUrlMap[model.TypeTopic]

0 commit comments

Comments
 (0)