1
0
forked from x/icebergs
This commit is contained in:
shylinux 2020-03-28 21:48:52 +08:00
parent b70843b780
commit 4b1cbf9e90
5 changed files with 108 additions and 93 deletions

View File

@ -22,8 +22,8 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
[]interface{}{"storm", "team", "team"}, []interface{}{"storm", "team", "team"},
[]interface{}{"field", "plan", "web.team"}, []interface{}{"field", "plan", "web.team"},
[]interface{}{"field", "stat", "web.team"},
[]interface{}{"field", "miss", "web.team"}, []interface{}{"field", "miss", "web.team"},
[]interface{}{"field", "stat", "web.team"},
[]interface{}{"field", "task", "web.team"}, []interface{}{"field", "task", "web.team"},
[]interface{}{"storm", "wiki", "wiki"}, []interface{}{"storm", "wiki", "wiki"},

View File

@ -2,7 +2,6 @@ package mall
import ( import (
"github.com/shylinux/icebergs" "github.com/shylinux/icebergs"
_ "github.com/shylinux/icebergs/base"
"github.com/shylinux/icebergs/base/web" "github.com/shylinux/icebergs/base/web"
"github.com/shylinux/toolkits" "github.com/shylinux/toolkits"
@ -10,7 +9,6 @@ import (
"fmt" "fmt"
"strconv" "strconv"
"strings" "strings"
"time"
) )
func input(m *ice.Message, arg ...string) bool { func input(m *ice.Message, arg ...string) bool {
@ -41,7 +39,7 @@ func input(m *ice.Message, arg ...string) bool {
var Index = &ice.Context{Name: "mall", Help: "贸易中心", var Index = &ice.Context{Name: "mall", Help: "贸易中心",
Caches: map[string]*ice.Cache{}, Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{ Configs: map[string]*ice.Config{
"railway": {Name: "railway", Help: "12306", Value: kit.Data()}, "railway": {Name: "railway", Help: "12306", Value: kit.Data("site", "https://kyfw.12306.cn")},
"asset": {Name: "asset", Help: "资产", Value: kit.Data(kit.MDB_SHORT, "account", "site", kit.Dict( "asset": {Name: "asset", Help: "资产", Value: kit.Data(kit.MDB_SHORT, "account", "site", kit.Dict(
"公积金", "https://grwsyw.gjj.beijing.gov.cn/ish/flow/menu/PPLGRZH0102?_r=0.6644871172745264", "公积金", "https://grwsyw.gjj.beijing.gov.cn/ish/flow/menu/PPLGRZH0102?_r=0.6644871172745264",
@ -54,28 +52,23 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
Commands: map[string]*ice.Command{ Commands: map[string]*ice.Command{
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Load() m.Load()
m.Cmd(ice.WEB_SPIDE, "add", "12306", m.Conf("railway", "meta.site"))
// m.Cmd(ice.CTX_CONFIG, "load", "mall.json")
// if m.Richs(ice.WEB_SPIDE, nil, "12306", nil) == nil {
// m.Cmd(ice.WEB_SPIDE, "add", "12306", "https://kyfw.12306.cn")
// }
}}, }},
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Save("asset") m.Save("asset", "railway")
// m.Cmd(ice.CTX_CONFIG, "save", "mall.json", "web.mall.railway")
}}, }},
"spend": {Name: "spend", Help: "支出", List: kit.List( "spend": {Name: "spend", Help: "支出", List: kit.List(
kit.MDB_INPUT, "text", "name", "account", "figure", "key", kit.MDB_INPUT, "text", "name", "account", "figure", "key",
kit.MDB_INPUT, "text", "name", "to", "figure", "key", kit.MDB_INPUT, "text", "name", "to", "figure", "key",
kit.MDB_INPUT, "text", "name", "name", "figure", "key", kit.MDB_INPUT, "text", "name", "name", "figure", "key",
kit.MDB_INPUT, "text", "name", "value", "figure", "key",
kit.MDB_INPUT, "button", "name", "记录", kit.MDB_INPUT, "button", "name", "记录",
kit.MDB_INPUT, "textarea", "name", "text", "figure", "key", kit.MDB_INPUT, "textarea", "name", "text", "figure", "key",
kit.MDB_INPUT, "text", "name", "value", "figure", "key",
kit.MDB_INPUT, "text", "name", "time", "figure", "date", kit.MDB_INPUT, "text", "name", "time", "figure", "date",
), 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 input(m, arg...) { if input(m, arg...) {
// 输入补全
return return
} }
if len(arg) < 2 { if len(arg) < 2 {
@ -83,26 +76,24 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
m.Cmdy("asset", arg) m.Cmdy("asset", arg)
return return
} }
if len(arg) == 4 {
arg = append(arg, "")
}
// 添加流水 // 添加流水
amount := kit.Int(arg[3]) amount := kit.Int(arg[4])
m.Cmdy("asset", arg[0], "", "转出", arg[1], arg[2], -amount, "time", arg[5:]) m.Cmdy("asset", arg[0], "", "转出", arg[1], arg[2], -amount, "time", arg[5:])
m.Cmdy("asset", arg[1], "", "转入", arg[0], arg[2], amount, "time", arg[5:]) m.Cmdy("asset", arg[1], "", "转入", arg[0], arg[2], amount, "time", arg[5:])
m.Cmdy("asset", arg[1], "", "支出", arg[2], arg[4], -amount, "time", arg[5:]) m.Cmdy("asset", arg[1], "", "支出", arg[2], arg[3], -amount, "time", arg[5:])
m.Cmdy("asset", "流水", "", "支出", arg[2], arg[4], -amount, "time", arg[5:]) m.Cmdy("asset", "流水", "", "支出", arg[2], arg[3], -amount, "time", arg[5:])
}}, }},
"trans": {Name: "trans", Help: "转账", List: kit.List( "trans": {Name: "trans", Help: "转账", List: kit.List(
kit.MDB_INPUT, "text", "name", "account", "figure", "key", kit.MDB_INPUT, "text", "name", "account", "figure", "key",
kit.MDB_INPUT, "text", "name", "to", "figure", "key", kit.MDB_INPUT, "text", "name", "to", "figure", "key",
kit.MDB_INPUT, "text", "name", "name", "figure", "key", kit.MDB_INPUT, "text", "name", "name", "figure", "key",
kit.MDB_INPUT, "text", "name", "value", "figure", "key",
kit.MDB_INPUT, "button", "name", "记录", kit.MDB_INPUT, "button", "name", "记录",
kit.MDB_INPUT, "textarea", "name", "text", "figure", "key", kit.MDB_INPUT, "textarea", "name", "text", "figure", "key",
kit.MDB_INPUT, "text", "name", "value", "figure", "key",
kit.MDB_INPUT, "text", "name", "time", "figure", "date",
), 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 input(m, arg...) { if input(m, arg...) {
// 输入补全
return return
} }
if len(arg) < 2 { if len(arg) < 2 {
@ -110,15 +101,12 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
m.Cmdy("asset", arg) m.Cmdy("asset", arg)
return return
} }
if len(arg) == 4 {
arg = append(arg, "")
}
// 添加流水 // 添加流水
amount := kit.Int(arg[3]) amount := kit.Int(arg[4])
m.Cmdy("asset", arg[0], "", "转出", arg[1], arg[2], -amount, arg[5:]) m.Cmdy("asset", arg[0], "", "转出", arg[1], arg[2], -amount, "time", arg[5:])
m.Cmdy("asset", arg[1], "", "转入", arg[0], arg[2], amount, arg[5:]) m.Cmdy("asset", arg[1], "", "转入", arg[0], arg[2], amount, "time", arg[5:])
m.Cmd("asset", "流水", "", "转出", arg[2], arg[4], -amount, arg[5:]) m.Cmd("asset", "流水", "", "转出", arg[2], arg[3], -amount, "time", arg[5:])
m.Cmd("asset", "流水", "", "转入", arg[2], arg[4], amount, arg[5:]) m.Cmd("asset", "流水", "", "转入", arg[2], arg[3], amount, "time", arg[5:])
}}, }},
"bonus": {Name: "bonus", Help: "收入", List: kit.List( "bonus": {Name: "bonus", Help: "收入", List: kit.List(
kit.MDB_INPUT, "text", "name", "account", "figure", "key", kit.MDB_INPUT, "text", "name", "account", "figure", "key",
@ -126,9 +114,10 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
kit.MDB_INPUT, "text", "name", "value", "figure", "key", kit.MDB_INPUT, "text", "name", "value", "figure", "key",
kit.MDB_INPUT, "button", "name", "记录", kit.MDB_INPUT, "button", "name", "记录",
kit.MDB_INPUT, "textarea", "name", "text", "figure", "key", kit.MDB_INPUT, "textarea", "name", "text", "figure", "key",
kit.MDB_INPUT, "text", "name", "time", "figure", "date",
), 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 input(m, arg...) { if input(m, arg...) {
// 输入补全
return return
} }
if len(arg) < 2 { if len(arg) < 2 {
@ -138,8 +127,8 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
} }
// 添加流水 // 添加流水
amount := kit.Int(arg[2]) amount := kit.Int(arg[2])
m.Cmdy("asset", arg[0], "", "收入", arg[1], arg[3], amount, arg[4:]) m.Cmdy("asset", arg[0], "", "收入", arg[1], arg[3], amount, "time", arg[4:])
m.Cmdy("asset", "流水", "", "收入", arg[1], arg[3], amount, arg[4:]) m.Cmdy("asset", "流水", "", "收入", arg[1], arg[3], amount, "time", arg[4:])
}}, }},
"month": {Name: "month", Help: "工资", List: kit.List( "month": {Name: "month", Help: "工资", List: kit.List(
kit.MDB_INPUT, "text", "name", "month", kit.MDB_INPUT, "text", "name", "month",
@ -301,22 +290,17 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
kit.MDB_INPUT, "text", "name", "id", "action", "auto", kit.MDB_INPUT, "text", "name", "id", "action", "auto",
kit.MDB_INPUT, "button", "name", "查看", "action", "auto", kit.MDB_INPUT, "button", "name", "查看", "action", "auto",
kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", kit.MDB_INPUT, "button", "name", "返回", "cb", "Last",
kit.MDB_INPUT, "button", "name", "保存",
), 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 len(arg) == 0 { if m.Option("_action") == "保存" {
// 账户列表 arg = []string{"action", "save"}
m.Richs("asset", nil, "*", func(key string, value map[string]interface{}) {
m.Push(key, value["meta"], []string{"account", "count", "amount", "bonus", "spend"})
})
m.Sort("amount", "int_r")
return
} }
if len(arg) > 0 && arg[0] == "action" { if len(arg) > 0 && arg[0] == "action" {
switch arg[1] { switch arg[1] {
case "modify": case "modify":
// 修改数据 // 修改数据
m.Richs("asset", nil, m.Option("account"), func(key string, account map[string]interface{}) { m.Richs(cmd, nil, m.Option("account"), func(key string, account map[string]interface{}) {
m.Grows("asset", kit.Keys("hash", key), "id", arg[5], func(index int, current 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]) 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]) kit.Value(current, arg[2], arg[3])
}) })
@ -325,18 +309,18 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
case "save": case "save":
// 保存数据 // 保存数据
m.Option("cache.limit", -2) m.Option("cache.limit", -2)
if f, p, e := kit.Create(arg[2]); m.Assert(e) { if f, p, e := kit.Create(kit.Select("usr/local/asset.csv", arg, 2)); m.Assert(e) {
defer f.Close() defer f.Close()
w := csv.NewWriter(f) w := csv.NewWriter(f)
defer w.Flush() defer w.Flush()
w.Write([]string{"时间", "收支类型", "账目分类", "备注", "金额", "账户"}) w.Write([]string{"时间", "收支类型", "账目分类", "备注", "金额", "账户"})
m.Richs("asset", nil, kit.Select("*", arg, 3), func(key string, account map[string]interface{}) { m.Richs(cmd, nil, kit.Select("*", arg, 3), func(key string, account map[string]interface{}) {
if kit.Format(kit.Value(account, "meta.account")) == "流水" { if kit.Format(kit.Value(account, "meta.account")) == "流水" {
return return
} }
m.Grows("asset", kit.Keys("hash", key), kit.Select("", arg, 4), kit.Select("", arg, 5), func(index int, current map[string]interface{}) { 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{ w.Write([]string{
kit.Format(current["time"]), kit.Format(current["time"]),
kit.Format(current["type"]), kit.Format(current["type"]),
@ -348,6 +332,7 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
}) })
}) })
m.Log(ice.LOG_EXPORT, "%s", p) m.Log(ice.LOG_EXPORT, "%s", p)
m.Cmdy(ice.WEB_STORY, "catch", "csv", p)
} }
case "load": case "load":
@ -361,15 +346,15 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
"time", data["时间"], "extra", kit.UnMarshal(data["extra"]), "time", data["时间"], "extra", kit.UnMarshal(data["extra"]),
) )
if m.Richs("asset", nil, account, nil) == nil { if m.Richs(cmd, nil, account, nil) == nil {
// 添加账户 // 添加账户
m.Log(ice.LOG_CREATE, "account: %s", account) m.Log(ice.LOG_CREATE, "account: %s", account)
m.Rich("asset", nil, kit.Data("account", account, "amount", "0", "bonus", "0", "spend", "0")) m.Rich(cmd, nil, kit.Data("account", account, "amount", "0", "bonus", "0", "spend", "0"))
} }
m.Richs("asset", nil, account, func(key string, value map[string]interface{}) { m.Richs(cmd, nil, account, func(key string, value map[string]interface{}) {
// 账户流水 // 账户流水
m.Grow("asset", kit.Keys("hash", key), item) m.Grow(cmd, kit.Keys("hash", key), item)
// 账户结余 // 账户结余
amount := kit.Int(kit.Value(value, "meta.amount")) + kit.Int(v) amount := kit.Int(kit.Value(value, "meta.amount")) + kit.Int(v)
@ -391,17 +376,26 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
return return
} }
if m.Richs("asset", nil, arg[0], nil) == nil { 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")
return
}
if len(arg) > 5 && m.Richs(cmd, nil, arg[0], nil) == nil {
// 添加账户 // 添加账户
m.Rich("asset", nil, kit.Data("account", arg[0], "amount", "0", "bonus", "0", "spend", "0")) m.Rich(cmd, nil, kit.Data("account", arg[0], "amount", "0", "bonus", "0", "spend", "0"))
m.Log(ice.LOG_CREATE, "account: %s", arg[0]) m.Log(ice.LOG_CREATE, "account: %s", arg[0])
} }
field := []string{"time", "id", "value", "type", "name", "text"} field := []string{"time", "id", "value", "type", "name", "text"}
m.Richs("asset", nil, arg[0], func(key string, value map[string]interface{}) { m.Richs(cmd, nil, arg[0], func(key string, value map[string]interface{}) {
if len(arg) == 1 { if len(arg) == 1 {
// 消费流水 // 消费流水
m.Grows("asset", kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) { m.Grows(cmd, kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) {
m.Push("", value, field) m.Push("", value, field)
}) })
m.Sort("id", "int_r") m.Sort("id", "int_r")
@ -409,7 +403,7 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
} }
if len(arg) == 2 { if len(arg) == 2 {
// 消费详情 // 消费详情
m.Grows("asset", kit.Keys("hash", key), "id", arg[1], func(index int, value map[string]interface{}) { m.Grows(cmd, kit.Keys("hash", key), "id", arg[1], func(index int, value map[string]interface{}) {
m.Push("detail", value) m.Push("detail", value)
}) })
return return
@ -428,7 +422,7 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
// 消费备注 // 消费备注
name, value = "text", arg[4] name, value = "text", arg[4]
} }
m.Grows("asset", kit.Keys("hash", key), name, value, func(index int, value map[string]interface{}) { m.Grows(cmd, kit.Keys("hash", key), name, value, func(index int, value map[string]interface{}) {
m.Push("", value, field) m.Push("", value, field)
}) })
m.Sort("id", "int_r") m.Sort("id", "int_r")
@ -457,7 +451,7 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
} }
} }
// 添加流水 // 添加流水
n := m.Grow("asset", kit.Keys("hash", key), data) n := m.Grow(cmd, kit.Keys(kit.MDB_HASH, key), data)
// 账户结余 // 账户结余
total := kit.Int(kit.Value(value, "meta.amount")) + amount total := kit.Int(kit.Value(value, "meta.amount")) + amount
@ -477,51 +471,34 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
}) })
}}, }},
"passcode": &ice.Command{Name: "passcode", Help: "passcode", Meta: kit.Dict("active", "mall/input"), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
prefix := []string{ice.WEB_SPIDE, "12306"}
if len(arg) == 0 {
m.Cmd(prefix, "raw", "/passport/web/auth/uamtk-static", "form", "appid", "otn")
m.Cmd(prefix, "raw", "GET", "/otn/HttpZF/GetJS")
m.Cmd(prefix, "raw", "/otn/login/conf")
m.Cmdy(prefix, "GET", fmt.Sprintf("/passport/captcha/captcha-image64?login_site=E&module=login&rand=sjrand"))
return
}
switch arg[0] {
case "check":
m.Cmdy(prefix, "GET", fmt.Sprintf("/passport/captcha/captcha-check?login_site=E&rand=sjrand&answer=%s", arg[1]))
case "login":
m.Cmdy(prefix, "raw", "/passport/web/login", "form", "username", arg[1], "password", arg[2], "answer", arg[3], "appid", "otn")
}
}},
"railway": &ice.Command{Name: "railway", Help: "12306", List: kit.List( "railway": &ice.Command{Name: "railway", Help: "12306", List: kit.List(
kit.MDB_INPUT, "text", "name", "date", "value", "2020-01-22", kit.MDB_INPUT, "text", "name", "date", "figure", "date",
kit.MDB_INPUT, "text", "name", "from", "value", "北京", kit.MDB_INPUT, "text", "name", "from", "value", "北京", "figure", "city",
kit.MDB_INPUT, "text", "name", "to", "value", "曲阜", kit.MDB_INPUT, "text", "name", "to", "value", "曲阜", "figure", "city",
kit.MDB_INPUT, "button", "name", "查询", kit.MDB_INPUT, "button", "name", "查询",
), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { ), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
if !m.Confs("railway", "meta.site") { if !m.Confs("railway", "meta.place") {
list := strings.Split(strings.TrimPrefix(m.Cmdx(ice.WEB_SPIDE, "12306", "raw", "GET", "/otn/resources/js/framework/station_name.js?station_version=1.9090"), "var statuion_names ='"), "|") list := strings.Split(strings.TrimPrefix(m.Cmdx(ice.WEB_SPIDE, "12306", "raw", "GET", "/otn/resources/js/framework/station_name.js?station_version=1.9090"), "var statuion_names ='"), "|")
for i := 0; i < len(list)-5; i += 5 { for i := 0; i < len(list)-5; i += 5 {
m.Conf("railway", kit.Keys("meta.site", list[i+1]), list[i+2]) m.Conf("railway", kit.Keys("meta.place", list[i+1]), list[i+2])
} }
} }
date := time.Now().Add(time.Hour * 24).Format("2006-01-02") date := strings.Split(m.Time("24h"), " ")[0]
if len(arg) > 0 { if len(arg) > 0 {
date, arg = arg[0], arg[1:] date, arg = arg[0], arg[1:]
} }
date = strings.Split(date, " ")[0]
from := "北京" from := "北京"
if len(arg) > 0 { if len(arg) > 0 {
from, arg = arg[0], arg[1:] from, arg = arg[0], arg[1:]
} }
from_code := m.Conf("railway", kit.Keys("meta.site", from)) from_code := m.Conf("railway", kit.Keys("meta.place", from))
to := "曲阜" to := "曲阜"
if len(arg) > 0 { if len(arg) > 0 {
to, arg = arg[0], arg[1:] to, arg = arg[0], arg[1:]
} }
to_code := m.Conf("railway", kit.Keys("meta.site", to)) to_code := m.Conf("railway", kit.Keys("meta.place", to))
m.Echo("%s->%s %s\n", from, to, date) m.Echo("%s->%s %s\n", from, to, date)
@ -546,6 +523,24 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
}) })
}) })
}}, }},
"passcode": &ice.Command{Name: "passcode", Help: "passcode", Meta: kit.Dict("active", "mall/input"), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
prefix := []string{ice.WEB_SPIDE, "12306"}
if len(arg) == 0 {
m.Cmd(prefix, "raw", "/passport/web/auth/uamtk-static", "form", "appid", "otn")
m.Cmd(prefix, "raw", "GET", "/otn/HttpZF/GetJS")
m.Cmd(prefix, "raw", "/otn/login/conf")
m.Cmdy(prefix, "GET", fmt.Sprintf("/passport/captcha/captcha-image64?login_site=E&module=login&rand=sjrand"))
return
}
switch arg[0] {
case "check":
m.Cmdy(prefix, "GET", fmt.Sprintf("/passport/captcha/captcha-check?login_site=E&rand=sjrand&answer=%s", arg[1]))
case "login":
m.Cmdy(prefix, "raw", "/passport/web/login", "form", "username", arg[1], "password", arg[2], "answer", arg[3], "appid", "otn")
}
}},
}, },
} }

