package renzhengshouquan import ( "shylinux.com/x/ice" kit "shylinux.com/x/toolkits" "shylinux.com/x/community/src/renzhengshouquan/model" ) type Auth struct { Table cert cert order string `data:"2"` models string `data:"auth"` fields string `data:"from_uid,name,info,auth_type,auth_status,avatar,background,service_uid,place_uid,user_uid"` memberList string `name:"memberList" role:"leader,worker"` certList string `name:"certList" role:"leader,worker"` issue string `name:"issue" role:"leader,worker"` revoke string `name:"revoke" role:"leader,worker"` } func (s Auth) List(m *ice.Message, arg ...string) { if len(arg) == 1 { s.Select(m, model.FROM_UID, arg[0]).Action() } else if len(arg) == 2 { s.SelectDetail(m, model.FROM_UID, arg[0], model.UID, arg[1]).Action(s.CertList, s.MemberList) } m.Table(func(value ice.Maps) { switch AuthStatus(kit.Int(value[model.AUTH_STATUS])) { case AuthCreate: m.PushButton(s.Issue) case AuthIssued: m.PushButton(s.Revoke) case AuthRevoked: m.PushButton(s.Issue) default: m.PushButton() } }).Display("") } func (s Auth) SelectList(m *ice.Message, arg ...string) { s.Table.SelectList(m, arg...).RenameAppend(model.TYPE, model.AUTH_TYPE, model.STATUS, model.AUTH_STATUS) s.RewriteAppend(m) } func (s Auth) MemberList(m *ice.Message, arg ...string) { m.Cmdy(m.Prefix("member"), arg[0]) } func (s Auth) CertList(m *ice.Message, arg ...string) { m.Cmdy(s.cert, arg[0]).Action() kit.If(m.Length() == 0, func() { m.Echo("没有上传证件") }) } func (s Auth) Issue(m *ice.Message, arg ...string) { msg := s.Select(m.Spawn(), model.UID, m.Option(model.AUTH_UID)) if !m.IsTech() || AuthType(kit.Int(msg.Append(model.AUTH_TYPE))) != AuthRoot { if m.WarnNotValid(AuthStatus(kit.Int(msg.Append(model.AUTH_STATUS))) != AuthIssued, "本服务还未认证") { return } } s.Update(m, kit.Dict(model.STATUS, AuthIssued), model.FROM_UID, m.Option(model.AUTH_UID), model.UID, m.Option(model.UID)) } func (s Auth) Revoke(m *ice.Message, arg ...string) { s.Update(m, kit.Dict(model.STATUS, AuthRevoked), model.FROM_UID, m.Option(model.AUTH_UID), model.UID, m.Option(model.UID)) } func init() { ice.TeamCtxCmd(Auth{}) } type AuthType int const ( AuthRoot AuthType = iota AuthCity // 1 AuthPersonal // 2 AuthService // 3 AuthCompany // 4 AuthSchool // 5 AuthStreet // 6 ) var AuthTypeList = map[AuthType]string{ AuthRoot: "root", AuthCity: "city", AuthPersonal: "personal", AuthService: "service", AuthCompany: "company", AuthSchool: "school", AuthStreet: "street", } func (s AuthType) String() string { return AuthTypeList[s] } type AuthStatus int const ( AuthCreate AuthStatus = iota AuthRequest AuthIssued AuthRevoked ) var AuthStatusList = map[AuthStatus]string{ AuthCreate: "create", AuthRequest: "request", AuthIssued: "issued", AuthRevoked: "revoked", } func (s AuthStatus) String() string { return AuthStatusList[s] }