/
tool.go
77 lines (71 loc) · 1.57 KB
/
tool.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
package admintool
import (
"github.com/i2eco/ecology/appgo/dao"
"github.com/i2eco/ecology/appgo/model/mysql"
"github.com/i2eco/ecology/appgo/pkg/mus"
"github.com/i2eco/ecology/appgo/router/core"
)
func List(c *core.Context) {
req := ReqList{}
if err := c.Bind(&req); err != nil {
c.JSONErrTips("参数错误", err)
return
}
total, list := dao.Tool.ListPage(c.Context, mysql.Conds{}, &req.ReqPage)
c.JSONList(list, req.ReqPage.Current, req.ReqPage.PageSize, total)
}
func Info(c *core.Context) {
req := ReqInfo{}
err := c.Bind(&req)
if err != nil {
c.JSONErrTips("参数错误", err)
return
}
resp, err := dao.Seo.Info(c.Context, req.Id)
if err != nil {
c.JSONErrTips("获取信息失败", err)
return
}
c.JSONOK(resp)
}
func Create(c *core.Context) {
req := ReqCreate{}
err := c.Bind(&req)
if err != nil {
c.JSONErrTips("参数错误", err)
return
}
createInfo := &mysql.Tool{
Name: req.Name,
Desc: req.Desc,
Identify: req.Identify,
Cover: req.Cover,
Uid: c.AdminUid(),
}
err = dao.Tool.Create(c.Context, mus.Db, createInfo)
if err != nil {
c.JSONErrTips("创建失败1", err)
return
}
c.JSONOK()
}
func Update(c *core.Context) {
req := ReqUpdate{}
err := c.Bind(&req)
if err != nil {
c.JSONErrTips("参数错误", err)
return
}
err = mus.Db.Model(mysql.Tool{}).Where("id = ?", req.Id).UpdateColumns(&mysql.Tool{
Name: req.Name,
Desc: req.Desc,
Identify: req.Identify,
Cover: req.Cover,
Uid: c.AdminUid(),
}).Error
if err != nil {
c.JSONErrTips("更新失败", err)
return
}
c.JSONOK()
}