community/src/gonganxitong/paymentlist.go
2024-12-06 09:00:24 +08:00

97 lines
2.6 KiB
Go

package gonganxitong
import (
"shylinux.com/x/ice"
kit "shylinux.com/x/toolkits"
"shylinux.com/x/community/src/gonganxitong/model"
)
type paymentlist struct {
Table
order string `data:"92"`
auth_uid string `data:""`
fields string `data:"title,content,amount,paymentlist_status,user_uid"`
create string `name:"create amount* title* content" role:"leader"`
payfor string `name:"payfor" help:"支付" style:"notice" role:"void"`
}
func (s paymentlist) Create(m *ice.Message, arg ...string) {
for i := 0; i < len(arg)-1; i += 2 {
if arg[i] == model.AMOUNT {
arg[i+1] = kit.Format(kit.Int(kit.Float(arg[i+1]) * 100))
}
}
m.Option(model.PLACE_UID, m.Option(s.PLACE_UID))
s.Insert(m, kit.Simple(arg, m.OptionSimple(model.PLACE_UID, model.USER_UID))...)
s.RecordEventWithName(m, "")
}
func (s paymentlist) List(m *ice.Message, arg ...string) {
if len(arg) == 1 {
s.Select(m, model.PLACE_UID, arg[0])
} else if len(arg) == 2 {
s.SelectDetail(m, model.PLACE_UID, arg[0], model.UID, arg[1])
if PaymentStatus(kit.Int(m.Append(model.PAYMENTLIST_STATUS))) == PaymentCreate {
m.EchoQRCode(s.Link(m, arg[0], m.PrefixKey(), arg[1])).Echo("请用微信扫码支付")
}
} else {
return
}
m.Table(func(value ice.Maps) {
switch PaymentStatus(kit.Int(value[model.PAYMENTLIST_STATUS])) {
case PaymentCreate:
m.PushButton(s.Payfor)
case PaymentSuccess:
m.PushButton()
default:
m.PushButton()
}
}).Display("")
s.SelectJoinUser(m)
}
func (s paymentlist) Payfor(m *ice.Message, arg ...string) {
s.cmdy(m, s.Request, arg...)
}
func (s paymentlist) Request(m *ice.Message, arg ...string) {
}
func (s paymentlist) Response(m *ice.Message, arg ...string) {
if len(arg) > 1 {
s.Update(m, kit.Dict(model.STATUS, PaymentSuccess), s.PLACE_UID, arg[0], model.UID, arg[1])
}
}
func init() { ice.TeamCtxCmd(paymentlist{Table: newTable()}) }
func (s paymentlist) cmdy(m *ice.Message, action ice.Any, arg ...string) {
m.Options(model.PLACE_UID, m.Option(s.PLACE_UID)).Cmdy(paymentVendorKey, action, arg)
}
type PaymentStatus int
const (
PaymentCreate PaymentStatus = iota
PaymentSuccess
PaymentFailure
)
var PaymentStatusList = map[PaymentStatus]string{
PaymentCreate: "create",
PaymentSuccess: "success",
PaymentFailure: "failure",
}
func (s PaymentStatus) String() string { return PaymentStatusList[s] }
type PaymentVendor interface {
Request(m *ice.Message, arg ...string)
Response(m *ice.Message, arg ...string)
}
var paymentVendorKey string
var paymentVendorList = map[string]PaymentVendor{}
func PaymentVendorAdd(key string, vendor PaymentVendor) {
paymentVendorKey, paymentVendorList[key] = key, vendor
}