menu_app.go
1.4 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
package models
import (
"time"
"github.com/astaxie/beego/orm"
)
type MenuApp 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:"菜单地址"`
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 *MenuApp) TableName() string {
return "menu_app"
}
func init() {
orm.RegisterModel(new(MenuApp))
}
// GetMenuAppById retrieves MenuApp by Id. Returns error if
// Id doesn't exist
func GetMenuAppById(id int) (v *MenuApp, err error) {
o := orm.NewOrm()
v = &MenuApp{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
func GetMenuApp() (v []*MenuApp, err error) {
o := orm.NewOrm()
sql := "select * from menu_app where enabled=1 order by sort"
if _, err = o.Raw(sql).QueryRows(&v); err == nil {
return
}
return
}