-
Notifications
You must be signed in to change notification settings - Fork 468
/
notice.go
executable file
·219 lines (189 loc) · 5.38 KB
/
notice.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
package users
import (
"fmt"
"opms/controllers"
. "opms/models/users"
"opms/utils"
"strconv"
"strings"
"github.com/astaxie/beego"
"github.com/astaxie/beego/utils/pagination"
)
//公告管理
type ManageNoticeController struct {
controllers.BaseController
}
func (this *ManageNoticeController) Get() {
//权限检测
if !strings.Contains(this.GetSession("userPermission").(string), "notice-manage") {
this.Abort("401")
}
page, err := this.GetInt("p")
status := this.GetString("status")
keywords := this.GetString("keywords")
if err != nil {
page = 1
}
offset, err1 := beego.AppConfig.Int("pageoffset")
if err1 != nil {
offset = 15
}
condArr := make(map[string]string)
condArr["status"] = status
condArr["keywords"] = keywords
countNotice := CountNotices(condArr)
paginator := pagination.SetPaginator(this.Ctx, offset, countNotice)
_, _, notice := ListNotices(condArr, page, offset)
this.Data["paginator"] = paginator
this.Data["condArr"] = condArr
this.Data["notice"] = notice
this.Data["countNotice"] = countNotice
this.TplName = "users/notice.tpl"
}
//公告状态
type AjaxStatusNoticeController struct {
controllers.BaseController
}
func (this *AjaxStatusNoticeController) Post() {
//权限检测
if !strings.Contains(this.GetSession("userPermission").(string), "notice-edit") {
this.Data["json"] = map[string]interface{}{"code": 0, "message": "无权设置"}
this.ServeJSON()
return
}
id, _ := this.GetInt64("id")
if id <= 0 {
this.Data["json"] = map[string]interface{}{"code": 0, "message": "请选择公告"}
this.ServeJSON()
return
}
status, _ := this.GetInt("status")
if status <= 0 || status >= 3 {
this.Data["json"] = map[string]interface{}{"code": 0, "message": "请选择操作状态"}
this.ServeJSON()
return
}
err := ChangeNoticeStatus(id, status)
if err == nil {
this.Data["json"] = map[string]interface{}{"code": 1, "message": "公告状态更改成功"}
} else {
this.Data["json"] = map[string]interface{}{"code": 0, "message": "公告状态更改失败"}
}
this.ServeJSON()
}
//公告添加
type AddNoticeController struct {
controllers.BaseController
}
func (this *AddNoticeController) Get() {
//权限检测
if !strings.Contains(this.GetSession("userPermission").(string), "notice-add") {
this.Abort("401")
}
this.TplName = "users/notice-form.tpl"
}
func (this *AddNoticeController) Post() {
//权限检测
if !strings.Contains(this.GetSession("userPermission").(string), "notice-add") {
this.Data["json"] = map[string]interface{}{"code": 0, "message": "无权设置"}
this.ServeJSON()
return
}
title := this.GetString("title")
if "" == title {
this.Data["json"] = map[string]interface{}{"code": 0, "message": "请填写标题"}
this.ServeJSON()
return
}
content := this.GetString("content")
var not Notices
not.Id = utils.SnowFlakeId()
not.Title = title
not.Content = content
err := AddNotices(not)
if err == nil {
this.Data["json"] = map[string]interface{}{"code": 1, "message": "公告添加成功"}
} else {
this.Data["json"] = map[string]interface{}{"code": 0, "message": "公告添加失败"}
}
this.ServeJSON()
}
//公告编辑
type EditNoticeController struct {
controllers.BaseController
}
func (this *EditNoticeController) Get() {
//权限检测
if !strings.Contains(this.GetSession("userPermission").(string), "notice-edit") {
this.Abort("401")
}
idstr := this.Ctx.Input.Param(":id")
id, err := strconv.Atoi(idstr)
notice, err := GetNotices(int64(id))
if err != nil {
this.Abort("404")
}
this.Data["notice"] = notice
this.TplName = "users/notice-form.tpl"
}
func (this *EditNoticeController) Post() {
//权限检测
if !strings.Contains(this.GetSession("userPermission").(string), "notice-edit") {
this.Data["json"] = map[string]interface{}{"code": 0, "message": "无权设置"}
this.ServeJSON()
return
}
id, _ := this.GetInt64("id")
if id <= 0 {
this.Data["json"] = map[string]interface{}{"code": 0, "message": "参数出错"}
this.ServeJSON()
return
}
_, err := GetNotices(id)
if err != nil {
this.Data["json"] = map[string]interface{}{"code": 0, "message": "公告不存在"}
this.ServeJSON()
return
}
title := this.GetString("title")
if "" == title {
this.Data["json"] = map[string]interface{}{"code": 0, "message": "请填写标题"}
this.ServeJSON()
return
}
content := this.GetString("content")
var not Notices
not.Title = title
not.Content = content
err = UpdateNotices(id, not)
if err == nil {
this.Data["json"] = map[string]interface{}{"code": 1, "message": "信息修改成功", "id": fmt.Sprintf("%d", id)}
} else {
this.Data["json"] = map[string]interface{}{"code": 0, "message": "信息修改失败"}
}
this.ServeJSON()
}
type AjaxDeleteNoticeController struct {
controllers.BaseController
}
func (this *AjaxDeleteNoticeController) Post() {
//权限检测
if !strings.Contains(this.GetSession("userPermission").(string), "notice-delete") {
this.Data["json"] = map[string]interface{}{"code": 0, "message": "无权设置"}
this.ServeJSON()
return
}
id, _ := this.GetInt64("id")
if id <= 0 {
this.Data["json"] = map[string]interface{}{"code": 0, "message": "请选择公告"}
this.ServeJSON()
return
}
err := DeleteNotice(id)
if err == nil {
this.Data["json"] = map[string]interface{}{"code": 1, "message": "删除成功"}
} else {
this.Data["json"] = map[string]interface{}{"code": 0, "message": "删除失败"}
}
this.ServeJSON()
}