package gonganxitong import ( "net/http" "time" "shylinux.com/x/ice" "shylinux.com/x/icebergs/base/aaa" "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/web" kit "shylinux.com/x/toolkits" "shylinux.com/x/community/src/api" "shylinux.com/x/community/src/gonganxitong/model" ) type user struct { Table setting setting order string `data:"509"` role string `data:"tech"` template string `data:"zJjgEbfiVKgJ_eDLfvHB_lXEzitNuxwZk0UHeTsFRns"` fields string `data:"auth_uid,open_id,language,name,info,avatar,background,status"` create string `name:"create open_id* avatar usernick"` modify string `name:"modify info" role:"void"` list string `name:"list uid auto" role:"void"` setCookie string `name:"setCookie" help:"切换"` sendCookie string `name:"sendCookie" help:"授权" role:"void"` authRemove string `name:"authRemove" help:"删除认证" role:"void"` email string `name:"email email*"` } func (s user) Create(m *ice.Message, arg ...string) { m.OptionDefault(aaa.AVATAR, m.Option(ice.MSG_AVATAR), aaa.USERNICK, m.Option(ice.MSG_USERNICK)) args := kit.Simple(m.OptionSimple(model.AVATAR), model.NAME, m.Option(aaa.USERNICK), model.LANGUAGE, m.Option(ice.MSG_LANGUAGE)) if msg := s.Table.Select(m.Spawn(), m.OptionSimple(model.OPEN_ID)...); msg.Length() == 0 { s.Insert(m, kit.Simple(m.OptionSimple(model.OPEN_ID), args)...) m.Option(model.USER_UID, m.Result()) } else { s.Update(m, args, msg.AppendSimple(model.UID)...) m.Option(model.USER_UID, msg.Append(model.UID)) } } func (s user) Modify(m *ice.Message, arg ...string) { s.Update(m, kit.Dict(m.OptionSimple(model.INFO)), model.UID, m.Option(model.USER_UID)) } func (s user) Remove(m *ice.Message, arg ...string) { s.Delete(m, m.OptionSimple(model.UID)...) } func (s user) List(m *ice.Message, arg ...string) { s.Tables(m, "LEFT JOIN sesses ON users.uid = sesses.user_uid").Groups(m, "user_uid").Orders(m, s.Desc("sesses.created_at")) s.FieldsWithCreatedAT(m, s, kit.Split("auth_uid,name,info,avatar,background,status,agent,system,location,ip,ua")).Limit(m, 3000) if len(arg) == 0 { if m.IsTech() { s.Limit(m, 3000) s.Select(m, arg...) m.EchoQRCode(m.MergePodCmd("", m.PrefixKey()+"/action/sendCookie", ice.FROM_DAEMON, m.Option(ice.MSG_DAEMON))).Echo("
").Echo("请扫码授权") m.StatusTimeCount(mdb.TOTAL, s.SelectTotal(m)) } } else { s.SelectDetail(m, s.Key(s, model.UID), arg[0]) if m.Append(model.AUTH_UID) == "" && arg[0] == m.Option(model.USER_UID) { m.EchoInfoButton("请申请个人认证", s.AuthCreate) } } s.SelectJoinAuth(m) m.Table(func(value ice.Maps) { button := []ice.Any{} defer func() { m.PushButton(button...) }() if value[model.AUTH_UID] != "" && value[model.AUTH_STATUS] != "issued" && (value[model.UID] == m.Option(ice.MSG_USERUID) || m.IsTech()) { button = append(button, s.AuthRemove) } button = append(button, s.AuthRemove) if m.IsTech() && value[model.UID] != m.Option(ice.MSG_USERUID) { button = append(button, s.SetCookie, s.Remove) } if m.IsTech() { if value[model.STATUS] == "1" { button = append(button, s.Enable) } else { button = append(button, s.Disable) } } }) } func (s user) SelectTotal(m *ice.Message, arg ...string) string { msg := m.Spawn() s.Fields(msg, "count(*) AS total") return s.Select(msg, arg...).Append(model.TOTAL) } func (s user) AuthCreate(m *ice.Message, arg ...string) { msg := s.Select(m.Spawn(), model.UID, m.Option(model.USER_UID)) if msg.Length() == 0 { s.Insert(m.Spawn(), model.UID, m.Option(model.USER_UID), model.NAME, m.Option(ice.MSG_USERNAME)) m.Options(model.NAME, m.Option(ice.MSG_USERNAME)) } else { m.Options(msg.AppendSimple(model.NAME, model.INFO)) } s.Table.AuthCreate(m, api.AuthPersonal, m.Option(model.AUTH_UID)) } func (s user) AuthRemove(m *ice.Message, arg ...string) { if m.WarnNotRight(!m.IsTech() && m.Option(model.UID) != m.Option(ice.MSG_USERUID)) { return } msg := s.Select(m.Spawn(), m.OptionSimple(model.UID)...) if m.WarnNotValid(msg.Append(model.AUTH_UID) == "") { return } m.Cmd(api.RENZHENGSHOUQUAN_CLEAN, "prune", msg.Option(model.AUTH_UID)) s.Update(m, ice.Maps{model.AUTH_UID: ""}, m.OptionSimple(model.UID)...) } func (s user) Disable(m *ice.Message, arg ...string) { s.Update(m, kit.Dict(model.STATUS, UserDisabled), m.OptionSimple(model.UID)...) } func (s user) Enable(m *ice.Message, arg ...string) { s.Update(m, kit.Dict(model.STATUS, "0"), m.OptionSimple(model.UID)...) } func (s user) SetCookie(m *ice.Message, arg ...string) { m.ProcessCookie(ice.MSG_USERUID, m.Option(model.UID)) } func (s user) SendCookie(m *ice.Message, arg ...string) { if m.Option(ice.MSG_METHOD) == http.MethodGet { m.EchoInfoButton("请确认授权", s.SendCookie) } else { m.Cmd(web.SPACE, m.Option(ice.FROM_DAEMON), "cookie", m.Option(ice.MSG_USERUID), ice.MSG_USERUID) } } func (s user) SendTemplate(m *ice.Message, arg ...string) { // from uid url type name hash time msg := s.Select(m, model.UID, kit.Select(m.Option(ice.MSG_USERUID), arg, 1)) m.Cmdy("web.chat.wx.template", "", m.Config(nfs.TEMPLATE), msg.Append(model.OPEN_ID), kit.Select("", arg, 2), "thing7", kit.Select("", arg, 3), "thing12", kit.Select("", arg, 4), "character_string2", kit.Cut(kit.Select("", arg, 5), 6), "thing18", kit.Select(kit.Select(m.Option(ice.MSG_USERNAME), m.Option(ice.MSG_USERNICK)), arg, 0), "time11", time.Now().Format("2006年01月02日 15:04"), ) } func (s user) Email(m *ice.Message, arg ...string) { s.Table.Update(m, kit.Dict(m.OptionSimple(model.EMAIL))) } func init() { ice.TeamCtxCmd(user{}) } type UserStatus int const ( UserEnabled UserStatus = iota UserDisabled )