2025-06-17 14:54:43 +08:00

79 lines
2.6 KiB
Go

package renzhengshouquan
import (
"shylinux.com/x/ice"
kit "shylinux.com/x/toolkits"
"shylinux.com/x/community/src/renzhengshouquan/model"
)
type transition struct {
Table
order string `data:"5"`
auth string `data:"issued"`
role string `data:"leader,worker"`
create string `name:"create transition_type* amount* title content from_account_uid to_account_uid" role:"leader"`
remove string `name:"remove" role:"leader"`
}
func (s transition) List(m *ice.Message, arg ...string) {
s.Tables(m,
"LEFT JOIN accounts AS to_accounts ON to_account_uid = to_accounts.uid",
"LEFT JOIN auths AS to_auths ON to_accounts.auth_uid = to_auths.uid",
"LEFT JOIN accounts AS from_accounts ON from_account_uid = from_accounts.uid",
"LEFT JOIN auths AS from_auths ON from_accounts.auth_uid = from_auths.uid",
).FieldsWithCreatedAT(m, s,
"transition_type", "transition_status", s.Key(s, model.AMOUNT), s.Key(s, model.USER_UID),
"from_account_uid", "from_auths.uid AS from_auth_uid", "from_auth_name", "from_auth_type", "from_auth_avatar",
"to_account_uid", "to_auths.uid AS to_auth_uid", "to_auth_name", "to_auth_type", "to_auth_avatar",
)
if len(arg) == 1 {
if !s.IsWorker(m) {
return
}
s.Select(m, "to_auths.uid = ? OR from_auths.uid = ?", arg[0], arg[0])
} else {
s.Select(m, "transitions.uid = ? AND (to_auths.uid = ? OR from_auths.uid = ?)", arg[1], arg[0], arg[0])
}
m.Table(func(value ice.Maps) {
switch TransitionType(kit.Int(value["transition_type"])) {
case TransitionRecharge:
m.Push(model.NAME, value["to_auth_name"])
m.Push(model.AUTH_TYPE, value["to_auth_type"])
m.Push(model.ICON, value["to_auth_avatar"])
case TransitionTransfer:
if value["from_auth_uid"] == arg[0] {
m.Push(model.NAME, value["to_auth_name"])
m.Push(model.AUTH_TYPE, value["to_auth_type"])
m.Push(model.ICON, value["to_auth_avatar"])
} else {
m.Push(model.NAME, value["from_auth_name"])
m.Push(model.AUTH_TYPE, value["from_auth_type"])
m.Push(model.ICON, value["from_auth_avatar"])
}
case TransitionWithdraw:
m.Push(model.NAME, value["from_auth_name"])
m.Push(model.AUTH_TYPE, value["from_auth_type"])
m.Push(model.ICON, value["from_auth_avatar"])
}
}).Action().Display("").DisplayCSS("")
}
func init() { ice.TeamCtxCmd(transition{}) }
type TransitionType int
const (
TransitionRecharge TransitionType = iota
TransitionTransfer
TransitionWithdraw
)
var TransitionTypeList = map[TransitionType]string{
TransitionRecharge: "充值",
TransitionTransfer: "转账",
TransitionWithdraw: "提现",
}
func (s TransitionType) String() string { return TransitionTypeList[s] }