forked from zzdboy/GoCMS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_group.go
143 lines (125 loc) · 4.48 KB
/
user_group.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
// +----------------------------------------------------------------------
// | GoCMS 0.1
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2014 http://www.6574.com.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: zzdboy <zzdboy1616@163.com>
// +----------------------------------------------------------------------
package models
//会员组
import "time"
import "github.com/revel/revel"
type User_Group struct {
Id int64 `xorm:"pk"`
Name string `xorm:"char(15)"`
Issystem int64 `xorm:"bool"`
Usernum int64 `xorm:"- <- ->"`
Star int64 `xorm:"tinyint(2)"`
Point int64 `xorm:"smallint(6)"`
Allowmessage int64 `xorm:"tinyint(5)"`
Allowvisit int64 `xorm:"bool"`
Allowpost int64 `xorm:"bool"`
Allowpostverify int64 `xorm:"bool"`
Allowsearch int64 `xorm:"bool"`
Allowupgrade int64 `xorm:"bool"`
Allowsendmessage int64 `xorm:"bool"`
Allowpostnum int64 `xorm:"bool"`
Allowattachment int64 `xorm:"bool"`
Priceyear float64 `xorm:"float(8,2)"`
Pricemonth float64 `xorm:"float(8,2)"`
Priceday float64 `xorm:"float(8,2)"`
Icon string `xorm:"char(100)"`
Usernamecolor string `xorm:"char(7)"`
Desc string `xorm:"char(100)"`
Status int64 `xorm:"bool"`
Createtime string `xorm:"DateTime"`
}
//根据Id获取信息
func (u *User_Group) GetById(Id int64) *User_Group {
user_group := new(User_Group)
has, err := DB_Read.Table("user_group").Id(Id).Get(user_group)
if err != nil {
revel.WARN.Println(has)
revel.WARN.Printf("错误: %v", err)
}
return user_group
}
//获取会员组列表
func (u *User_Group) GetGroupList() []*User_Group {
//初始化菜单
group_list := []*User_Group{}
err := DB_Read.Table("user_group").Find(&group_list)
if err != nil {
revel.WARN.Printf("错误: %v", err)
}
if len(group_list) > 0 {
for i, v := range group_list {
group_list[i].Usernum = v.Id
}
}
return group_list
}
//添加会员组
func (u *User_Group) Save() bool {
user_group := new(User_Group)
user_group.Name = u.Name
user_group.Issystem = u.Issystem
user_group.Star = u.Star
user_group.Point = u.Point
user_group.Allowmessage = u.Allowmessage
user_group.Allowvisit = u.Allowvisit
user_group.Allowpost = u.Allowpost
user_group.Allowpostverify = u.Allowpostverify
user_group.Allowsearch = u.Allowsearch
user_group.Allowupgrade = u.Allowupgrade
user_group.Allowsendmessage = u.Allowsendmessage
user_group.Allowpostnum = u.Allowpostnum
user_group.Allowattachment = u.Allowattachment
user_group.Priceyear = u.Priceyear
user_group.Pricemonth = u.Pricemonth
user_group.Priceday = u.Priceday
user_group.Icon = u.Icon
user_group.Usernamecolor = u.Usernamecolor
user_group.Desc = u.Desc
user_group.Status = u.Status
user_group.Createtime = time.Now().Format("2006-01-02 15:04:04")
has, err := DB_Write.Table("user_group").Insert(user_group)
if err != nil {
revel.WARN.Println(has)
revel.WARN.Printf("错误: %v", err)
return false
}
return true
}
//编辑会员组
func (u *User_Group) Edit(Id int64) bool {
user_group := new(User_Group)
user_group.Name = u.Name
user_group.Star = u.Star
user_group.Point = u.Point
user_group.Allowmessage = u.Allowmessage
user_group.Allowvisit = u.Allowvisit
user_group.Allowpost = u.Allowpost
user_group.Allowpostverify = u.Allowpostverify
user_group.Allowsearch = u.Allowsearch
user_group.Allowupgrade = u.Allowupgrade
user_group.Allowsendmessage = u.Allowsendmessage
user_group.Allowpostnum = u.Allowpostnum
user_group.Allowattachment = u.Allowattachment
user_group.Priceyear = u.Priceyear
user_group.Pricemonth = u.Pricemonth
user_group.Priceday = u.Priceday
user_group.Icon = u.Icon
user_group.Usernamecolor = u.Usernamecolor
user_group.Desc = u.Desc
user_group.Status = u.Status
has, err := DB_Write.Table("user_group").Id(Id).Cols("name", "star", "point", "allowmessage", "allowvisit", "allowpost", "allowpostverify", "allowsearch", "allowupgrade", "allowsendmessage", "allowpostnum", "allowattachment", "priceyear", "pricemonth", "priceday", "icon", "usernamecolor", "desc", "status").Update(user_group)
if err != nil {
revel.WARN.Println(has)
revel.WARN.Printf("错误: %v", err)
return false
}
return true
}