menu.go
1.8 KB
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
package models
import (
"time"
"github.com/astaxie/beego/orm"
)
type Menu struct {
Id int `orm:"column(id);auto" description:"主键"`
Name string `orm:"column(name);size(10)" description:"菜单名称"`
Icon string `orm:"column(icon);size(128)" description:"菜单图标地址"`
ParentId int `orm:"column(parent_id)" description:"上一级菜单 id"`
Type int `orm:"column(type)" description:"类型:1为 pc 2为app"`
Url string `orm:"column(url);size(128)" description:"菜单地址"`
SeniorStatus int `orm:"column(senior_status)" description:"类型:是否有高级设置 1是 0 否"`
Code string `orm:"column(code);size(128)" description:"菜单编码"`
Sort int `orm:"column(sort)" description:"同级菜单序号 "`
CreateTime time.Time `orm:"column(create_time);type(timestamp);null" description:"创建时间"`
Enabled int8 `orm:"column(enabled)" description:"是否有效"`
}
func (t *Menu) TableName() string {
return "menu"
}
func init() {
orm.RegisterModel(new(Menu))
}
// GetMenuById retrieves Menu by Id. Returns error if
// Id doesn't exist
func GetMenuById(id int) (v *Menu, err error) {
o := orm.NewOrm()
v = &Menu{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
func GetMenuByIds(ids []int64) (v []*Menu, err error) {
o := orm.NewOrm()
_, err = o.QueryTable(&Menu{}).
Filter("id__in", ids).
All(&v)
if err == orm.ErrNoRows {
return v, nil
}
return v, nil
}
func GetMenuByCode(code string) (*Menu, error) {
var (
menuinfo = &Menu{}
err error
)
o := orm.NewOrm()
err = o.QueryTable(&Menu{}).
Filter("code", code).
One(menuinfo)
if err != nil {
return nil, err
}
return menuinfo, nil
}