diff --git a/src/gonganxitong/apply.go b/src/gonganxitong/apply.go index 2022b99..f8e685a 100644 --- a/src/gonganxitong/apply.go +++ b/src/gonganxitong/apply.go @@ -11,21 +11,18 @@ type apply struct { Table user user userPlace userPlace - place place street street + city city + place place event event portal string `data:"true"` - create string `name:"create place_uid*:select user_place_role*:select begin_time:select@date end_time:select@date" role:"void"` + create string `name:"create place_uid* 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"` - list string `name:"list place_uid uid auto" role:"void"` } func (s apply) Inputs(m *ice.Message, arg ...string) { switch arg[0] { - case model.PLACE_UID: - m.Cmdy(s.userPlace, m.Option(model.USER_UID)) - m.Cut(model.PLACE_UID, model.PLACE_NAME).DisplayInputKeyNameIconTitle() case model.USER_PLACE_ROLE: for k, v := range UserPlaceRoleList { if k != UserPlaceCreator && k != UserPlaceVisitor { @@ -47,33 +44,49 @@ func (s apply) Cancel(m *ice.Message, arg ...string) { s.SendTemplate(m, msg.Append(model.USER_UID), "场所权限申请 已取消") } func (s apply) Submit(m *ice.Message, arg ...string) { + msg := s.status(m, ApplyCreate, ApplySubmit) + if m.WarnNotValid(msg.IsErr()) { + return + } defer s.event.Record(m, m.Option(model.UID)) defer m.ToastProcess()() role := UserPlaceCreator - switch UserPlaceRole(kit.Int(s.status(m, ApplyCreate, ApplySubmit).Append(model.ROLE))) { + switch UserPlaceRole(kit.Int(msg.Append(model.ROLE))) { case UserPlaceLandlord: role = UserPlaceCreator case UserPlaceTenant, UserPlaceAdmin: role = UserPlaceLandlord } - msg := m.Cmd(s.userPlace, s.userPlace.Select, m.OptionSimple(model.PLACE_UID), model.ROLE, role.String()) + msg = m.Cmd(s.userPlace, s.userPlace.Select, m.OptionSimple(model.PLACE_UID), model.ROLE, role.String()) + if m.WarnNotFound(msg.Length() == 0, role.String()) { + return + } m.Cmd(order{}, order{}.Create, msg.AppendSimple(model.USER_UID), model.APPLY_UID, m.Option(model.UID), model.STATUS, OrderCreate) - s.SendTemplate(m, m.Option(model.USER_UID), "场所权限申请 已提交 🕑") + s.SendTemplate(m, m.Option(model.USER_UID), "场所权限申请 已提交") +} +func (s apply) Reject(m *ice.Message, arg ...string) { + msg := s.status(m, ApplySubmit, ApplyRejected) + s.SendTemplate(m, msg.Append(model.USER_UID), "场所权限申请 已驳回 ❌") +} +func (s apply) Approve(m *ice.Message, arg ...string) { + msg := s.status(m, ApplySubmit, ApplyApproved) + s.SendTemplate(m, msg.Append(model.USER_UID), "场所权限申请 已通过 ✅") + m.Cmd(s.userPlace, s.userPlace.Create, msg.AppendSimple(model.USER_UID, model.PLACE_UID, model.ROLE)) } func (s apply) List(m *ice.Message, arg ...string) { - s.Tables(m, s.place, s.street).Fields(m, "applies.created_at", - model.PLACE_NAME, model.PLACE_TYPE, "applies.role AS user_place_role", model.APPLY_STATUS, - model.STREET_NAME, model.PLACE_ADDRESS, "applies.uid", model.PLACE_UID, model.STREET_UID, + s.Tables(m, s.user, s.place, s.street, s.city).Fields(m, s.Key(s, model.CREATED_AT), s.Key(s, model.ID), + model.USER_NAME, model.USER_AVATAR, + model.PLACE_NAME, model.PLACE_TYPE, s.AS(s.Key(s, model.ROLE), model.USER_PLACE_ROLE), model.APPLY_STATUS, + model.CITY_NAME, model.STREET_NAME, model.PLACE_ADDRESS, model.BEGIN_TIME, model.END_TIME, - ).Orders(m, "created_at DESC") + s.Key(s, model.UID), model.PLACE_UID, + ).Orders(m, s.Desc(model.CREATED_AT)) if len(arg) == 0 { if m.IsTech() { s.Table.Select(m) - } else { - s.Table.Select(m, m.OptionSimple(model.USER_UID)...) } } else if len(arg) == 1 { - if s.Table.Select(m, model.USER_UID, m.Option(model.USER_UID), model.PLACE_UID, arg[0]).Action(s.Create); m.Length() == 0 { + if s.Table.Select(m, model.USER_UID, m.Option(model.USER_UID), model.PLACE_UID, arg[0]); m.Length() == 0 { m.EchoInfoButton(m.Trans("please create apply", "请创建权限申请"), s.Create) return } @@ -85,7 +98,7 @@ func (s apply) List(m *ice.Message, arg ...string) { ApplyCancel.String(), }, ice.STR_R) } else { - s.Table.Select(m.FieldsSetDetail(), "applies.uid", arg[1]) + s.Table.Select(m.FieldsSetDetail(), s.Key(s, model.UID), arg[1]) if ApplyStatus(kit.Int(m.Append(model.APPLY_STATUS))) == ApplySubmit { m.EchoQRCode(cmdurl(m, arg[0], m.Prefix("order"), arg[1])) } @@ -101,17 +114,8 @@ func (s apply) List(m *ice.Message, arg ...string) { s.RewriteAppend(m).Display("").DisplayCSS("") } -func init() { ice.Cmd(prefixKey(), apply{}) } +func init() { ice.TeamCtxCmd(apply{}) } -func (s apply) Reject(m *ice.Message, arg ...string) { - msg := s.status(m, ApplySubmit, ApplyRejected) - s.SendTemplate(m, msg.Append(model.USER_UID), "场所权限申请 已驳回 ❌") -} -func (s apply) Approve(m *ice.Message, arg ...string) { - msg := s.status(m, ApplySubmit, ApplyApproved) - s.SendTemplate(m, msg.Append(model.USER_UID), "场所权限申请 已通过 ✅") - m.Cmd(s.userPlace, s.userPlace.Create, msg.AppendSimple(model.USER_UID, model.PLACE_UID, model.ROLE)) -} func (s apply) status(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)) { diff --git a/src/gonganxitong/apply.js b/src/gonganxitong/apply.js index 07be3ee..3f640a1 100644 --- a/src/gonganxitong/apply.js +++ b/src/gonganxitong/apply.js @@ -1,17 +1,16 @@ Volcanos(chat.ONIMPORT, { _init: function(can, msg) { if (msg.IsDetail()) { return msg.Dump(can) } - can.page.Append(can, can._output, msg.Table(function(value) { - value._style = [value.place_type, value.user_place_role, value.apply_status] + can.page.Append(can, can._output, msg.Table(function(value) { value._style = [value.place_type, value.user_place_role, value.apply_status] return can.onimport.itemcard(can, value, [ {view: html.TITLE, list: [{text: value.place_name}, {text: [can.user.transValue(can, value, "place_type"), "", mdb.TYPE]}, {text: [can.user.transValue(can, value, "user_place_role"), "", aaa.ROLE]}, {text: [can.user.transValue(can, value, "apply_status"), "", mdb.STATUS]}, ]}, - {view: html.STATUS, list: [{text: value.street_name}, {text: value.place_address}]}, {view: html.STATUS, list: [{text: value.uid.slice(0, 6)}, {text: can.base.TimeTrim(value.created_at)}]}, {view: html.STATUS, list: [{text: value.begin_time.split(" ")[0]}, {text: value.end_time.split(" ")[0]}]}, - ], function() { can.Option("uid", value.uid), can.Update() }) + {view: html.STATUS, list: [{text: value.city_name}, {text: value.street_name}, {text: value.place_address}]}, + ]) })) }, }) \ No newline at end of file diff --git a/src/gonganxitong/city.go b/src/gonganxitong/city.go new file mode 100644 index 0000000..684f566 --- /dev/null +++ b/src/gonganxitong/city.go @@ -0,0 +1,24 @@ +package gonganxitong + +import ( + "shylinux.com/x/ice" + + "shylinux.com/x/community/src/gonganxitong/model" +) + +type city struct{ Table } + +func init() { ice.TeamCtxCmd(city{}) } + +func (s city) FindOrCreateByName(m *ice.Message, arg ...string) { + if msg := m.Cmd(s, s.Select, model.NAME, arg[1]); msg.Length() == 0 { + msg := m.Cmd(s, s.Create, model.NAME, arg[1]) + arg[0], arg[1] = model.CITY_UID, msg.Result() + } else { + arg[0], arg[1] = model.CITY_UID, msg.Append(model.UID) + } +} + +type City struct{ city } + +func init() { ice.TeamCtxCmd(City{}) } diff --git a/src/gonganxitong/common.go b/src/gonganxitong/common.go index 7615d76..86fda2f 100644 --- a/src/gonganxitong/common.go +++ b/src/gonganxitong/common.go @@ -11,15 +11,16 @@ import ( type Table struct { db.Table - list string `name:"list place_uid uid auto"` + inputs string `name:"inputs" role:"void"` + list string `name:"list place_uid uid auto" role:"void"` } -func (s Table) Inputs(m *ice.Message, arg ...string) { - s.Table.Inputs(m, arg...) -} func (s Table) Init(m *ice.Message, arg ...string) { kit.If(m.Config(web.PORTAL) == ice.TRUE, func() { portal{}.Show(m) }) } +func (s Table) Inputs(m *ice.Message, arg ...string) { + s.Table.Inputs(m, arg...) +} func (s Table) List(m *ice.Message, arg ...string) *ice.Message { if len(arg) == 0 || len(arg) == 1 { if m.IsTech() { @@ -47,8 +48,6 @@ func (s Table) SendTemplate(m *ice.Message, user_uid, title string) { } } func cmdurl(m *ice.Message, arg ...string) string { - return m.MergePodCmd("", m.Prefix(web.PORTAL), ice.MSG_DEBUG, m.Option(ice.MSG_DEBUG)) + + return m.MergePodCmd("", m.Prefix(web.PORTAL)) + "?debug=true" + "#" + kit.Join([]string{arg[0], kit.Select(m.PrefixKey(), arg, 1), kit.Select("", arg, 2)}, ":") } - -func prefixKey() string { return kit.Keys("web.team", kit.PathName(-1), kit.FileName(-1)) } diff --git a/src/gonganxitong/email.go b/src/gonganxitong/email.go index d92b84d..1c62f97 100644 --- a/src/gonganxitong/email.go +++ b/src/gonganxitong/email.go @@ -14,37 +14,40 @@ import ( type email struct { user user portal portal - Creds emails.Creds - apply string `name:"apply username* password*"` - reset string `name:"reset password*" help:"重置密码"` + creds emails.Creds + apply string `name:"apply username* password*" role:"void"` + reset string `name:"reset password*" help:"重置密码" role:"void"` } func (s email) Init(m *ice.Message, arg ...string) { s.portal.Show(m) } -func (s email) List(m *ice.Message, arg ...string) { - if msg := m.Cmd(s.user, s.user.Select, model.UID, m.Option(model.USER_UID)); len(msg.Append(model.EMAIL)) < 10 { - m.EchoInfoButton(m.Trans("please apply email", "请申请邮箱"), s.Apply) - } else { - m.EchoInfoButton(msg.Append(model.EMAIL), s.Reset) - } -} func (s email) Apply(m *ice.Message, arg ...string) { + defer m.ToastProcess()() msg := m.Cmd(s.user, s.user.Select, model.UID, m.Option(model.USER_UID)) if m.Warn(msg.Append(model.EMAIL) != "", m.Trans("email already exists", "邮箱已存在")) { return } if !strings.Contains(m.Option(aaa.USERNAME), "@") { - m.Option(aaa.USERNAME, m.Option(aaa.USERNAME)+"@"+m.UserWeb().Hostname()) + m.Option(aaa.USERNAME, m.Option(aaa.USERNAME)+"@"+strings.Split(m.UserHost(), "://")[1]) } - m.Cmdy(s.Creds, s.Creds.Create, m.Option(aaa.USERNAME), m.Option(aaa.PASSWORD)) + m.Cmdy(s.creds, s.creds.Create, m.Option(aaa.USERNAME), m.Option(aaa.PASSWORD)) kit.If(!m.IsErr(), func() { m.Cmdy(s.user, s.user.Email, m.Option(aaa.USERNAME)) }) - kit.If(!m.IsErr(), func() { m.ToastSuccess() }) } func (s email) Reset(m *ice.Message, arg ...string) { + defer m.ToastProcess()() msg := m.Cmd(s.user, s.user.Select, model.UID, m.Option(model.USER_UID)) - m.Cmdy(s.Creds, s.Creds.Password, msg.Append(model.EMAIL), m.Option(aaa.PASSWORD)) - kit.If(!m.IsErr(), func() { m.ToastSuccess() }) + if m.WarnNotFound(msg.Append(model.EMAIL) == "", model.EMAIL) { + return + } + m.Cmdy(s.creds, s.creds.Password, msg.Append(model.EMAIL), m.Option(aaa.PASSWORD)) +} +func (s email) List(m *ice.Message, arg ...string) { + if msg := m.Cmd(s.user, s.user.Select, model.UID, m.Option(model.USER_UID)); msg.Append(model.EMAIL) == "" { + m.EchoInfoButton(m.Trans("please apply email", "请申请邮箱"), s.Apply) + } else { + m.EchoInfoButton(msg.Append(model.EMAIL), s.Reset) + } } -func init() { ice.Cmd(prefixKey(), email{}) } +func init() { ice.TeamCtxCmd(email{}) } diff --git a/src/gonganxitong/event.go b/src/gonganxitong/event.go index d6f7544..e957fa6 100644 --- a/src/gonganxitong/event.go +++ b/src/gonganxitong/event.go @@ -16,13 +16,24 @@ type event struct { func (s event) List(m *ice.Message, arg ...string) { s.Tables(m, s.user).Fields(m, - "events.created_at", "events.uid", - "index", "operate", "args", - "users.avatar AS icons", "user_name", "user_uid", - ).Orders(m, "created_at DESC").Select(m).Display("") + s.Key(s, model.CREATED_AT), s.Key(s, model.ID), + model.USER_AVATAR, model.USER_NAME, + ctx.INDEX, model.OPERATE, ctx.ARGS, model.INFO, + s.Key(s, model.UID), model.USER_UID, + ).Orders(m, s.Desc(model.CREATED_AT)) + if len(arg) == 0 { + if m.IsTech() { + s.Select(m) + } + } else if len(arg) == 1 { + s.Select(m, model.PLACE_UID, arg[0]) + } else { + s.Select(m.FieldsSetDetail(), s.Key(s, model.UID), arg[1]) + } + m.Display("") } -func init() { ice.Cmd(prefixKey(), event{}) } +func init() { ice.TeamCtxCmd(event{}) } -func (s event) Record(m *ice.Message, arg ...string) { - m.Cmd(s, s.Create, m.OptionSimple(model.USER_UID, model.PLACE_UID), ctx.INDEX, m.PrefixKey(), "operate", m.ActionKey(), ctx.ARGS, kit.Join(arg, ",")) +func (s event) Record(m *ice.Message, info string, arg ...string) { + m.Cmd(s, s.Create, m.OptionSimple(model.USER_UID, model.PLACE_UID), model.INFO, info, ctx.INDEX, m.PrefixKey(), model.OPERATE, m.ActionKey(), ctx.ARGS, kit.Join(arg, ",")) } diff --git a/src/gonganxitong/event.js b/src/gonganxitong/event.js index a437fb3..634abc3 100644 --- a/src/gonganxitong/event.js +++ b/src/gonganxitong/event.js @@ -6,7 +6,8 @@ Volcanos(chat.ONIMPORT, { {view: html.STATUS, list: [{text: value.uid.slice(0, 6)}, {text: can.base.TimeTrim(value.created_at)}]}, {view: html.STATUS, list: [{text: value.index}, {text: value.operate}]}, {view: html.STATUS, list: [{text: value.args}]}, - ], function() { can.Option("uid", value.uid), can.Update() }) + {view: html.OUTPUT, list: [{text: value.info}]}, + ]) })) }, }) \ No newline at end of file diff --git a/src/gonganxitong/express/common.go b/src/gonganxitong/express/common.go new file mode 100644 index 0000000..7adbc1d --- /dev/null +++ b/src/gonganxitong/express/common.go @@ -0,0 +1,8 @@ +package express + +import ( + "shylinux.com/x/community/src/gonganxitong" + _ "shylinux.com/x/community/src/gonganxitong/express/model" +) + +type Table struct{ gonganxitong.Table } diff --git a/src/gonganxitong/express/common.json b/src/gonganxitong/express/common.json new file mode 100644 index 0000000..b9d4329 --- /dev/null +++ b/src/gonganxitong/express/common.json @@ -0,0 +1,7 @@ +{ + "express": "寄快递", + "icons": { + "express": "https://img.icons8.com/officel/80/shipped.png" + }, + "value": {} +} \ No newline at end of file diff --git a/src/gonganxitong/express/express.go b/src/gonganxitong/express/express.go new file mode 100644 index 0000000..b7f18e7 --- /dev/null +++ b/src/gonganxitong/express/express.go @@ -0,0 +1,18 @@ +package express + +import ( + "shylinux.com/x/ice" + + "shylinux.com/x/community/src/gonganxitong" +) + +type express struct { + Table + portal gonganxitong.Portal +} + +func (s express) Init(m *ice.Message, arg ...string) { + s.portal.Show(m) +} + +func init() { ice.TeamCtxCmd(express{}) } diff --git a/src/gonganxitong/express/model/model.go b/src/gonganxitong/express/model/model.go new file mode 100644 index 0000000..dcbfc3d --- /dev/null +++ b/src/gonganxitong/express/model/model.go @@ -0,0 +1,12 @@ +package model + +import "shylinux.com/x/mysql-story/src/db" + +type Express struct { + db.ModelWithUID + FromPlaceUID string `gorm:"type:char(32);index"` + ToPlaceUID string `gorm:"type:char(32);index"` + Status uint8 +} + +func init() { db.CmdModels("", &Express{}) } diff --git a/src/gonganxitong/icons/apply.png b/src/gonganxitong/icons/apply.png new file mode 100644 index 0000000..3500f1b Binary files /dev/null and b/src/gonganxitong/icons/apply.png differ diff --git a/src/gonganxitong/icons/event.png b/src/gonganxitong/icons/event.png new file mode 100644 index 0000000..c286ab7 Binary files /dev/null and b/src/gonganxitong/icons/event.png differ diff --git a/src/gonganxitong/icons/house.png b/src/gonganxitong/icons/house.png new file mode 100644 index 0000000..82c8493 Binary files /dev/null and b/src/gonganxitong/icons/house.png differ diff --git a/src/gonganxitong/icons/office.png b/src/gonganxitong/icons/office.png new file mode 100644 index 0000000..4fcb7d3 Binary files /dev/null and b/src/gonganxitong/icons/office.png differ diff --git a/src/gonganxitong/icons/order.png b/src/gonganxitong/icons/order.png new file mode 100644 index 0000000..00a4f28 Binary files /dev/null and b/src/gonganxitong/icons/order.png differ diff --git a/src/gonganxitong/model/model.go b/src/gonganxitong/model/model.go index a75de45..f2d9017 100644 --- a/src/gonganxitong/model/model.go +++ b/src/gonganxitong/model/model.go @@ -1,15 +1,12 @@ package model -import ( - "time" - - "shylinux.com/x/ice" - "shylinux.com/x/mysql-story/src/db" -) +import "shylinux.com/x/mysql-story/src/db" const ( + ID = "id" UID = "uid" NAME = "name" + INFO = "info" TYPE = "type" ROLE = "role" STATUS = "status" @@ -19,17 +16,22 @@ const ( OPEN_ID = "open_id" USER_UID = "user_uid" USER_NAME = "user_name" + USER_AVATAR = "user_avatar" USER_PLACE_ROLE = "user_place_role" PLACE_UID = "place_uid" PLACE_NAME = "place_name" PLACE_TYPE = "place_type" PLACE_ADDRESS = "place_address" - STREET_UID = "street_uid" STREET_NAME = "street_name" + STREET_UID = "street_uid" + CITY_NAME = "city_name" + CITY_UID = "city_uid" APPLY_UID = "apply_uid" APPLY_STATUS = "apply_status" ORDER_STATUS = "order_status" ORDER_UID = "order_uid" + CREATED_AT = "created_at" + OPERATE = "operate" BEGIN_TIME = "begin_time" END_TIME = "end_time" ) @@ -48,32 +50,38 @@ type User struct { Avatar string `gorm:"size:256"` } type UserPlace struct { - db.Model + db.ModelWithUID UserUID string `gorm:"type:char(32);index"` PlaceUID string `gorm:"type:char(32)"` Role uint8 - BeginTime time.Time - EndTime time.Time + BeginTime db.Time + EndTime db.Time } type Place struct { db.ModelWithUID StreetUID string `gorm:"type:char(32)"` Name string `gorm:"type:char(32)"` - Type uint8 Address string `gorm:"size:256"` + Type uint8 } type Street struct { db.ModelWithUID - Name string `gorm:"type:char(32)"` + CityUID string `gorm:"type:char(32)"` + Name string `gorm:"type:char(32);index"` +} +type City struct { + db.ModelWithUID + Name string `gorm:"type:char(32);index"` } type Event struct { db.ModelWithUID PlaceUID string `gorm:"type:char(32);index"` - UserUID string `gorm:"type:char(32)"` + UserUID string `gorm:"type:char(32)";index` Index string `gorm:"type:char(32)"` Operate string `gorm:"type:char(32)"` Args string `gorm:"type:char(32)"` + Info string `gorm:"size:1024"` } type Apply struct { db.ModelWithUID @@ -81,8 +89,8 @@ type Apply struct { PlaceUID string `gorm:"type:char(32)"` Status uint8 Role uint8 - BeginTime time.Time - EndTime time.Time + BeginTime db.Time + EndTime db.Time } type Order struct { db.ModelWithUID @@ -91,10 +99,6 @@ type Order struct { Status uint8 } -type models struct{ db.Models } - -func (s models) Init(m *ice.Message, arg ...string) { - s.Models.Register(m, "gonganxitong", &Sess{}, &User{}, &UserPlace{}, &Place{}, &Street{}, Event{}, Apply{}, Order{}) +func init() { + db.CmdModels("", &Sess{}, &User{}, &UserPlace{}, &Place{}, &Street{}, &City{}, Event{}, Apply{}, Order{}) } - -func init() { ice.Cmd("web.team.community.gonganxitong.models", models{}) } diff --git a/src/gonganxitong/model/model.sql b/src/gonganxitong/model/model.sql deleted file mode 100644 index 4681996..0000000 --- a/src/gonganxitong/model/model.sql +++ /dev/null @@ -1 +0,0 @@ -CREATE DATABASE IF NOT EXISTS gonganxitong CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; \ No newline at end of file diff --git a/src/gonganxitong/order.go b/src/gonganxitong/order.go index 492d59a..0af0d3d 100644 --- a/src/gonganxitong/order.go +++ b/src/gonganxitong/order.go @@ -9,53 +9,57 @@ import ( type order struct { Table - user user - apply apply - place place - street street - event event - portal string `data:"true"` - create string `name:"create user_uid* apply_uid* status*"` - reject string `name:"reject" role:"void"` - approve string `name:"approve" role:"void"` - list string `name:"list place_uid uid auto" role:"void"` + user user + apply apply + userPlace userPlace + place place + street street + city city + event event + portal string `data:"true"` + create string `name:"create user_uid* apply_uid* status*"` + reject string `name:"reject" role:"void"` + approve string `name:"approve" role:"void"` } func (s order) Create(m *ice.Message, arg ...string) { s.Table.Create(m, arg...) - s.SendTemplate(m, m.Option(model.USER_UID), "场所权限申请 请审批 🕑") + s.SendTemplate(m, m.Option(model.USER_UID), "场所权限审批 请处理") } func (s order) Reject(m *ice.Message, arg ...string) { defer m.ToastProcess()() - defer s.event.Record(m, m.Option(model.UID)) + defer s.event.Record(m, kit.Format("审批驳回%s成为%s", m.Option(model.USER_NAME), m.Option(model.USER_PLACE_ROLE)), m.Option(model.UID)) m.Cmd(s.apply, s.apply.Reject, m.Option(model.UID)) s.Table.Update(m, kit.Dict(model.STATUS, OrderRejected), model.UID, m.Option(model.ORDER_UID)) - s.SendTemplate(m, m.Option(model.USER_UID), "场所权限申请 已驳回 ❌") + s.SendTemplate(m, m.Option(model.USER_UID), "场所权限审批 已驳回 ❌") } func (s order) Approve(m *ice.Message, arg ...string) { defer m.ToastProcess()() - defer s.event.Record(m, m.Option(model.UID)) + defer s.event.Record(m, kit.Format("审批通过%s成为%s", m.Option(model.USER_NAME), m.Option(model.USER_PLACE_ROLE)), m.Option(model.UID)) m.Cmd(s.apply, s.apply.Approve, m.Option(model.UID)) s.Table.Update(m, kit.Dict(model.STATUS, OrderApproved), model.UID, m.Option(model.ORDER_UID)) - s.SendTemplate(m, m.Option(model.USER_UID), "场所权限申请 已通过 ✅") + s.SendTemplate(m, m.Option(model.USER_UID), "场所权限审批 已通过 ✅") } func (s order) List(m *ice.Message, arg ...string) { - s.Tables(m, s.apply, s.place, s.street).Fields(m, "orders.created_at", - model.PLACE_NAME, model.PLACE_TYPE, "applies.role AS user_place_role", model.ORDER_STATUS, - model.STREET_NAME, model.PLACE_ADDRESS, model.PLACE_UID, "orders.uid AS order_uid", - "applies.uid", model.BEGIN_TIME, model.END_TIME, - ).Orders(m, "created_at DESC") + s.Tables(m, s.apply, "left join users on applies.user_uid = users.uid", s.place, s.street, s.city).Fields(m, + s.Key(s, model.CREATED_AT), s.Key(s, model.ID), + model.USER_AVATAR, model.USER_NAME, + model.PLACE_NAME, model.PLACE_TYPE, s.AS(s.Key(s.apply, model.ROLE), model.USER_PLACE_ROLE), model.ORDER_STATUS, + model.CITY_NAME, model.STREET_NAME, model.PLACE_ADDRESS, + model.BEGIN_TIME, model.END_TIME, + s.Key(s.apply, model.UID), s.AS(s.Key(s, model.UID), model.ORDER_UID), model.PLACE_UID, + ).Orders(m, s.Desc(model.CREATED_AT)) if len(arg) == 0 { if m.IsTech() { s.Table.Select(m) } else { - s.Table.Select(m, "orders.user_uid", m.Option(model.USER_UID)) + s.Table.Select(m, s.Key(s, model.USER_UID), m.Option(model.USER_UID)) } } else if len(arg) == 1 { - s.Table.Select(m, "orders.user_uid", m.Option(model.USER_UID), model.PLACE_UID, arg[0]).Action(s.Create) - defer m.Sort("order_status,created_at", []string{OrderCreate.String(), OrderApproved.String(), OrderRejected.String()}, ice.STR_R) + s.Table.Select(m, s.Key(s, model.USER_UID), m.Option(model.USER_UID), model.PLACE_UID, arg[0]) + defer m.Sort(kit.Fields(model.ORDER_STATUS, model.CREATED_AT), []string{OrderCreate.String(), OrderApproved.String(), OrderRejected.String()}, ice.STR_R) } else { - s.Table.Select(m.FieldsSetDetail(), "orders.user_uid", m.Option(model.USER_UID), "applies.uid", arg[1]) + s.Table.Select(m.FieldsSetDetail(), s.Key(s, model.USER_UID), m.Option(model.USER_UID), s.Key(s.apply, model.UID), arg[1]) } m.Table(func(value ice.Maps) { switch OrderStatus(kit.Int(value[model.ORDER_STATUS])) { @@ -65,10 +69,11 @@ func (s order) List(m *ice.Message, arg ...string) { m.PushButton() } }) + m.Info("what %v", m.FormatsMeta(nil)) s.RewriteAppend(m).Display("").DisplayCSS("") } -func init() { ice.Cmd(prefixKey(), order{}) } +func init() { ice.TeamCtxCmd(order{}) } type OrderStatus int diff --git a/src/gonganxitong/order.js b/src/gonganxitong/order.js index 6ea5328..78b2a5c 100644 --- a/src/gonganxitong/order.js +++ b/src/gonganxitong/order.js @@ -1,17 +1,20 @@ Volcanos(chat.ONIMPORT, { - _init: function(can, msg) { if (msg.IsDetail()) { return msg.Dump(can) } - can.page.Append(can, can._output, msg.Table(function(value) { - value._style = [value.place_type, value.user_place_role, value.order_status] + _init: function(can, msg) { + if (msg.IsDetail()) { msg.Option("_share_icons", msg.Append("user_avatar")) + msg.Option("_share_content", can.user.transValue(can, msg, "user_place_role")+" "+msg.Append("user_name")) + return msg.Dump(can) + } + can.page.Append(can, can._output, msg.Table(function(value) { value._style = [value.place_type, value.user_place_role, value.order_status] return can.onimport.itemcard(can, value, [ - {view: html.TITLE, list: [{text: value.place_name}, + {view: html.TITLE, list: [{text: value.user_name}, {text: [can.user.transValue(can, value, "place_type"), "", mdb.TYPE]}, {text: [can.user.transValue(can, value, "user_place_role"), "", aaa.ROLE]}, {text: [can.user.transValue(can, value, "order_status"), "", mdb.STATUS]}, ]}, - {view: html.STATUS, list: [{text: value.street_name}, {text: value.place_address}]}, {view: html.STATUS, list: [{text: value.uid.slice(0, 6)}, {text: can.base.TimeTrim(value.created_at)}]}, {view: html.STATUS, list: [{text: value.begin_time.split(" ")[0]}, {text: value.end_time.split(" ")[0]}]}, - ], function() { can.Option("uid", value.uid), can.Update() }) + {view: html.STATUS, list: [{text: value.city_name}, {text: value.street_name}, {text: value.place_address}]}, + ]) })) }, }) \ No newline at end of file diff --git a/src/gonganxitong/place.go b/src/gonganxitong/place.go index 211928e..90d4b3f 100644 --- a/src/gonganxitong/place.go +++ b/src/gonganxitong/place.go @@ -2,14 +2,30 @@ package gonganxitong import ( "shylinux.com/x/ice" + "shylinux.com/x/icebergs/base/ctx" "shylinux.com/x/community/src/gonganxitong/model" ) -type place struct{ Table } +type place struct { + Table + user user + city city + street street +} func (s place) Inputs(m *ice.Message, arg ...string) { switch arg[0] { + case model.CITY_NAME: + if m.Option(ctx.ACTION) == "placeCreate" { + break + } + m.Cmdy(s.city, s.city.Select).CutTo(model.NAME, arg[0]) + case model.STREET_NAME: + if m.Option(ctx.ACTION) == "placeCreate" { + break + } + m.Cmdy(s.street, s.street.Select).CutTo(model.NAME, arg[0]) case model.PLACE_TYPE: for k, v := range PlaceTypeList { m.Push(arg[0], k).Push(model.NAME, v) @@ -19,8 +35,28 @@ func (s place) Inputs(m *ice.Message, arg ...string) { s.Table.Inputs(m, arg...) } } +func (s place) User(m *ice.Message, arg ...string) { + userPlace := userPlace{} + s.Tables(m, "left join user_places on places.uid = user_places.place_uid", s.user).Fields(m, + s.Key(userPlace, model.CREATED_AT), s.Key(userPlace, model.UID), + model.USER_AVATAR, model.USER_NAME, model.USER_PLACE_ROLE, model.BEGIN_TIME, model.END_TIME, + ).Orders(m, s.Desc(model.CREATED_AT)) + if len(arg) == 0 { + if m.IsTech() { + s.Select(m) + } + } else if len(arg) == 1 { + s.Select(m, model.PLACE_UID, arg[0]) + } else { + s.Select(m.FieldsSetDetail(), s.Key(userPlace, model.UID), arg[1]) + } + s.RewriteAppend(m) +} +func init() { ice.TeamCtxCmd(place{}) } -func init() { ice.Cmd(prefixKey(), place{}) } +type Place struct{ place } + +func init() { ice.TeamCtxCmd(Place{}) } type PlaceType int diff --git a/src/gonganxitong/placeUser.go b/src/gonganxitong/placeUser.go new file mode 100644 index 0000000..65e48c8 --- /dev/null +++ b/src/gonganxitong/placeUser.go @@ -0,0 +1,22 @@ +package gonganxitong + +import ( + "shylinux.com/x/ice" + + "shylinux.com/x/community/src/gonganxitong/model" +) + +type placeUser struct { + place place + portal portal + list string `name:"list place_uid uid auto" role:"void"` +} + +func (s placeUser) Init(m *ice.Message, arg ...string) { + s.portal.Show(m, model.ROLE, "creator,landlord") +} +func (s placeUser) List(m *ice.Message, arg ...string) { + m.Cmdy(s.place, s.place.User, arg).PushAction().Action().Display("") +} + +func init() { ice.TeamCtxCmd(placeUser{}) } diff --git a/src/gonganxitong/placeUser.js b/src/gonganxitong/placeUser.js new file mode 100644 index 0000000..b1d0c0b --- /dev/null +++ b/src/gonganxitong/placeUser.js @@ -0,0 +1,13 @@ +Volcanos(chat.ONIMPORT, { + _init: function(can, msg) { if (msg.IsDetail()) { return msg.Dump(can) } + can.page.Append(can, can._output, msg.Table(function(value) { value._style = [value.user_place_role] + return can.onimport.itemcard(can, value, [ + {view: html.TITLE, list: [{text: value.user_name}, + {text: [can.user.transValue(can, value, "user_place_role"), "", aaa.ROLE]}, + ]}, + {view: html.STATUS, list: [{text: value.uid.slice(0, 6)}, {text: can.base.TimeTrim(value.created_at)}]}, + {view: html.STATUS, list: [{text: value.begin_time.split(" ")[0]}, {text: value.end_time.split(" ")[0]}]}, + ]) + })) + }, +}) \ No newline at end of file diff --git a/src/gonganxitong/portal.css b/src/gonganxitong/portal.css index b7bf16f..9b735b7 100644 --- a/src/gonganxitong/portal.css +++ b/src/gonganxitong/portal.css @@ -14,4 +14,11 @@ $output>div.list>div.action div.item i { display:none; } $output>div.action div.item.button { margin-right:5px; } $output>div.action div.item.button input { border:none; color:var(--notice-bg-color); min-width:80px; float:left; } $output>div.action div.item.button span { display:none; } -$output>fieldset.qrcode table.content td { text-align:center; } \ No newline at end of file +$output>fieldset table.content td { box-shadow:none; } +$output>fieldset table.content tr.uid { display:none; } +$output>fieldset table.content tr.order_uid { display:none; } +$output>fieldset table.content tr.place_uid { display:none; } +$output>fieldset table.content td img { max-width:100%; } +$output>fieldset.qrcode table.content td { text-align:center; } +$output>fieldset.qrcode div.code { text-align:center; } +$output>fieldset.story { box-shadow:none; } \ No newline at end of file diff --git a/src/gonganxitong/portal.go b/src/gonganxitong/portal.go index c465883..8e0be44 100644 --- a/src/gonganxitong/portal.go +++ b/src/gonganxitong/portal.go @@ -16,12 +16,14 @@ type portal struct { userPlace userPlace place place street street + city city export string `data:"true"` short string `data:"index"` field string `data:"time,name,icons,index,order,enable,type,role"` + inputs string `name:"inputs" role:"void"` list string `name:"list place_uid index uid auto" role:"void"` - placeCreate string `name:"placeCreate street_uid*:select place_type*:select name* address*" role:"void"` - placeRemove string `name:"placeRemove place_uid*" role:"void"` + placeCreate string `name:"placeCreate city_name* street_name* place_type*:select name* address*" role:"void"` + placeRemove string `name:"placeRemove user_uid* place_uid* user_place_role*" role:"void"` scanQRCode string `name:"scanQRCode type text" role:"void"` } @@ -41,6 +43,8 @@ func (s portal) List(m *ice.Message, arg ...string) { } else if len(arg) == 1 { s.Hash.List(m, arg[1:]...).SortInt(mdb.ORDER) } else if len(arg) == 2 { + msg := m.Cmd(s.place, s.place.Select, model.UID, arg[0]) + m.Option(model.PLACE_NAME, msg.Append(model.NAME)) m.Cmdy(ctx.COMMAND, arg[1]).Push(ctx.ARGS, arg[0]) } else { m.FieldsSetDetail().Cmdy(arg[1], mdb.SELECT, model.UID, arg[2]).PushAction().Action() @@ -49,11 +53,10 @@ func (s portal) List(m *ice.Message, arg ...string) { } func (s portal) PlaceCreate(m *ice.Message, arg ...string) { defer m.ToastProcess()() - if m.WarnNotFound(m.Cmd(s.street, s.street.Select, model.UID, m.Option(model.STREET_UID)).Length() == 0, "street") { - return - } + s.city.FindOrCreateByName(m, arg...) + s.street.FindOrCreateByName(m, arg...) arg = kit.TransArgKeys(arg, model.PLACE_TYPE, model.TYPE) - if m.Cmdy(s.place, s.place.Create, arg).IsErr() { + if m.Cmdy(s.place, s.place.Create, arg[2:]).IsErr() { return } args := kit.Simple(model.USER_UID, m.Option(model.USER_UID), model.PLACE_UID, m.Result(), model.ROLE, UserPlaceCreator) @@ -62,12 +65,12 @@ func (s portal) PlaceCreate(m *ice.Message, arg ...string) { } func (s portal) PlaceRemove(m *ice.Message, arg ...string) { defer m.ToastProcess()() - args := kit.Simple(model.USER_UID, m.Option(model.USER_UID), model.PLACE_UID, m.Option(model.PLACE_UID)) + args := kit.Simple(model.USER_UID, m.Option(model.USER_UID), model.PLACE_UID, m.Option(model.PLACE_UID), model.ROLE, m.Option(model.USER_PLACE_ROLE)) msg := m.Cmd(s.userPlace, s.userPlace.Select, args) if m.WarnNotFound(msg.Length() == 0, "place") { return } - m.Cmdy(s.userPlace, s.userPlace.Delete, args) + m.Cmdy(s.userPlace, s.userPlace.Delete, msg.AppendSimple(model.UID)) if kit.Int(msg.Append(model.ROLE)) == kit.Int(UserPlaceCreator) { m.Cmdy(s.place, s.place.Delete, model.UID, m.Option(model.PLACE_UID)) } @@ -88,7 +91,7 @@ func (s portal) ScanQRCode(m *ice.Message, arg ...string) { } } -func init() { ice.Cmd(prefixKey(), portal{}) } +func init() { ice.TeamCtxCmd(portal{}) } type Portal struct { portal @@ -97,12 +100,12 @@ type Portal struct { field string `data:"time,name,icons,index,order,enable,type,role"` } -func init() { ice.Cmd(prefixKey(), Portal{}) } +func init() { ice.TeamCtxCmd(Portal{}) } func (s portal) Show(m *ice.Message, arg ...string) { m.GoSleep("30ms", func() { cmd := m.GetCommand() icon := kit.Select(cmd.Icon, kit.Value(cmd.Meta, kit.Keys(ice.CTX_ICONS, m.CommandKey()))) - m.Cmd(s, s.Create, mdb.NAME, cmd.Help, mdb.ICONS, icon, ctx.INDEX, m.PrefixKey()) + m.Cmd(s, s.Create, mdb.NAME, cmd.Help, mdb.ICONS, icon, ctx.INDEX, m.PrefixKey(), arg) }) } diff --git a/src/gonganxitong/portal.js b/src/gonganxitong/portal.js index b29b456..5a52662 100644 --- a/src/gonganxitong/portal.js +++ b/src/gonganxitong/portal.js @@ -9,15 +9,17 @@ Volcanos(chat.ONIMPORT, { {text: [can.user.transValue(can, value, PLACE_TYPE), "", mdb.TYPE]}, value.user_place_role != "creator" && {text: [can.user.transValue(can, value, "user_place_role"), "", aaa.ROLE]}, ]}, - {view: html.STATUS, list: [{text: value[PLACE_UID].slice(0, 8)}, {text: value.street_name}, {text: can.base.TimeTrim(value.created_at)}]}, + {view: html.STATUS, list: [ + {text: value[PLACE_UID].slice(0, 6)}, {text: can.base.TimeTrim(value.created_at)}, + {text: value.city_name}, {text: value.street_name}, + ]}, ] }, myPortal: function(can, msg, PLACE_UID, PLACE_NAME, title) { can.user.isMobile && can.isCmdMode() && can.onappend.style(can, html.OUTPUT) - can.db.hash = can.misc.SearchHash(can), can.sup.current = can.sup.current||{} + can.isCmdMode() && (can.db.hash = can.misc.SearchHash(can)) + can.sup.current = can.sup.current||{} if (can.Option(PLACE_UID) == "") { - if (can.db.hash.length > 1 && can.db.hash[0]) { - return can.Option(PLACE_UID, can.db.hash[0]), can.Option(ctx.INDEX, can.db.hash[1]), can.Update() - } + if (can.db.hash.length > 1 && can.db.hash[0]) { return can.Option(PLACE_UID, can.db.hash[0]), can.Option(ctx.INDEX, can.db.hash[1]), can.Update() } can.db.hash[0] && can.onexport.session(can, PLACE_UID, can.db.hash[0]) can.ui = can.page.Append(can, can._output, ["myplace.list", "myindex.list"]) can.page.Append(can, can.ui.myplace, [{view: html.TITLE, list: [{text: can.user.trans(can, "My Place", title)}], _init: function(target) { @@ -25,14 +27,18 @@ Volcanos(chat.ONIMPORT, { msg.Option(ice.MSG_ACTION) && can.onappend._action(can, msg.Option(ice.MSG_ACTION), target) }}]) }}]) + msg.Table(function(value) { var key = "_trans.value."+PLACE_NAME.replace("_name", "_type")+".icons." + msg.Push(mdb.ICONS, can.Conf(key+value.place_type)||can.Conf(key+"office")) + }) var uid = can.onimport.myPlace(can, msg, can.ui.myplace, PLACE_UID, PLACE_NAME) msg.Length() > 0 && can.run({}, [uid], function(msg) { can.page.Append(can, can.ui.myindex, [{view: html.TITLE, list: [{text: can.user.trans(can, "My Index", "我的应用")}]}]) for (var i = 0; i < 1; i++) { can.onimport.myIndex(can, msg, can.ui.myindex, PLACE_UID) } can.onimport.selectIndex(can, can.sup.current) }) + can.user.agent.init(can) } else { - can.onimport.myData(can, msg, can._output, PLACE_UID) + can.onimport.myData(can, msg, can._output, PLACE_UID, PLACE_NAME) } }, myPlace: function(can, msg, target, PLACE_UID, PLACE_NAME) { var place_uid @@ -78,17 +84,20 @@ Volcanos(chat.ONIMPORT, { }} })) }, - myData: function(can, msg, target, PLACE_UID) { + myData: function(can, msg, target, PLACE_UID, PLACE_NAME) { msg.Table(function(value) { function back() {} function refresh() {} var list = [can.page.button(can, can.user.trans(can, "goback", "返回"), function(event) { back() }), can.page.button(can, can.user.trans(can, "reload", "刷新"), function(event) { refresh() })] var ui = can.page.Append(can, can._output, [{view: html.ACTION}]) if (can.db.hash.length > 2 && can.db.hash[0] && can.db.hash[2]) { value.args = [can.db.hash[0], can.db.hash[2]] } value.style = html.OUTPUT, value.height = can.ConfHeight()-html.ACTION_HEIGHT - can.onexport.title(can, can.ConfHelp(), can.sup.current.place_name, value.help) + // can.onexport.title(can, value.help, can.user.trans(can, msg.Option("place_type"), null, "value.place_type"), msg.Option("place_name")) + can.onexport.title(can, value.help, msg.Option(PLACE_NAME)) can.onappend.plugin(can, value, function(sub) { refresh = function() { sub.Update() } - sub.onexport.output = function(_sub, msg) { can.user.toastSuccess(can, "load", "", 1000), can.onappend.style(sub, html.OUTPUT) + sub.Conf(PLACE_NAME, msg.Option(PLACE_NAME)) + sub.onexport.output = function(_sub, msg) { can.onappend.style(sub, html.OUTPUT) can.page.Appends(can, ui.action, list), msg.Option(ice.MSG_ACTION) && can.onappend._action(sub, msg.Option(ice.MSG_ACTION), ui.action, null, true) can.onexport.hash(can, can.Option(PLACE_UID), value.index, sub.Option(UID)) + can.user.agent.init(can, msg.Option("_share_content")||value.help, msg.Option("_share_icons")||value.icons) back = function() { if (sub.Option(UID)) { can.onexport.hash(can, can.Option(PLACE_UID), can.Option(ctx.INDEX)), sub.Option(UID, ""), sub.Update() diff --git a/src/gonganxitong/portal.json b/src/gonganxitong/portal.json index e9d681e..799d162 100644 --- a/src/gonganxitong/portal.json +++ b/src/gonganxitong/portal.json @@ -1,43 +1,50 @@ { - "user": "用户", - "place": "场所", - "street": "街道", "portal": "用户场所", "scanQRCode": "扫码添加", "placeCreate": "添加场所", "placeRemove": "删除场所", - "email": "邮箱配置", "qrcode": "场所码", - "event": "事件流", "apply": "申请单", "order": "审批单", + "event": "事件流", + "email": "邮箱配置", + "placeUser": "场所用户", + "cancel": "取消", + "submit": "提交", "reject": "驳回", "approve": "通过", "icons": { - "email": "usr/icons/Mail.png", - "qrcode": "usr/icons/Chess.png", "scanQRCode": "bi bi-qr-code-scan", - "placeCreate": "bi bi-plus-square-dotted" + "placeCreate": "bi bi-plus-square-dotted", + "qrcode": "https://img.icons8.com/officel/80/qr-code.png", + "apply": "https://img.icons8.com/officel/80/edit-property.png", + "order": "https://img.icons8.com/officel/80/receipt-approved.png", + "event": "https://img.icons8.com/officel/80/property-with-timer.png", + "email": "https://img.icons8.com/officel/80/reading-confirmation.png", + "placeUser": "https://img.icons8.com/officel/80/person-at-home.png" }, "style": { "placeRemove": "danger" }, "input": { - "address": "地址", - "open_id": "外键", - "user_uid": "用户", - "user_name": "用户名", - "user_place_role": "用户角色", + "city_uid": "城市", + "city_name": "城市名称", + "street_uid": "街道", + "street_name": "街道名称", "place_uid": "场所", "place_name": "场所名称", "place_type": "场所类型", "place_address": "场所地址", - "street_uid": "街道", - "street_name": "街道名称", + "user_place_role": "用户角色", + "user_uid": "用户", + "user_name": "用户昵称", + "user_avatar": "用户头像", "apply_status": "申请状态", "order_status": "审批状态", + "order_uid": "审批", "begin_time": "起始时间", - "end_time": "结束时间" + "end_time": "结束时间", + "operate": "操作" }, "value": { "place_type": { @@ -48,7 +55,17 @@ "school": "学校", "office": "办公", "factory": "工厂", - "hospital": "医院" + "hospital": "医院", + "icons": { + "house": "https://img.icons8.com/officel/80/cottage.png", + "hotel": "https://img.icons8.com/officel/80/5-star-hotel.png", + "store": "https://img.icons8.com/officel/80/online-store.png", + "public": "https://img.icons8.com/officel/80/university.png", + "school": "https://img.icons8.com/officel/80/classroom.png", + "office": "https://img.icons8.com/officel/80/building.png", + "factory": "https://img.icons8.com/officel/80/manufacturing.png", + "hospital": "https://img.icons8.com/officel/80/clinic.png" + } }, "user_place_role": { "creator": "创建人", diff --git a/src/gonganxitong/portal.shy b/src/gonganxitong/portal.shy new file mode 100644 index 0000000..b51013e --- /dev/null +++ b/src/gonganxitong/portal.shy @@ -0,0 +1,11 @@ +chapter "用户场所" +refer ` +ICON https://igoutu.cn/icons/officel +GORM https://gorm.io/docs/indexes.html +` + +field web.code.mysql.client +field web.code.mysql.query args `mysql gonganxitong` +field web.code.db.database +field web.code.db.driver +field web.code.db.models \ No newline at end of file diff --git a/src/gonganxitong/qrcode.go b/src/gonganxitong/qrcode.go index 445a78a..f30cefc 100644 --- a/src/gonganxitong/qrcode.go +++ b/src/gonganxitong/qrcode.go @@ -2,14 +2,15 @@ package gonganxitong import ( "shylinux.com/x/ice" + kit "shylinux.com/x/toolkits" "shylinux.com/x/community/src/gonganxitong/model" ) type qrcode struct { portal portal - user user userPlace userPlace + list string `name:"list place_uid uid auto" role:"void"` } func (s qrcode) Init(m *ice.Message, arg ...string) { @@ -18,9 +19,12 @@ func (s qrcode) Init(m *ice.Message, arg ...string) { func (s qrcode) List(m *ice.Message, arg ...string) { msg := m.Cmd(s.userPlace, m.Option(model.USER_UID), arg[0]) m.FieldsSetDetail() - m.Push(model.PLACE_NAME, msg.Append(model.PLACE_NAME)) - m.Push(model.PLACE_UID, arg[0]) + kit.For([]string{ + model.CITY_NAME, model.STREET_NAME, model.PLACE_NAME, model.PLACE_ADDRESS, + }, func(key string) { + m.Push(key, msg.Append(key)) + }) m.EchoQRCode(cmdurl(m, arg[0], m.Prefix("apply"))) } -func init() { ice.Cmd(prefixKey(), qrcode{}) } +func init() { ice.TeamCtxCmd(qrcode{}) } diff --git a/src/gonganxitong/sess.go b/src/gonganxitong/sess.go index 6d26de6..df791bd 100644 --- a/src/gonganxitong/sess.go +++ b/src/gonganxitong/sess.go @@ -22,10 +22,11 @@ func (s sess) Create(m *ice.Message, arg ...string) { func (s sess) Check(m *ice.Message, arg ...string) { msg := s.Table.Select(m.Spawn(), model.UID, arg[0]) msg = m.Cmd(s.user, s.user.Select, model.UID, msg.Append(model.USER_UID)) + m.Option(ice.MSG_USERROLE, aaa.VOID) m.Option(ice.MSG_USERNAME, msg.Append(model.UID)) m.Option(ice.MSG_USERNICK, msg.Append(model.NAME)) m.Option(ice.MSG_AVATAR, msg.Append(model.AVATAR)) m.Option(model.USER_UID, msg.Append(model.UID)) } -func init() { ice.Cmd(prefixKey(), sess{}) } +func init() { ice.TeamCtxCmd(sess{}) } diff --git a/src/gonganxitong/street.go b/src/gonganxitong/street.go index bde04b2..e722ee3 100644 --- a/src/gonganxitong/street.go +++ b/src/gonganxitong/street.go @@ -1,7 +1,20 @@ package gonganxitong -import "shylinux.com/x/ice" +import ( + "shylinux.com/x/ice" + + "shylinux.com/x/community/src/gonganxitong/model" +) type street struct{ Table } -func init() { ice.Cmd(prefixKey(), street{}) } +func (s street) FindOrCreateByName(m *ice.Message, arg ...string) { + if msg := m.Cmd(s, s.Select, model.CITY_UID, arg[1], model.NAME, arg[3]); msg.Length() == 0 { + msg := m.Cmd(s, s.Create, model.CITY_UID, arg[1], model.NAME, arg[3]) + arg[2], arg[3] = model.STREET_UID, msg.Result() + } else { + arg[2], arg[3] = model.STREET_UID, msg.Append(model.UID) + } +} + +func init() { ice.TeamCtxCmd(street{}) } diff --git a/src/gonganxitong/user.go b/src/gonganxitong/user.go index 256c011..2808027 100644 --- a/src/gonganxitong/user.go +++ b/src/gonganxitong/user.go @@ -22,15 +22,13 @@ func (s user) Create(m *ice.Message, arg ...string) { s.Table.Create(m, kit.Simple(m.OptionSimple(model.OPEN_ID, model.AVATAR), model.NAME, m.Option(aaa.USERNICK))...) m.Option(model.USER_UID, m.Result()) } else { + s.Table.Update(m, kit.Dict(m.OptionSimple(model.AVATAR), model.NAME, m.Option(aaa.USERNICK)), m.AppendSimple(model.UID)...) m.Option(model.USER_UID, m.Append(model.UID)) } } func (s user) Email(m *ice.Message, arg ...string) { - s.Table.Update(m, m.OptionSimple(model.EMAIL), model.UID, m.Option(model.USER_UID)) + s.Table.Update(m, kit.Dict(m.OptionSimple(model.EMAIL)), model.UID, m.Option(model.USER_UID)) } - -func init() { ice.Cmd(prefixKey(), user{}) } - func (s user) SendTemplate(m *ice.Message, arg ...string) { // uid url type name hash msg := s.Select(m, model.UID, arg[0]) m.Cmdy("web.chat.wx.template", "", m.Config("template"), msg.Append(model.OPEN_ID), kit.Select("", arg, 1), @@ -39,6 +37,8 @@ func (s user) SendTemplate(m *ice.Message, arg ...string) { // uid url type name ) } +func init() { ice.TeamCtxCmd(user{}) } + type User struct{ user } -func init() { ice.Cmd(prefixKey(), User{}) } +func init() { ice.TeamCtxCmd(User{}) } diff --git a/src/gonganxitong/userPlace.go b/src/gonganxitong/userPlace.go index 0a8d420..3ecc6ec 100644 --- a/src/gonganxitong/userPlace.go +++ b/src/gonganxitong/userPlace.go @@ -10,27 +10,34 @@ type userPlace struct { Table place place street street - create string `name:"create user_uid* place_uid* role*"` + city city + create string `name:"create user_uid* place_uid* role* begin_time end_time"` list string `name:"list user_uid place_uid auto"` } func (s userPlace) List(m *ice.Message, arg ...string) { - s.Tables(m, s.place, s.street).Fields(m, "user_places.created_at", - model.USER_UID, model.PLACE_UID, + s.Tables(m, s.place, s.street, s.city).Fields(m, "user_places.created_at", "user_places.id", model.PLACE_NAME, model.PLACE_TYPE, model.USER_PLACE_ROLE, - model.STREET_NAME, model.PLACE_ADDRESS, - ).Orders(m, "user_places.id DESC") + model.CITY_NAME, model.STREET_NAME, model.PLACE_ADDRESS, + model.USER_UID, model.PLACE_UID, + ).Orders(m, "created_at DESC") if len(arg) == 0 { - s.Select(m) + if m.IsTech() { + s.Select(m) + } } else if len(arg) == 1 { s.Select(m, model.USER_UID, arg[0]) } else { - s.Select(m.FieldsSetDetail(), model.USER_UID, arg[0], model.PLACE_UID, arg[1]) + s.Select(m.FieldsSetDetail(), model.PLACE_UID, arg[1]) } s.RewriteAppend(m) } -func init() { ice.Cmd(prefixKey(), userPlace{}) } +func init() { ice.TeamCtxCmd(userPlace{}) } + +type UserPlace struct{ userPlace } + +func init() { ice.TeamCtxCmd(UserPlace{}) } type UserPlaceRole int diff --git a/src/main.go b/src/main.go index b4262b8..73d74e3 100644 --- a/src/main.go +++ b/src/main.go @@ -4,6 +4,7 @@ import ( "shylinux.com/x/ice" _ "shylinux.com/x/community/src/gonganxitong" + _ "shylinux.com/x/community/src/gonganxitong/express" ) func main() { print(ice.Run()) } diff --git a/src/template/web.code.autogen/demo.go b/src/template/web.code.autogen/demo.go index 4c052ab..676d21e 100644 --- a/src/template/web.code.autogen/demo.go +++ b/src/template/web.code.autogen/demo.go @@ -10,4 +10,4 @@ func (s {{.Option "name"}}) List(m *ice.Message, arg ...string) { s.Table.List(m, arg...) } -func init() { ice.Cmd(prefixKey(), {{.Option "name"}}{}) } +func init() { ice.TeamCtxCmd({{.Option "name"}}{}) }