mirror of
https://shylinux.com/x/icebergs
synced 2025-04-29 02:29:22 +08:00
fix action share
This commit is contained in:
parent
f40802f5c3
commit
5f3f1044d2
@ -92,7 +92,7 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块",
|
|||||||
m.Save(RUNTIME, SYSTEM)
|
m.Save(RUNTIME, SYSTEM)
|
||||||
}},
|
}},
|
||||||
|
|
||||||
RUNTIME: {Name: "runtime", Help: "运行环境", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
RUNTIME: {Name: "runtime name auto", Help: "运行环境", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
switch kit.Select("", arg, 0) {
|
switch kit.Select("", arg, 0) {
|
||||||
case "hostinfo":
|
case "hostinfo":
|
||||||
case "hostname":
|
case "hostname":
|
||||||
|
@ -65,11 +65,20 @@ func _hash_import(m *ice.Message, prefix, key, file string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
count := 0
|
count := 0
|
||||||
|
if m.Conf(prefix, kit.Keys(key, kit.MDB_META, kit.MDB_SHORT)) == "" {
|
||||||
|
for k, data := range list {
|
||||||
|
// 导入数据
|
||||||
|
m.Conf(prefix, kit.Keys(key, kit.MDB_HASH, k), data)
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
} else {
|
||||||
for _, data := range list {
|
for _, data := range list {
|
||||||
// 导入数据
|
// 导入数据
|
||||||
m.Rich(prefix, key, data)
|
m.Rich(prefix, key, data)
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m.Log_IMPORT(kit.MDB_KEY, kit.Keys(prefix, key), kit.MDB_COUNT, count)
|
m.Log_IMPORT(kit.MDB_KEY, kit.Keys(prefix, key), kit.MDB_COUNT, count)
|
||||||
m.Echo(kit.Keys(file, JSON))
|
m.Echo(kit.Keys(file, JSON))
|
||||||
}
|
}
|
||||||
|
@ -70,13 +70,15 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon
|
|||||||
msg.Option(v.Name, v.Value)
|
msg.Option(v.Name, v.Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 请求
|
||||||
msg.Option(ice.MSG_OUTPUT, "")
|
msg.Option(ice.MSG_OUTPUT, "")
|
||||||
if u, e := url.Parse(r.Header.Get("Referer")); e == nil {
|
if u, e := url.Parse(r.Header.Get("Referer")); e == nil {
|
||||||
for k, v := range u.Query() {
|
for k, v := range u.Query() {
|
||||||
msg.Logs("refer", k, v)
|
if msg.Logs("refer", k, v); k != "name" {
|
||||||
msg.Option(k, v)
|
msg.Option(k, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 用户请求
|
// 用户请求
|
||||||
msg.Option(ice.MSG_USERWEB, kit.Select(msg.Conf(SHARE, "meta.domain"), r.Header.Get("Referer")))
|
msg.Option(ice.MSG_USERWEB, kit.Select(msg.Conf(SHARE, "meta.domain"), r.Header.Get("Referer")))
|
||||||
|
@ -91,7 +91,12 @@ func _share_create(m *ice.Message, kind, name, text string, arg ...string) strin
|
|||||||
h := m.Rich(SHARE, nil, kit.Dict(
|
h := m.Rich(SHARE, nil, kit.Dict(
|
||||||
kit.MDB_TIME, m.Time(m.Conf(SHARE, "meta.expire")),
|
kit.MDB_TIME, m.Time(m.Conf(SHARE, "meta.expire")),
|
||||||
kit.MDB_TYPE, kind, kit.MDB_NAME, name, kit.MDB_TEXT, text,
|
kit.MDB_TYPE, kind, kit.MDB_NAME, name, kit.MDB_TEXT, text,
|
||||||
kit.MDB_EXTRA, kit.Dict(aaa.USERROLE, m.Option(ice.MSG_USERROLE), aaa.USERNAME, m.Option(ice.MSG_USERNAME), arg),
|
kit.MDB_EXTRA, kit.Dict(
|
||||||
|
aaa.USERROLE, m.Option(ice.MSG_USERROLE),
|
||||||
|
aaa.USERNAME, m.Option(ice.MSG_USERNAME),
|
||||||
|
"river", m.Option(ice.MSG_RIVER),
|
||||||
|
"storm", m.Option(ice.MSG_STORM),
|
||||||
|
arg),
|
||||||
))
|
))
|
||||||
|
|
||||||
// 创建列表
|
// 创建列表
|
||||||
@ -150,6 +155,8 @@ func _share_action(m *ice.Message, value map[string]interface{}, arg ...string)
|
|||||||
func _share_action_redirect(m *ice.Message, value map[string]interface{}, share string) bool {
|
func _share_action_redirect(m *ice.Message, value map[string]interface{}, share string) bool {
|
||||||
tool := kit.Value(value, "extra.tool.0").(map[string]interface{})
|
tool := kit.Value(value, "extra.tool.0").(map[string]interface{})
|
||||||
m.Render("redirect", "/share", "share", share, "title", kit.Format(value["name"]),
|
m.Render("redirect", "/share", "share", share, "title", kit.Format(value["name"]),
|
||||||
|
"river", kit.Format(kit.Value(value, "extra.river")),
|
||||||
|
"storm", kit.Format(kit.Value(value, "extra.storm")),
|
||||||
"pod", kit.Format(tool["pod"]), kit.UnMarshal(kit.Format(tool["val"])),
|
"pod", kit.Format(tool["pod"]), kit.UnMarshal(kit.Format(tool["val"])),
|
||||||
)
|
)
|
||||||
return true
|
return true
|
||||||
|
@ -119,11 +119,15 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
|
|||||||
}
|
}
|
||||||
case "/action":
|
case "/action":
|
||||||
if len(arg) > 0 {
|
if len(arg) > 0 {
|
||||||
|
if arg[0] != "" {
|
||||||
m.Option(ice.MSG_RIVER, arg[0])
|
m.Option(ice.MSG_RIVER, arg[0])
|
||||||
|
}
|
||||||
arg = arg[1:]
|
arg = arg[1:]
|
||||||
}
|
}
|
||||||
if len(arg) > 0 {
|
if len(arg) > 0 {
|
||||||
|
if arg[0] != "" {
|
||||||
m.Option(ice.MSG_STORM, arg[0])
|
m.Option(ice.MSG_STORM, arg[0])
|
||||||
|
}
|
||||||
arg = arg[1:]
|
arg = arg[1:]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,6 +146,21 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
|
|||||||
|
|
||||||
})
|
})
|
||||||
}) == nil {
|
}) == nil {
|
||||||
|
if m.Option("share") != "" {
|
||||||
|
m.Richs(web.SHARE, "", m.Option("share"), func(key string, value map[string]interface{}) {
|
||||||
|
if m.Option(ice.MSG_RIVER) == kit.Value(value, "extra.river") && m.Richs(RIVER, kit.Keys(kit.MDB_HASH, m.Option(ice.MSG_RIVER), USER), kit.Value(value, "extra.username"), nil) != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// m.Option(ice.MSG_USERNAME, kit.Value(value, "extra.username"))
|
||||||
|
// m.Option(ice.MSG_USERROLE, kit.Value(value, "extra.userrole"))
|
||||||
|
// m.Log_AUTH(web.SHARE, key, "username", m.Option(ice.MSG_USERNAME))
|
||||||
|
m.Render(web.STATUS, 403, "not join")
|
||||||
|
m.Option(ice.MSG_USERURL, "")
|
||||||
|
return
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
m.Render(web.STATUS, 403, "not join")
|
m.Render(web.STATUS, 403, "not join")
|
||||||
m.Option(ice.MSG_USERURL, "")
|
m.Option(ice.MSG_USERURL, "")
|
||||||
return
|
return
|
||||||
@ -155,6 +174,7 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
|
|||||||
if m.Right(m.Option(ice.MSG_USERURL), m.Optionv(ice.MSG_CMDS)) {
|
if m.Right(m.Option(ice.MSG_USERURL), m.Optionv(ice.MSG_CMDS)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 登录检查
|
// 登录检查
|
||||||
if m.Warn(!m.Options(ice.MSG_USERNAME), "not login") {
|
if m.Warn(!m.Options(ice.MSG_USERNAME), "not login") {
|
||||||
if m.Option("share") == "" {
|
if m.Option("share") == "" {
|
||||||
@ -171,23 +191,13 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
|
|||||||
m.Option(ice.MSG_USERURL, "")
|
m.Option(ice.MSG_USERURL, "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
}},
|
}},
|
||||||
|
|
||||||
"tool": {Name: "tool", Help: "应用", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
"tool": {Name: "tool", Help: "应用", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
}},
|
}},
|
||||||
"node": {Name: "node", Help: "设备", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
"node": {Name: "node", Help: "设备", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
}},
|
}},
|
||||||
"user": {Name: "user", Help: "用户", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
|
||||||
m.Richs(RIVER, nil, m.Option(ice.MSG_RIVER), func(key string, value map[string]interface{}) {
|
|
||||||
m.Richs(RIVER, kit.Keys(kit.MDB_HASH, m.Option(ice.MSG_RIVER), USER), kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
|
||||||
value = value[kit.MDB_META].(map[string]interface{})
|
|
||||||
m.Push(key, value, []string{kit.MDB_TIME})
|
|
||||||
m.Push(aaa.USERZONE, aaa.UserZone(m, value[aaa.USERNAME]))
|
|
||||||
m.Push(aaa.USERNICK, aaa.UserNick(m, value[aaa.USERNAME]))
|
|
||||||
m.Push(key, value, []string{aaa.USERNAME})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}},
|
|
||||||
|
|
||||||
"/ocean": {Name: "/ocean", Help: "大海洋", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
"/ocean": {Name: "/ocean", Help: "大海洋", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if len(arg) == 0 {
|
if len(arg) == 0 {
|
||||||
|
@ -89,6 +89,10 @@ func init() {
|
|||||||
if m.Option(ice.MSG_USERUA) == "" {
|
if m.Option(ice.MSG_USERUA) == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if value["照片"] == "" {
|
||||||
|
m.Push("照片", "")
|
||||||
|
continue
|
||||||
|
}
|
||||||
m.Push("照片", m.Cmdx(mdb.RENDER, web.RENDER.IMG, path.Join("/share/local", value["照片"])))
|
m.Push("照片", m.Cmdx(mdb.RENDER, web.RENDER.IMG, path.Join("/share/local", value["照片"])))
|
||||||
} else {
|
} else {
|
||||||
m.Push(k, value[k])
|
m.Push(k, value[k])
|
||||||
|
@ -97,6 +97,8 @@ func init() {
|
|||||||
"base", kit.Dict(
|
"base", kit.Dict(
|
||||||
"admin", []interface{}{
|
"admin", []interface{}{
|
||||||
"web.chat.user",
|
"web.chat.user",
|
||||||
|
"web.chat.tool",
|
||||||
|
"web.chat.info",
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -116,7 +118,106 @@ func init() {
|
|||||||
)},
|
)},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
"/" + RIVER: {Name: "/river", Help: "小河流",
|
"info": {Name: "info auto 导出:button", Help: "信息", Action: map[string]*ice.Action{
|
||||||
|
mdb.MODIFY: {Name: "modify", Help: "编辑", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
arg[0] = kit.Keys(kit.MDB_META, arg[0])
|
||||||
|
m.Richs(RIVER, nil, m.Option(ice.MSG_RIVER), func(key string, value map[string]interface{}) {
|
||||||
|
m.Log_MODIFY(RIVER, m.Option(ice.MSG_RIVER), arg[0], arg[1], "old", kit.Format(kit.Value(value, arg[0])))
|
||||||
|
kit.Value(value, arg[0], arg[1])
|
||||||
|
})
|
||||||
|
}},
|
||||||
|
mdb.EXPORT: {Name: "export file", Help: "导出", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
m.Cmdy(mdb.EXPORT, m.Prefix(RIVER), "", mdb.HASH)
|
||||||
|
}},
|
||||||
|
mdb.IMPORT: {Name: "import file", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
m.Cmdy(mdb.IMPORT, m.Prefix(RIVER), "", mdb.HASH)
|
||||||
|
}},
|
||||||
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
m.Richs(RIVER, nil, m.Option(ice.MSG_RIVER), func(key string, value map[string]interface{}) {
|
||||||
|
m.Push("detail", value[kit.MDB_META])
|
||||||
|
})
|
||||||
|
}},
|
||||||
|
|
||||||
|
"user": {Name: "user auto", Help: "用户", Action: map[string]*ice.Action{
|
||||||
|
mdb.DELETE: {Name: "delete", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
if m.Option(aaa.USERNAME) == cli.UserName {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if m.Option(aaa.USERNAME) == m.Option(ice.MSG_USERNAME) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
m.Richs(RIVER, nil, m.Option(ice.MSG_RIVER), func(key string, value map[string]interface{}) {
|
||||||
|
m.Richs(RIVER, kit.Keys(kit.MDB_HASH, m.Option(ice.MSG_RIVER), USER), m.Option(aaa.USERNAME), func(key string, value map[string]interface{}) {
|
||||||
|
m.Conf(RIVER, kit.Keys(kit.MDB_HASH, m.Option(ice.MSG_RIVER), USER, kit.MDB_HASH, key), "")
|
||||||
|
m.Log_DELETE(RIVER, m.Option(ice.MSG_RIVER), USER, m.Option(aaa.USERNAME))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}},
|
||||||
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
m.Richs(RIVER, nil, m.Option(ice.MSG_RIVER), func(key string, value map[string]interface{}) {
|
||||||
|
m.Richs(RIVER, kit.Keys(kit.MDB_HASH, m.Option(ice.MSG_RIVER), USER), kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||||
|
value = value[kit.MDB_META].(map[string]interface{})
|
||||||
|
m.Push(key, value, []string{kit.MDB_TIME})
|
||||||
|
m.Push(aaa.USERZONE, aaa.UserZone(m, value[aaa.USERNAME]))
|
||||||
|
m.Push(aaa.USERNICK, aaa.UserNick(m, value[aaa.USERNAME]))
|
||||||
|
m.Push(key, value, []string{aaa.USERNAME})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
m.PushAction("删除")
|
||||||
|
}},
|
||||||
|
"tool": {Name: "tool storm=auto id=auto auto", Help: "工具", Action: map[string]*ice.Action{
|
||||||
|
mdb.MODIFY: {Name: "modify", Help: "编辑", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
m.Richs(RIVER, nil, m.Option(ice.MSG_RIVER), func(key string, value map[string]interface{}) {
|
||||||
|
m.Richs(RIVER, kit.Keys(kit.MDB_HASH, m.Option(ice.MSG_RIVER), TOOL), m.Option("storm"), func(key string, value map[string]interface{}) {
|
||||||
|
switch arg[0] {
|
||||||
|
case kit.MDB_TIME, kit.MDB_ID:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if m.Option(kit.MDB_ID) == "" {
|
||||||
|
m.Log_MODIFY(RIVER, m.Option(ice.MSG_RIVER), arg[0], arg[1], "old", kit.Value(value, kit.Keys(kit.MDB_META, arg[0])))
|
||||||
|
kit.Value(value, kit.Keys(kit.MDB_META, arg[0]), arg[1])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
m.Grows(RIVER, kit.Keys(kit.MDB_HASH, m.Option(ice.MSG_RIVER), TOOL, kit.MDB_HASH, key), kit.MDB_ID, m.Option(kit.MDB_ID), func(index int, value map[string]interface{}) {
|
||||||
|
m.Log_MODIFY(RIVER, m.Option(ice.MSG_RIVER), arg[0], arg[1], "old", kit.Value(value, kit.Keys(kit.MDB_META, arg[0])))
|
||||||
|
kit.Value(value, kit.Keys(kit.MDB_META, arg[0]), arg[1])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}},
|
||||||
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
if len(arg) == 0 {
|
||||||
|
m.Richs(RIVER, nil, m.Option(ice.MSG_RIVER), func(key string, value map[string]interface{}) {
|
||||||
|
m.Richs(RIVER, kit.Keys(kit.MDB_HASH, m.Option(ice.MSG_RIVER), TOOL), kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||||
|
value = value[kit.MDB_META].(map[string]interface{})
|
||||||
|
m.Push("time", value[kit.MDB_TIME])
|
||||||
|
m.Push("storm", key)
|
||||||
|
m.Push("name", value[kit.MDB_NAME])
|
||||||
|
m.Push("count", value[kit.MDB_COUNT])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Richs(RIVER, nil, m.Option(ice.MSG_RIVER), func(key string, value map[string]interface{}) {
|
||||||
|
if len(arg) == 1 {
|
||||||
|
m.Grows(RIVER, kit.Keys(kit.MDB_HASH, m.Option(ice.MSG_RIVER), TOOL, kit.MDB_HASH, arg[0]), "", "", func(index int, value map[string]interface{}) {
|
||||||
|
value = value[kit.MDB_META].(map[string]interface{})
|
||||||
|
m.Push("time", value[kit.MDB_TIME])
|
||||||
|
m.Push("id", value[kit.MDB_ID])
|
||||||
|
m.Push("ctx", value["ctx"])
|
||||||
|
m.Push("cmd", value["cmd"])
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
m.Grows(RIVER, kit.Keys(kit.MDB_HASH, m.Option(ice.MSG_RIVER), TOOL, kit.MDB_HASH, arg[0]), kit.MDB_ID, arg[1], func(index int, value map[string]interface{}) {
|
||||||
|
value = value[kit.MDB_META].(map[string]interface{})
|
||||||
|
m.Push("detail", value)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}},
|
||||||
|
|
||||||
|
"/river": {Name: "/river", Help: "小河流",
|
||||||
Action: map[string]*ice.Action{
|
Action: map[string]*ice.Action{
|
||||||
mdb.CREATE: {Name: "create type name text arg...", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
mdb.CREATE: {Name: "create type name text arg...", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||||
_river_create(m, arg[0], arg[1], arg[2], arg[3:]...)
|
_river_create(m, arg[0], arg[1], arg[2], arg[3:]...)
|
||||||
|
@ -9,7 +9,6 @@ import (
|
|||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -248,22 +247,9 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
|
|||||||
}},
|
}},
|
||||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save(ASSET) }},
|
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save(ASSET) }},
|
||||||
|
|
||||||
ASSET: {Name: "asset account=auto id=auto auto 支出:button 转账:button 收入:button 导出:button 导入:button", Help: "资产", Meta: kit.Dict(
|
ASSET: {Name: "asset account=auto id=auto auto 添加:button 导出:button 导入:button", Help: "资产", Meta: kit.Dict(
|
||||||
"支出", _input_spend, "转账", _input_trans, "收入", _input_bonus,
|
"添加", _input_spend,
|
||||||
), Action: map[string]*ice.Action{
|
), Action: map[string]*ice.Action{
|
||||||
"spend": {Name: "insert [key value]...", Help: "支出", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
_asset_create(m, arg[1])
|
|
||||||
_asset_insert(m, arg[1], arg[2:]...)
|
|
||||||
}},
|
|
||||||
"trans": {Name: "insert [key value]...", Help: "转账", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
_asset_create(m, arg[1])
|
|
||||||
_asset_insert(m, arg[1], arg[2:]...)
|
|
||||||
}},
|
|
||||||
"bonus": {Name: "insert [key value]...", Help: "收入", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
_asset_create(m, arg[1])
|
|
||||||
_asset_insert(m, arg[1], arg[2:]...)
|
|
||||||
}},
|
|
||||||
|
|
||||||
mdb.INSERT: {Name: "insert [key value]...", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
mdb.INSERT: {Name: "insert [key value]...", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||||
_asset_create(m, arg[1])
|
_asset_create(m, arg[1])
|
||||||
_asset_insert(m, arg[1], arg[2:]...)
|
_asset_insert(m, arg[1], arg[2:]...)
|
||||||
@ -284,191 +270,15 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
|
|||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if _asset_list(m, kit.Select("", arg, 0), kit.Select("", arg, 1)); len(arg) < 2 {
|
if _asset_list(m, kit.Select("", arg, 0), kit.Select("", arg, 1)); len(arg) < 2 {
|
||||||
m.Table(func(index int, value map[string]string, head []string) {
|
m.Table(func(index int, value map[string]string, head []string) {
|
||||||
})
|
|
||||||
} else {
|
|
||||||
m.Table(func(index int, value map[string]string, head []string) {
|
|
||||||
if value["key"] == "status" {
|
|
||||||
m.Push("key", "action")
|
|
||||||
m.Push("value", _asset_action(m, value["value"]))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return
|
|
||||||
if m.Option("_action") == "保存" {
|
|
||||||
arg = []string{"action", "save"}
|
|
||||||
}
|
|
||||||
if len(arg) > 0 && arg[0] == "action" {
|
|
||||||
switch arg[1] {
|
|
||||||
case "modify":
|
|
||||||
// 修改数据
|
|
||||||
m.Richs(cmd, nil, m.Option("account"), func(key string, account map[string]interface{}) {
|
|
||||||
m.Grows(cmd, kit.Keys("hash", key), "id", arg[5], func(index int, current map[string]interface{}) {
|
|
||||||
m.Log(ice.LOG_MODIFY, "%s: %d %s: %s->%s", key, index, kit.Value(current, arg[2]), arg[2], arg[3])
|
|
||||||
kit.Value(current, arg[2], arg[3])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
case "save":
|
|
||||||
// 保存数据
|
|
||||||
m.Option("cache.limit", -2)
|
|
||||||
if f, p, e := kit.Create(kit.Select("usr/local/asset.csv", arg, 2)); m.Assert(e) {
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
w := csv.NewWriter(f)
|
|
||||||
defer w.Flush()
|
|
||||||
|
|
||||||
w.Write([]string{"时间", "收支类型", "账目分类", "备注", "金额", "账户"})
|
|
||||||
m.Richs(cmd, nil, kit.Select("*", arg, 3), func(key string, account map[string]interface{}) {
|
|
||||||
if kit.Format(kit.Value(account, "meta.account")) == "流水" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
m.Grows(cmd, kit.Keys("hash", key), kit.Select("", arg, 4), kit.Select("", arg, 5), func(index int, current map[string]interface{}) {
|
|
||||||
w.Write([]string{
|
|
||||||
kit.Format(current["time"]),
|
|
||||||
kit.Format(current["type"]),
|
|
||||||
kit.Format(current["name"]),
|
|
||||||
kit.Format(current["text"]),
|
|
||||||
kit.Format(current["value"]),
|
|
||||||
kit.Format(kit.Value(account, "meta.account")),
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
m.Log(ice.LOG_EXPORT, "%s", p)
|
|
||||||
m.Cmdy(web.STORY, "catch", "csv", p)
|
|
||||||
}
|
|
||||||
|
|
||||||
case "load":
|
|
||||||
// 加载数据
|
|
||||||
m.CSV(m.Cmdx("nfs.cat", arg[2])).Table(func(index int, data map[string]string, head []string) {
|
|
||||||
v, _ := strconv.ParseFloat(data["金额"], 64)
|
|
||||||
for _, account := range []string{kit.Select(data["账户"], arg, 3), "流水"} {
|
|
||||||
// amount := kit.Int(v * 100)
|
|
||||||
item := kit.Dict(
|
|
||||||
"type", data["收支类型"], "name", data["账目分类"], "text", data["备注"], "value", kit.Int(v),
|
|
||||||
"time", data["时间"], "extra", kit.UnMarshal(data["extra"]),
|
|
||||||
)
|
|
||||||
|
|
||||||
if m.Richs(cmd, nil, account, nil) == nil {
|
|
||||||
// 添加账户
|
|
||||||
m.Log(ice.LOG_CREATE, "account: %s", account)
|
|
||||||
m.Rich(cmd, nil, kit.Data("account", account, "amount", "0", "bonus", "0", "spend", "0"))
|
|
||||||
}
|
|
||||||
|
|
||||||
m.Richs(cmd, nil, account, func(key string, value map[string]interface{}) {
|
|
||||||
// 账户流水
|
|
||||||
m.Grow(cmd, kit.Keys("hash", key), item)
|
|
||||||
|
|
||||||
// 账户结余
|
|
||||||
amount := kit.Int(kit.Value(value, "meta.amount")) + kit.Int(v)
|
|
||||||
m.Log(ice.LOG_INSERT, "%s: %v", key, amount)
|
|
||||||
kit.Value(value, "meta.amount", amount)
|
|
||||||
|
|
||||||
switch data["收支类型"] {
|
|
||||||
case "收入":
|
|
||||||
bonus := kit.Int(kit.Value(value, "meta.bonus")) + kit.Int(v)
|
|
||||||
kit.Value(value, "meta.bonus", bonus)
|
|
||||||
case "支出":
|
|
||||||
spend := kit.Int(kit.Value(value, "meta.spend")) + kit.Int(v)
|
|
||||||
kit.Value(value, "meta.spend", spend)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(arg) == 0 {
|
|
||||||
// 账户列表
|
|
||||||
m.Richs(cmd, nil, "*", func(key string, value map[string]interface{}) {
|
|
||||||
m.Push(key, value["meta"], []string{"account", "count", "amount", "bonus", "spend"})
|
|
||||||
})
|
})
|
||||||
m.Sort("amount", "int_r")
|
m.Sort("amount", "int_r")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
m.Table(func(index int, value map[string]string, head []string) {
|
||||||
if len(arg) > 5 && m.Richs(cmd, nil, arg[0], nil) == nil {
|
if value["key"] == "status" {
|
||||||
// 添加账户
|
m.Push("key", "action")
|
||||||
m.Rich(cmd, nil, kit.Data("account", arg[0], "amount", "0", "bonus", "0", "spend", "0"))
|
m.Push("value", _asset_action(m, value["value"]))
|
||||||
m.Log(ice.LOG_CREATE, "account: %s", arg[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
field := []string{"time", "id", "value", "type", "name", "text"}
|
|
||||||
m.Richs(cmd, nil, arg[0], func(key string, value map[string]interface{}) {
|
|
||||||
if len(arg) == 1 {
|
|
||||||
// 消费流水
|
|
||||||
m.Grows(cmd, kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) {
|
|
||||||
m.Push("", value, field)
|
|
||||||
})
|
|
||||||
m.Sort("id", "int_r")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if len(arg) == 2 {
|
|
||||||
// 消费详情
|
|
||||||
m.Grows(cmd, kit.Keys("hash", key), "id", arg[1], func(index int, value map[string]interface{}) {
|
|
||||||
m.Push("detail", value)
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if len(arg) < 6 {
|
|
||||||
// 消费查询
|
|
||||||
name, value := "type", arg[2]
|
|
||||||
switch len(arg) {
|
|
||||||
case 3:
|
|
||||||
// 消费分类
|
|
||||||
name, value = "type", arg[2]
|
|
||||||
case 4:
|
|
||||||
// 消费对象
|
|
||||||
name, value = "name", arg[3]
|
|
||||||
case 5:
|
|
||||||
// 消费备注
|
|
||||||
name, value = "text", arg[4]
|
|
||||||
}
|
|
||||||
m.Grows(cmd, kit.Keys("hash", key), name, value, func(index int, value map[string]interface{}) {
|
|
||||||
m.Push("", value, field)
|
|
||||||
})
|
|
||||||
m.Sort("id", "int_r")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 词汇统计
|
|
||||||
web.Count(m, cmd, "meta.word.type", arg[2])
|
|
||||||
web.Count(m, cmd, "meta.word.name", arg[3])
|
|
||||||
web.Count(m, cmd, "meta.word.text", arg[4])
|
|
||||||
web.Count(m, cmd, "meta.word.value", strings.TrimPrefix(arg[5], "-"))
|
|
||||||
|
|
||||||
// 数据结构
|
|
||||||
amount := kit.Int(arg[5])
|
|
||||||
extra := kit.Dict()
|
|
||||||
data := kit.Dict(
|
|
||||||
kit.MDB_TYPE, arg[2], kit.MDB_NAME, arg[3], kit.MDB_TEXT, arg[4],
|
|
||||||
"value", amount, "extra", extra,
|
|
||||||
)
|
|
||||||
for i := 6; i < len(arg)-1; i += 2 {
|
|
||||||
switch arg[i] {
|
|
||||||
case kit.MDB_TIME:
|
|
||||||
kit.Value(data, arg[i], arg[i+1])
|
|
||||||
default:
|
|
||||||
kit.Value(extra, arg[i], arg[i+1])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 添加流水
|
|
||||||
n := m.Grow(cmd, kit.Keys(kit.MDB_HASH, key), data)
|
|
||||||
|
|
||||||
// 账户结余
|
|
||||||
total := kit.Int(kit.Value(value, "meta.amount")) + amount
|
|
||||||
m.Log(ice.LOG_INSERT, "account: %s total: %v", arg[0], total)
|
|
||||||
kit.Value(value, "meta.amount", total)
|
|
||||||
m.Echo("%s: %d %d\n", arg[0], n, total)
|
|
||||||
|
|
||||||
// 收支统计
|
|
||||||
switch data["type"] {
|
|
||||||
case "收入":
|
|
||||||
bonus := kit.Int(kit.Value(value, "meta.bonus")) + amount
|
|
||||||
kit.Value(value, "meta.bonus", bonus)
|
|
||||||
case "支出":
|
|
||||||
spend := kit.Int(kit.Value(value, "meta.spend")) + amount
|
|
||||||
kit.Value(value, "meta.spend", spend)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}},
|
}},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user