-
Notifications
You must be signed in to change notification settings - Fork 0
/
fields_user.go
195 lines (174 loc) · 5.36 KB
/
fields_user.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package UserCore
import (
"database/sql/driver"
"encoding/json"
"errors"
CoreSQLConfig "github.com/fotomxq/weeekj_core/v5/core/sql/config"
"github.com/lib/pq"
"time"
)
// FieldsUserType 用户结构
type FieldsUserType struct {
//ID
ID int64 `db:"id" json:"id"`
//创建时间
CreateAt time.Time `db:"create_at" json:"createAt"`
//更新时间
UpdateAt time.Time `db:"update_at" json:"updateAt"`
//删除时间
DeleteAt time.Time `db:"delete_at" json:"deleteAt"`
//状态
// 0 -> ban后,用户可以正常登录,但一切内容无法使用
// 1 -> audit后,用户登录后无法正常使用,但提示不太一样
// 2 -> public 正常访问
Status int `db:"status" json:"status"`
//组织ID
// 如果为空,则说明是平台的用户;否则为对应组织的用户
// 所有获取的方法,都需要给与该ID参数,也可以留空,否则禁止获取
OrgID int64 `db:"org_id" json:"orgID"`
//姓名
Name string `db:"name" json:"name"`
//密码
Password string `db:"password" json:"password"`
//绑定手机号的国家代码
NationCode string `db:"nation_code" json:"nationCode"`
//手机号码,绑定后的手机
Phone string `db:"phone" json:"phone"`
//手机是否验证
PhoneVerify time.Time `db:"phone_verify" json:"phoneVerify"`
//邮箱,如果不存在手机则必须存在的
Email string `db:"email" json:"email"`
//邮箱是否验证
EmailVerify time.Time `db:"email_verify" json:"emailVerify"`
//用户名,如果不存在手机号和邮箱,则必须存在的
Username string `db:"username" json:"username"`
//用户头像
Avatar int64 `db:"avatar" json:"avatar"`
//上级关系
Parents FieldsUserParents `db:"parents" json:"parents"`
//用户组
Groups FieldsUserGroupsType `db:"groups" json:"groups"`
//信息结构体
// 特殊情况下,如果不希望创建新的模块,可以使用该字段实现特定目标
// 例如是否进入过某个页面,或是否进行过某些行为的标识码
Infos CoreSQLConfig.FieldsConfigsType `db:"infos" json:"infos"`
//登录结构体
// 提供给第三方登录的数据接口
Logins FieldsUserLoginsType `db:"logins" json:"logins"`
//用户分类
SortID int64 `db:"sort_id" json:"sortID"`
//用户标签
Tags pq.Int64Array `db:"tags" json:"tags"`
}
// FieldsUserParents 上下级关系处理
type FieldsUserParents []FieldsUserParent
func (t FieldsUserParents) Value() (driver.Value, error) {
return json.Marshal(t)
}
func (t *FieldsUserParents) Scan(value interface{}) error {
b, ok := value.([]byte)
if !ok {
return errors.New("type assertion to []byte failed")
}
return json.Unmarshal(b, &t)
}
type FieldsUserParent struct {
//系统类型标识码
// 用于指定不同类型的系统、模块的上下级关系
// eg: transport / finance
System string `db:"system" json:"system"`
//上级ID
ParentID int64 `db:"parentID" json:"parentID"`
//权限标记
Operate []string `db:"operate" json:"operate"`
}
func (t FieldsUserParent) Value() (driver.Value, error) {
return json.Marshal(t)
}
func (t *FieldsUserParent) Scan(value interface{}) error {
b, ok := value.([]byte)
if !ok {
return errors.New("type assertion to []byte failed")
}
return json.Unmarshal(b, &t)
}
// FieldsUserGroupsType 用户组信息结构
type FieldsUserGroupsType []FieldsUserGroupType
func (t FieldsUserGroupsType) Value() (driver.Value, error) {
return json.Marshal(t)
}
func (t *FieldsUserGroupsType) Scan(value interface{}) error {
b, ok := value.([]byte)
if !ok {
return errors.New("type assertion to []byte failed")
}
return json.Unmarshal(b, &t)
}
type FieldsUserGroupType struct {
//用户组ID
GroupID int64 `db:"group_id" json:"groupID"`
//创建时间
CreateAt time.Time `db:"create_at" json:"createAt"`
//过期时间
ExpireAt time.Time `db:"expire_at" json:"expireAt"`
}
// sql底层处理器
func (t FieldsUserGroupType) Value() (driver.Value, error) {
return json.Marshal(t)
}
func (t *FieldsUserGroupType) Scan(value interface{}) error {
b, ok := value.([]byte)
if !ok {
return errors.New("type assertion to []byte failed")
}
return json.Unmarshal(b, &t)
}
// FieldsUserLoginsType 登录结构体
type FieldsUserLoginsType []FieldsUserLoginType
// Value sql底层处理器
func (t FieldsUserLoginsType) Value() (driver.Value, error) {
return json.Marshal(t)
}
func (t *FieldsUserLoginsType) Scan(value interface{}) error {
b, ok := value.([]byte)
if !ok {
return errors.New("type assertion to []byte failed")
}
return json.Unmarshal(b, &t)
}
// SetUserLogins 写入数据
func SetUserLogins(data FieldsUserLoginsType, mark string, val string, config string) FieldsUserLoginsType {
for k, v := range data {
if v.Mark == mark {
data[k].Val = val
data[k].Config = config
return data
}
}
data = append(data, FieldsUserLoginType{
Mark: mark,
Val: val,
Config: config,
})
return data
}
type FieldsUserLoginType struct {
//标识码
Mark string `db:"mark" json:"mark"`
//值
Val string `db:"val" json:"val"`
//配置结构
// 可任意建立,主要指一些特定的标记,如API反馈的原始数据等
Config string `db:"config" json:"config"`
}
// Value sql底层处理器
func (t FieldsUserLoginType) Value() (driver.Value, error) {
return json.Marshal(t)
}
func (t *FieldsUserLoginType) Scan(value interface{}) error {
b, ok := value.([]byte)
if !ok {
return errors.New("type assertion to []byte failed")
}
return json.Unmarshal(b, &t)
}