forked from george518/PPGo_Job
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathban.go
126 lines (107 loc) · 2.85 KB
/
ban.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
/************************************************************
** @Description: controllers
** @Author: haodaquan
** @Date: 2018-06-10 19:50
** @Last Modified by: haodaquan
** @Last Modified time: 2018-06-10 19:50
*************************************************************/
package controllers
import (
"strings"
"time"
"github.com/astaxie/beego"
"github.com/george518/PPGo_Job/models"
)
type BanController struct {
BaseController
}
func (self *BanController) List() {
self.Data["pageTitle"] = "禁用命令管理"
self.display()
}
func (self *BanController) Add() {
self.Data["pageTitle"] = "新增禁用命令"
// 角色
filters := make([]interface{}, 0)
filters = append(filters, "status", 1)
result, _ := models.RoleGetList(1, 1000, filters...)
list := make([]map[string]interface{}, len(result))
for k, v := range result {
row := make(map[string]interface{})
row["id"] = v.Id
row["role_name"] = v.RoleName
list[k] = row
}
self.Data["role"] = list
self.display()
}
func (self *BanController) Edit() {
self.Data["pageTitle"] = "编辑禁用命令"
id, _ := self.GetInt("id", 0)
ban, _ := models.BanGetById(id)
row := make(map[string]interface{})
row["id"] = ban.Id
row["code"] = ban.Code
self.Data["ban"] = row
self.display()
}
func (self *BanController) AjaxSave() {
id, _ := self.GetInt("id")
if id == 0 {
ban := new(models.Ban)
ban.Code = strings.TrimSpace(self.GetString("code"))
ban.CreateTime = time.Now().Unix()
if _, err := models.BanAdd(ban); err != nil {
self.ajaxMsg(err.Error(), MSG_ERR)
}
self.ajaxMsg("", MSG_OK)
}
ban, _ := models.BanGetById(id)
//修改
ban.Id = id
ban.UpdateTime = time.Now().Unix()
ban.Code = strings.TrimSpace(self.GetString("code"))
if err := ban.Update(); err != nil {
self.ajaxMsg(err.Error(), MSG_ERR)
}
self.ajaxMsg("", MSG_OK)
}
func (self *BanController) AjaxDel() {
id, _ := self.GetInt("id")
ban, _ := models.BanGetById(id)
ban.UpdateTime = time.Now().Unix()
ban.Status = 1
if err := ban.Update(); err != nil {
self.ajaxMsg(err.Error(), MSG_ERR)
}
self.ajaxMsg("操作成功", MSG_OK)
}
func (self *BanController) Table() {
//列表
page, err := self.GetInt("page")
if err != nil {
page = 1
}
limit, err := self.GetInt("limit")
if err != nil {
limit = 30
}
code := strings.TrimSpace(self.GetString("code"))
self.pageSize = limit
//查询条件
filters := make([]interface{}, 0)
filters = append(filters, "status", 0)
if code != "" {
filters = append(filters, "code__icontains", code)
}
result, count := models.BanGetList(page, self.pageSize, filters...)
list := make([]map[string]interface{}, len(result))
for k, v := range result {
row := make(map[string]interface{})
row["id"] = v.Id
row["code"] = v.Code
row["create_time"] = beego.Date(time.Unix(v.CreateTime, 0), "Y-m-d H:i:s")
list[k] = row
}
self.ajaxList("成功", MSG_OK, count, list)
}