WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 9a7a057

Browse files
committed
书籍收录管理
1 parent 4a1df89 commit 9a7a057

File tree

7 files changed

+190
-11
lines changed

7 files changed

+190
-11
lines changed

controllers/ManagerController.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,3 +972,37 @@ func (this *ManagerController) UploadBanner() {
972972
}
973973
this.JsonResult(0, "横幅上传成功")
974974
}
975+
976+
func (this *ManagerController) SubmitBook() {
977+
this.TplName = "manager/submit_book.html"
978+
m := models.NewSubmitBooks()
979+
page, _ := this.GetInt("page", 1)
980+
size, _ := this.GetInt("size", 100)
981+
books, total, _ := m.Lists(page, size)
982+
if total > 0 {
983+
this.Data["PageHtml"] = utils.NewPaginations(conf.RollPage, int(total), size, page, beego.URLFor("ManagerController.SubmitBook"), "")
984+
} else {
985+
this.Data["PageHtml"] = ""
986+
}
987+
this.Data["Books"] = books
988+
this.Data["IsSubmitBook"] = true
989+
}
990+
991+
func (this *ManagerController) DeleteSubmitBook() {
992+
id, _ := this.GetInt("id")
993+
orm.NewOrm().QueryTable(models.NewSubmitBooks()).Filter("id", id).Delete()
994+
this.JsonResult(0, "删除成功")
995+
}
996+
997+
func (this *ManagerController) UpdateSubmitBook() {
998+
field := this.GetString("field")
999+
value := this.GetString("value")
1000+
id, _ := this.GetInt("id")
1001+
if id > 0 {
1002+
_, err := orm.NewOrm().QueryTable(models.NewSubmitBooks()).Filter("id", id).Update(orm.Params{field: value})
1003+
if err != nil {
1004+
this.JsonResult(1, err.Error())
1005+
}
1006+
}
1007+
this.JsonResult(0, "更新成功")
1008+
}

models/submit_books.go

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package models
22

