2024-12-04 14:39:53 +08:00

114 lines
3.4 KiB
Go

package renzhengshouquan
import (
"math/rand"
"shylinux.com/x/ice"
"shylinux.com/x/icebergs/base/mdb"
kit "shylinux.com/x/toolkits"
"shylinux.com/x/community/src/renzhengshouquan/model"
)
type cert struct {
Table
order string `data:"1"`
fields string `data:"cert_status,path,number,name,type,person,address,mobile,verify,user_uid"`
upload string `name:"upload" role:"leader"`
remove string `name:"remove" role:"leader"`
verify string `name:"verify mobile* verify*" style:"notice" role:"leader"`
}
func (s cert) Upload(m *ice.Message, arg ...string) {
p := s.UploadCreate(m.Options(mdb.FIELD, "cert"), model.PATH, "")
switch AuthType(kit.Int(m.Cmd(Auth{}, s.Select, model.UID, m.Option(model.AUTH_UID)).Append(model.AUTH_TYPE))) {
case AuthPersonal:
msg := m.Cmd(OcrVendor, OcrVendor.IDCard, p)
s.Update(m, kit.Dict(
model.NUMBER, msg.Append("IdNum"),
model.NAME, msg.Append("Name"),
model.TYPE, msg.Append("Sex"),
model.BIRTH, msg.Append("Birth"),
model.ADDRESS, msg.Append("Address"),
), m.OptionSimple(model.AUTH_UID)...)
case AuthCompany:
msg := m.Cmd(OcrVendor, OcrVendor.BizLicense, p)
s.Update(m, kit.Dict(
model.NUMBER, msg.Append("RegNum"),
model.NAME, msg.Append("Name"),
model.TYPE, msg.Append("Type"),
model.PERSON, msg.Append("Person"),
model.PERIOD, msg.Append("Period"),
model.ADDRESS, msg.Append("Address"),
model.AUTHOR, msg.Append("RegistrationAuthority"),
), m.OptionSimple(model.AUTH_UID)...)
}
}
func (s cert) List(m *ice.Message, arg ...string) {
if len(arg) == 1 {
s.Select(m, model.AUTH_UID, arg[0]).Table(func(value ice.Maps) {
switch CertStatus(kit.Int(value[model.CERT_STATUS])) {
case CertUpload:
m.PushButton(s.Verify, s.Remove)
case CertVerify:
m.PushButton(s.Check, s.Remove)
default:
m.PushButton()
}
}).Action().Display("").DisplayCSS("")
s.Button(m, "", s.Upload)
}
}
func (s cert) Verify(m *ice.Message, arg ...string) {
msg := s.Select(m.Spawn(), m.OptionSimple(model.AUTH_UID)...)
if msg.Append(model.VERIFY) == "" {
verify := kit.Format("%06d", rand.Intn(1000000))
s.Update(m, kit.Dict(model.MOBILE, m.Option(model.MOBILE), model.VERIFY, verify), m.OptionSimple(model.AUTH_UID)...)
m.Cmd(SmsVendor, SmsVendor.Send, m.Option(model.MOBILE), verify)
} else {
if m.Option(model.VERIFY) == "" {
return
}
if !m.WarnNotValid(m.Option(model.VERIFY) != msg.Append(model.VERIFY)) {
s.Check(m)
}
}
}
func (s cert) Check(m *ice.Message, arg ...string) {
if m.Option(model.PERSON) != "" {
msg := s.Select(m.Spawn(), model.USER_UID, m.Option(model.USER_UID), model.NAME, m.Option(model.PERSON))
m.Options(msg.AppendSimple(model.NUMBER, model.NAME))
}
if !m.Cmdy(RealnameVendor, RealnameVendor.Check, m.Option(model.MOBILE), m.Option(model.NUMBER), kit.Select(m.Option(model.NAME), m.Option(model.PERSON))).IsErr() {
s.Update(m, kit.Dict(model.STATUS, CertCheck), m.OptionSimple(model.AUTH_UID)...)
}
}
func init() { ice.TeamCtxCmd(cert{}) }
type CertStatus int
const (
CertUpload CertStatus = iota
CertVerify
CertCheck
)
var CertStatusList = map[CertStatus]string{
CertUpload: "upload",
CertVerify: "verify",
CertCheck: "check",
}
func (s CertStatus) String() string { return CertStatusList[s] }
var OcrVendor interface {
IDCard(m *ice.Message, arg ...string)
BizLicense(m *ice.Message, arg ...string)
}
var SmsVendor interface {
Send(m *ice.Message, arg ...string)
}
var RealnameVendor interface {
Check(m *ice.Message, arg ...string)
}