mirror of
https://shylinux.com/x/community
synced 2025-05-01 19:59:22 +08:00
138 lines
5.0 KiB
Go
138 lines
5.0 KiB
Go
package gonganxitong
|
|
|
|
import (
|
|
"shylinux.com/x/ice"
|
|
kit "shylinux.com/x/toolkits"
|
|
|
|
"shylinux.com/x/community/src/gonganxitong/model"
|
|
)
|
|
|
|
type apply struct {
|
|
Table
|
|
user user
|
|
event event
|
|
portal Portal
|
|
order string `data:"91"`
|
|
role string `data:"creator"`
|
|
create string `name:"create user_place_role*:select begin_time:select@date end_time:select@date" role:"void"`
|
|
cancel string `name:"cancel" role:"void"`
|
|
submit string `name:"submit" role:"void"`
|
|
}
|
|
|
|
func (s apply) Init(m *ice.Message, arg ...string) {
|
|
s.Table.Init(m, arg...)
|
|
place_uid, user_place_role := s.Keys(s.Place, model.UID), s.Keys(s.UserPlace, model.ROLE)
|
|
m.Design(s.Create, "", user_place_role+"*:select")
|
|
m.Design(s.List, "", kit.JoinWord(place_uid, model.UID, ice.AUTO))
|
|
}
|
|
func (s apply) Inputs(m *ice.Message, arg ...string) {
|
|
s.UserPlace.Inputs(m, arg...)
|
|
}
|
|
func (s apply) Create(m *ice.Message, arg ...string) {
|
|
PLACE_UID := s.Keys(s.Place, model.UID)
|
|
USER_PLACE_ROLE := s.Keys(s.UserPlace, model.ROLE)
|
|
arg = kit.TransArgKeys(arg, PLACE_UID, model.PLACE_UID)
|
|
arg = kit.TransArgKeys(arg, USER_PLACE_ROLE, model.ROLE)
|
|
s.Table.Create(m, kit.Simple(model.PLACE_UID, m.Option(PLACE_UID), arg, m.OptionSimple(model.USER_UID), model.STATUS, ApplyCreate)...)
|
|
m.ProcessRewrite(model.UID, m.Result())
|
|
}
|
|
func (s apply) List(m *ice.Message, arg ...string) {
|
|
s.Tables(m, s.user).FieldsWithCreatedAT(m, s, model.USER_AVATAR, model.USER_NAME,
|
|
model.PLACE_UID, s.AS(s.Key(s, model.ROLE), s.Keys(s.UserPlace, model.ROLE)), model.APPLY_STATUS,
|
|
model.BEGIN_TIME, model.END_TIME,
|
|
)
|
|
if len(arg) == 1 {
|
|
s.Table.Select(m, model.USER_UID, m.Option(model.USER_UID), model.PLACE_UID, arg[0])
|
|
s.Button(m, "")
|
|
} else if len(arg) == 2 {
|
|
s.Table.SelectDetail(m, model.USER_UID, m.Option(model.USER_UID), model.PLACE_UID, arg[0], s.Key(s, model.UID), arg[1])
|
|
switch ApplyStatus(kit.Int(m.Append(model.APPLY_STATUS))) {
|
|
case ApplySubmit:
|
|
m.EchoQRCode(s.portal.Link(m, arg[0], ice.GetTypeKey(allow{}), arg[1]))
|
|
case ApplyRejected, ApplyApproved:
|
|
s.DoneMessage(m)
|
|
}
|
|
} else {
|
|
return
|
|
}
|
|
s.RenameAppend(m, model.PLACE_UID, s.Keys(s.Place, model.UID)).SelectJoin(m, s.Place, model.NAME, model.TYPE)
|
|
m.Table(func(value ice.Maps) {
|
|
if ApplyStatus(kit.Int(value[model.APPLY_STATUS])) == ApplyCreate {
|
|
m.PushButton(s.Cancel, s.Submit)
|
|
} else {
|
|
m.PushButton()
|
|
}
|
|
})
|
|
s.DisplayBase(m, "")
|
|
}
|
|
func (s apply) Cancel(m *ice.Message, arg ...string) {
|
|
s.changeStatus(m, ApplyCreate, ApplyCancel)
|
|
}
|
|
func (s apply) Submit(m *ice.Message, arg ...string) {
|
|
msg := s.changeStatus(m, ApplyCreate, ApplySubmit)
|
|
if m.WarnNotValid(msg.IsErr()) {
|
|
return
|
|
}
|
|
defer m.ToastProcess()()
|
|
role := UserPlaceCreator
|
|
switch UserPlaceRole(kit.Int(msg.Append(model.ROLE))) {
|
|
case UserPlaceLandlord:
|
|
role = UserPlaceCreator
|
|
case UserPlaceTenant, UserPlaceAdmin:
|
|
role = UserPlaceLandlord
|
|
}
|
|
msg = m.Cmd(s.UserPlace, s.Select, m.OptionSimple(s.Keys(s.Place, model.UID)), model.ROLE, role)
|
|
if m.WarnNotFound(msg.Length() == 0, role.String()) {
|
|
return
|
|
}
|
|
m.Option(model.FROM_USER_UID, m.Option(model.USER_UID))
|
|
m.Cmd(s.Prefix(m, allow{}), s.Create, model.APPLY_UID, m.Option(model.UID), model.PLACE_UID, m.Option(s.Keys(s.Place, model.UID)), msg.AppendSimple(model.USER_UID), model.STATUS, AllowCreate)
|
|
s.RecordEvent(m, kit.JoinWord("🕑", m.Trans("role apply submit", "权限申请 已提交"), kit.Cut(m.Option(model.UID), 6), s.TransRole(m), m.Option(model.USER_NAME)), m.Option(model.UID))
|
|
s.SendMessage(m, msg.Append(model.USER_UID), m.Option(model.USER_UID))
|
|
}
|
|
func (s apply) Reject(m *ice.Message, arg ...string) {
|
|
msg := s.changeStatus(m, ApplySubmit, ApplyRejected)
|
|
s.sendTemplate(msg, m.Trans("role apply rejected", "权限申请 已驳回"))
|
|
}
|
|
func (s apply) Approve(m *ice.Message, arg ...string) {
|
|
msg := s.changeStatus(m, ApplySubmit, ApplyApproved)
|
|
m.Cmd(s.UserPlace, s.Create, msg.AppendSimple(model.USER_UID, model.ROLE), s.Keys(s.Place, model.UID), msg.Append(model.PLACE_UID))
|
|
s.sendTemplate(msg, m.Trans("role apply approved", "权限申请 已通过"))
|
|
}
|
|
|
|
func init() { ice.TeamCtxCmd(apply{Table: newTable()}) }
|
|
|
|
func (s apply) changeStatus(m *ice.Message, from, todo ApplyStatus, arg ...string) *ice.Message {
|
|
msg := s.Table.Select(m.Spawn(), m.OptionSimple(model.UID)...)
|
|
if !m.WarnNotFound(msg.Length() == 0, m.Option(model.UID)) {
|
|
if status := ApplyStatus(kit.Int(msg.Append(model.STATUS))); !m.WarnNotValid(status != from, status.String()) {
|
|
s.Table.Update(m, kit.Dict(model.STATUS, todo), m.OptionSimple(model.UID)...)
|
|
}
|
|
}
|
|
return msg
|
|
}
|
|
func (s apply) sendTemplate(m *ice.Message, info string) *ice.Message {
|
|
s.Table.SendTemplate(m, "", m.Append(model.USER_UID), info)
|
|
return m
|
|
}
|
|
|
|
type ApplyStatus int
|
|
|
|
const (
|
|
ApplyCreate ApplyStatus = iota
|
|
ApplyCancel
|
|
ApplySubmit
|
|
ApplyRejected
|
|
ApplyApproved
|
|
)
|
|
|
|
var ApplyStatusList = map[ApplyStatus]string{
|
|
ApplyCreate: "create",
|
|
ApplyCancel: "cancel",
|
|
ApplySubmit: "submit",
|
|
ApplyRejected: "rejected",
|
|
ApplyApproved: "approved",
|
|
}
|
|
|
|
func (s ApplyStatus) String() string { return ApplyStatusList[s] }
|