33
import (
4+
"fmt"
45
"time"
56

67
"github.com/astaxie/beego"
@@ -11,15 +12,23 @@ import (
1112
)
1213

1314
type SubmitBooks struct {
14-
Id int
15-
Uid int `orm:"index"`
16-
Title string `form:"title"`
17-
Url string `form:"url"`
18-
UrlMd5 string `orm:"size(32);unique"`
19-
Message string `orm:"size(512)" form:"message"`
20-
Status bool
21-
CreatedAt time.Time
22-
UpdatedAt time.Time
15+
Id int
16+
Uid int `orm:"index"`
17+
// 注意: nickname 和 account 是不存储用户昵称和账户的。orm:"-" 的时候,beego自带的orm没法将用户的数据匹配到字段上来,所以用这种勉强的方式
18+
Nickname string `orm:"default();size(1)"`
19+
Account string `orm:"default();size(1)"`
20+
Title string `form:"title"`
21+
Url string `form:"url"`
22+
UrlMd5 string `orm:"size(32);unique"`
23+
Message string `orm:"size(512)" form:"message"`
24+
Status bool
25+
CreatedAt time.Time
26+
UpdatedAt time.Time
27+
CreatedAtStr string `orm:"-"`
28+
}
29+
30+
func NewSubmitBooks() *SubmitBooks {
31+
return &SubmitBooks{}
2332
}
2433

2534
func (m *SubmitBooks) Add() (err error) {
@@ -47,3 +56,38 @@ func (m *SubmitBooks) Add() (err error) {
4756

4857
return
4958
}
59+
60+
func (m *SubmitBooks) Lists(page, size int, status ...bool) (books []SubmitBooks, total int64, err error) {
61+
o := orm.NewOrm()
62+
q := o.QueryTable(m)
63+
where := ""
64+
if len(status) > 0 {
65+
q = q.Filter("status", status[0])
66+
if status[0] == true {
67+
where = " where status = 1 "
68+
} else {
69+
where = "where status = 0 "
70+
}
71+
}
72+
total, err = q.Count()
73+
if err != nil {
74+
beego.Error(err)
75+
return
76+
}
77+
if total == 0 {
78+
return
79+
}
80+
81+
querySQL := fmt.Sprintf("select b.*,u.nickname,u.account from md_submit_books b left join md_members u on u.member_id = b.uid %v order by b.id desc limit %v offset %v",
82+
where, size, (page-1)*size,
83+
)
84+
_, err = o.Raw(querySQL).QueryRows(&books)
85+
if err != nil {
86+
beego.Error(err.Error())
87+
}
88+
for idx, book := range books {
89+
book.CreatedAtStr = book.CreatedAt.Format("2006-01-02 15:04:05")
90+
books[idx] = book
91+
}
92+
return
93+
}

routers/web.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ func webRouter() {
6060
beego.Router("/manager/banners/upload", &controllers.ManagerController{}, "post:UploadBanner")
6161
beego.Router("/manager/banners/delete", &controllers.ManagerController{}, "get:DeleteBanner")
6262
beego.Router("/manager/banners/update", &controllers.ManagerController{}, "get:UpdateBanner")
63+
beego.Router("/manager/submit-book", &controllers.ManagerController{}, "get:SubmitBook")
64+
beego.Router("/manager/submit-book/update", &controllers.ManagerController{}, "get:UpdateSubmitBook")
65+
beego.Router("/manager/submit-book/delete", &controllers.ManagerController{}, "get:DeleteSubmitBook")
6366

6467
beego.Router("/setting", &controllers.SettingController{}, "*:Index")
6568
beego.Router("/setting/password", &controllers.SettingController{}, "*:Password")

static/editor.md/lib/codemirror/mode/lua/lua.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ CodeMirror.defineMode("lua", function(config, parserConfig) {
4040

4141
"close","flush","lines","read","seek","setvbuf","write",
4242

43-
"io.close","io.flush","io.input","io.lines","io.open","io.output","io.popen","io.read","io.stderr","io.stdin",
43+
"io.close","io.flush","io.input","io.lines","io.open","io.output","io.popen","read","io.stderr","io.stdin",
4444
"io.stdout","io.tmpfile","io.type","io.write",
4545

4646
"math.abs","math.acos","math.asin","math.atan","math.atan2","math.ceil","math.cos","math.cosh","math.deg",

static/editor.md/lib/codemirror/modes.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

views/manager/menu.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<li {{if .IsBooks}}class="active"{{end}}><a href="{{urlfor "ManagerController.Books" }}" class="item"><i class="fa fa-book" aria-hidden="true"></i> 项目管理</a> </li>
55
<li {{if .IsComments}}class="active"{{end}}><a href="{{urlfor "ManagerController.Comments" }}" class="item"><i class="fa fa-comments-o" aria-hidden="true"></i> 评论管理</a> </li>
66
<li {{if .IsBanner}}class="active"{{end}}><a href="{{urlfor "ManagerController.Banners" }}" class="item"><i class="fa fa-image" aria-hidden="true"></i> 横幅管理</a> </li>
7+
<li {{if .IsSubmitBook}}class="active"{{end}}><a href="{{urlfor "ManagerController.SubmitBook" }}" class="item"><i class="fa fa-check-square-o" aria-hidden="true"></i> 收录管理</a> </li>
78
<li {{if .IsSetting}}class="active"{{end}}><a href="{{urlfor "ManagerController.Setting" }}" class="item"><i class="fa fa-cogs" aria-hidden="true"></i> 配置管理</a> </li>
89
<li {{if .IsManagerSeo}}class="active"{{end}}><a href="{{urlfor "ManagerController.Seo" }}" class="item"><i class="fa fa-globe" aria-hidden="true"></i> SEO管理</a> </li>
910
<li {{if .IsCategory}}class="active"{{end}}><a href="{{urlfor "ManagerController.Category" }}" class="item"><i class="fa fa-th" aria-hidden="true"></i> 分类管理</a> </li>

views/manager/submit_book.html

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<!DOCTYPE html>
2+
<html lang="zh-CN">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
7+
8+
<title>收录管理 - {{.SITE_NAME}}</title>
9+
10+
<link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet">
11+
<link href="/static/font-awesome/css/font-awesome.min.css" rel="stylesheet">
12+
13+
<link href="/static/css/main.css?version={{$.Version}}" rel="stylesheet">
14+
{{/*<script src="/static/html5shiv/3.7.3/html5shiv.min.js"></script>*/}}
15+
<script src="/static/html5shiv/3.7.3/html5shiv.min.js"></script>
16+
{{/*<script src="/static/respond.js/1.4.2/respond.min.js"></script>*/}}
17+
<script src="/static/respond.js/1.4.2/respond.min.js"></script>
18+
19+
<link rel="stylesheet" href="/static/css/toast.css">
20+
<style>.content-block{max-width: 350px;word-break: break-all;}</style>
21+
</head>
22+
<body>
23+
<div class="manual-reader">
24+
{{template "widgets/header.html" .}}
25+
<div class="container manual-body">
26+
<div class="row">
27+
<div class="page-left">
28+
{{template "manager/menu.html" .}}
29+
</div>
30+
<div class="page-right">
31+
<div class="m-box">
32+
<div class="box-head">
33+
<strong class="box-title">收录管理</strong>
34+
</div>
35+
</div>
36+
<div class="box-body" id="bookList">
37+
<table class="table table-hover table-striped">
38+
<thead>
39+
<tr>
40+
<th>#</th>
41+
<th>用户</th>
42+
<th>内容</th>
43+
<th>留言</th>
44+
<th>时间</th>
45+
<th>状态</th>
46+
<th>操作</th>
47+
</tr>
48+
</thead>
49+
<tbody>
50+
{{range .Books}}
51+
<tr>
52+
<td>{{.Id}}</td>
53+
<td>
54+
<a href="{{urlfor "UserController.Index" ":username" .Account}}" target="_blank">{{.Nickname}}</a>
55+
</td>
56+
<td>
57+
<a href="{{.Url}}" target="_blank">《{{.Title}}》</a>
58+
</td>
59+
<td>
60+
<div class="help-block conten-block">{{.Message}}</div>
61+
</td>
62+
<td>{{.CreatedAtStr}}</td>
63+
<td>
64+
{{if .Status}}
65+
<span class="text-success">已处理</span>
66+
{{else}}
67+
<span class="text-danger">待处理</span>
68+
{{end}}
69+
</td>
70+
<td>
71+
{{if .Status}}
72+
<a href="{{urlfor "ManagerController.UpdateSubmitBook"}}?id={{.Id}}&field=status&value=0" class="ajax-get">待处理</a>
73+
{{else}}
74+
<a href="{{urlfor "ManagerController.UpdateSubmitBook"}}?id={{.Id}}&field=status&value=1" class="ajax-get">已处理</a>
75+
{{end}}
76+
<a href="{{urlfor "ManagerController.DeleteSubmitBook"}}?id={{.Id}}" class="text-danger confirm ajax-get">删除</a>
77+
</td>
78+
</tr>
79+
{{end}}
80+
</tbody>
81+
</table>
82+
83+
{{.PageHtml}}
84+
</div>
85+
</div>
86+
</div>
87+
</div>
88+
</div>
89+
90+
{{/*<script src="/static/jquery/1.12.4/jquery.min.js" type="text/javascript"></script>*/}}
91+
<script src="/static/jquery/1.12.4/jquery.min.js" type="text/javascript"></script>
92+
{{/*<script src="/static/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>*/}}
93+
<script src="/static/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
94+
<script src="{{$.StaticDomain}}/static/js/toast.script.js"></script>
95+
<script src="/static/js/main.js?version={{$.Version}}" type="text/javascript"></script>
96+
</body>
97+
</html>

0 commit comments

Comments
 (0)