View File

@ -2,7 +2,6 @@ package team
import ( import (
"github.com/shylinux/icebergs" "github.com/shylinux/icebergs"
_ "github.com/shylinux/icebergs/base"
"github.com/shylinux/icebergs/base/web" "github.com/shylinux/icebergs/base/web"
"github.com/shylinux/toolkits" "github.com/shylinux/toolkits"
@ -53,18 +52,23 @@ var Index = &ice.Context{Name: "team", Help: "团队中心",
m.Save("task") m.Save("task")
}}, }},
"task": {Name: "task [zone [id [type [name [text args...]]]]]", Help: "任务", Meta: kit.Dict("remote", "you"), List: kit.List( "task": {Name: "task [zone [id [type [name [text args...]]]]]", Help: "任务", List: kit.List(
kit.MDB_INPUT, "text", "name", "zone", "action", "auto", kit.MDB_INPUT, "text", "name", "zone", "action", "auto",
kit.MDB_INPUT, "text", "name", "id", "action", "auto", kit.MDB_INPUT, "text", "name", "id", "action", "auto",
kit.MDB_INPUT, "button", "name", "查看", "action", "auto", kit.MDB_INPUT, "button", "name", "查看", "action", "auto",
kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", kit.MDB_INPUT, "button", "name", "返回", "cb", "Last",
kit.MDB_INPUT, "button", "name", "保存",
), 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 m.Option("_action") == "保存" {
arg = []string{"action", "export"}
}
if len(arg) > 0 && arg[0] == "action" { if len(arg) > 0 && arg[0] == "action" {
switch arg[1] { switch arg[1] {
case "export": case "export":
// 导出数据 // 导出数据
m.Option("cache.limit", -2) m.Option("cache.limit", -2)
if f, p, e := kit.Create(arg[2]); m.Assert(e) { if f, p, e := kit.Create(kit.Select("usr/local/task.csv", arg, 2)); m.Assert(e) {
defer f.Close() defer f.Close()
w := csv.NewWriter(f) w := csv.NewWriter(f)
@ -86,6 +90,7 @@ var Index = &ice.Context{Name: "team", Help: "团队中心",
}) })
}) })
m.Log(ice.LOG_EXPORT, "%s", p) m.Log(ice.LOG_EXPORT, "%s", p)
m.Cmdy(ice.WEB_STORY, "catch", "csv", p)
} }
case "import": case "import":
@ -195,11 +200,14 @@ var Index = &ice.Context{Name: "team", Help: "团队中心",
// 词汇统计 // 词汇统计
web.Count(m, cmd, "meta.word.type", arg[2]) web.Count(m, cmd, "meta.word.type", arg[2])
web.Count(m, cmd, "meta.word.name", arg[3]) web.Count(m, cmd, "meta.word.name", arg[3])
web.Count(m, cmd, "meta.word.text", arg[4])
// 数据结构 // 数据结构
extra := kit.Dict() extra := kit.Dict()
data := kit.Dict("type", arg[2], "name", arg[3], "text", arg[4], "extra", extra, data := kit.Dict(
kit.MDB_TYPE, arg[2], kit.MDB_NAME, arg[3], kit.MDB_TEXT, arg[4],
"begin_time", m.Time(), "close_time", m.Time(), "status", "prepare", "begin_time", m.Time(), "close_time", m.Time(), "status", "prepare",
"extra", extra,
) )
// 扩展字段 // 扩展字段
@ -218,15 +226,13 @@ var Index = &ice.Context{Name: "team", Help: "团队中心",
}) })
}}, }},
"plan": {Name: "plan day|week|month|year", Help: "计划", Meta: kit.Dict( "plan": {Name: "plan day|week|month|year", Help: "计划", Meta: kit.Dict(
"remote", "you", "display", "team/plan", "detail", []string{"process", "finish", "cancel"}, "display", "team/plan", "detail", []string{"process", "finish", "cancel"},
), List: kit.List( ), List: kit.List(
kit.MDB_INPUT, "select", "name", "scale", "value", "day", "values", []string{"day", "week", "month", "months", "year", "long"}, "action", "auto", kit.MDB_INPUT, "select", "name", "scale", "value", "day", "values", []string{"day", "week", "month", "months", "year", "long"}, "action", "auto",
kit.MDB_INPUT, "text", "name", "begin_time", "figure", "date", "action", "auto", kit.MDB_INPUT, "text", "name", "begin_time", "figure", "date", "action", "auto",
kit.MDB_INPUT, "text", "name", "end_time", "figure", "date", "action", "auto", kit.MDB_INPUT, "text", "name", "end_time", "figure", "date", "action", "auto",
kit.MDB_INPUT, "button", "name", "查看", "action", "auto", kit.MDB_INPUT, "button", "name", "查看", "action", "auto",
), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Option("cache.limit", -1)
// 起始日期 // 起始日期
first := time.Now() first := time.Now()
if len(arg) > 1 { if len(arg) > 1 {
@ -241,6 +247,7 @@ var Index = &ice.Context{Name: "team", Help: "团队中心",
} }
last = DateZero(m, last) last = DateZero(m, last)
m.Option("cache.limit", -1)
switch head := kit.Simple(m.Confv(cmd, "meta.head")); arg[0] { switch head := kit.Simple(m.Confv(cmd, "meta.head")); arg[0] {
case "action": case "action":
switch arg[1] { switch arg[1] {
@ -416,7 +423,7 @@ var Index = &ice.Context{Name: "team", Help: "团队中心",
m.Sort("year", "int") m.Sort("year", "int")
} }
}}, }},
"stat": {Name: "stat", Help: "统计", Meta: kit.Dict("remote", "you"), List: kit.List( "stat": {Name: "stat", Help: "统计", List: kit.List(
kit.MDB_INPUT, "text", "name", "begin_time", "figure", "date", "action", "auto", kit.MDB_INPUT, "text", "name", "begin_time", "figure", "date", "action", "auto",
kit.MDB_INPUT, "text", "name", "end_time", "figure", "date", "action", "auto", kit.MDB_INPUT, "text", "name", "end_time", "figure", "date", "action", "auto",
kit.MDB_INPUT, "button", "name", "查看", "action", "auto", kit.MDB_INPUT, "button", "name", "查看", "action", "auto",
@ -466,13 +473,12 @@ var Index = &ice.Context{Name: "team", Help: "团队中心",
m.Push("max", kit.FmtTime(int64(stat["max"])*int64(time.Second))) m.Push("max", kit.FmtTime(int64(stat["max"])*int64(time.Second)))
}) })
}}, }},
"miss": {Name: "miss zone type name text", Help: "任务", Meta: kit.Dict("remote", "you"), List: kit.List( "miss": {Name: "miss zone type name text", Help: "任务", List: kit.List(
kit.MDB_INPUT, "text", "name", "zone", "figure", "key", "action", "auto", kit.MDB_INPUT, "text", "name", "zone", "figure", "key", "action", "auto",
kit.MDB_INPUT, "text", "name", "type", "figure", "key", kit.MDB_INPUT, "text", "name", "type", "figure", "key",
kit.MDB_INPUT, "text", "name", "name", "figure", "key", kit.MDB_INPUT, "text", "name", "name", "figure", "key",
kit.MDB_INPUT, "button", "name", "添加", kit.MDB_INPUT, "button", "name", "添加",
kit.MDB_INPUT, "textarea", "name", "text", kit.MDB_INPUT, "textarea", "name", "text",
kit.MDB_INPUT, "text", "name", "location", "figure", "key", "cb", "location", "className", "opts",
), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { ), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
if len(arg) > 0 && arg[0] == "action" { if len(arg) > 0 && arg[0] == "action" {
switch arg[1] { switch arg[1] {

View File

@ -8,6 +8,7 @@ import (
"github.com/shylinux/toolkits" "github.com/shylinux/toolkits"
"fmt" "fmt"
"io"
"io/ioutil" "io/ioutil"
"math/rand" "math/rand"
"os" "os"
@ -477,7 +478,20 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心",
kit.MDB_INPUT, "text", "name", "name", kit.MDB_INPUT, "text", "name", "name",
kit.MDB_INPUT, "button", "name", "执行", kit.MDB_INPUT, "button", "name", "执行",
kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", kit.MDB_INPUT, "button", "name", "返回", "cb", "Last",
kit.MDB_INPUT, "button", "name", "上传", "figure", "upload",
), 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 m.Option("_action") == "上传" {
if f, h, e := m.R.FormFile("upload"); m.Assert(e) {
defer f.Close()
if o, p, e := kit.Create(path.Join(m.Option("name"), h.Filename)); m.Assert(e) {
if n, e := io.Copy(o, f); m.Assert(e) {
m.Log(ice.LOG_IMPORT, "%s: %s", kit.FmtSize(n), p)
}
}
}
return
}
if len(arg) > 0 && arg[0] == "action" { if len(arg) > 0 && arg[0] == "action" {
switch arg[1] { switch arg[1] {
case "删除": case "删除":

View File

@ -77,7 +77,7 @@ var Index = &ice.Context{Name: "mp", Help: "小程序",
}) })
case "scan": case "scan":
m.Render(ice.RENDER_QRCODE, m.Option("scan")) m.Cmd(ice.WEB_FAVOR, "device", "scan", m.Option("name"), m.Option("text"))
case "auth": case "auth":
if !m.Options(ice.MSG_USERNAME) { if !m.Options(ice.MSG_USERNAME) {