1
0
forked from x/icebergs

opt web.*

This commit is contained in:
shylinux 2020-03-06 01:05:09 +08:00
parent 6e9ceeacd1
commit 8765fe3187
4 changed files with 124 additions and 87 deletions

View File

@ -244,46 +244,51 @@ func (web *Frame) HandleCmd(m *ice.Message, key string, cmd *ice.Command) {
}
}
if !web.Login(msg, w, r) {
// 登录失败
w.WriteHeader(401)
return
}
if msg.Optionv("cmds") == nil {
msg.Optionv("cmds", strings.Split(msg.Option(ice.MSG_USERURL), "/")[2:])
}
cmds := kit.Simple(msg.Optionv("cmds"))
// 执行命令
if web.Login(msg, w, r) && msg.Target().Run(msg, cmd, msg.Option(ice.MSG_USERURL), kit.Simple(msg.Optionv("cmds"))...) != nil {
// 输出响应
switch msg.Append("_output") {
case "void":
case "status":
msg.Info("status %s", msg.Result())
w.WriteHeader(kit.Int(kit.Select("200", msg.Result(0))))
case "redirect":
http.Redirect(w, r, msg.Result(), 302)
case "file":
msg.Info("_output: %s %s", msg.Append("_output"), msg.Append("file"))
w.Header().Set("Content-Disposition", fmt.Sprintf("filename=%s", kit.Select(msg.Append("name"), msg.Append("story"))))
w.Header().Set("Content-Type", kit.Select("text/html", msg.Append("type")))
http.ServeFile(w, r, msg.Append("file"))
case "qrcode":
if qr, e := qrcode.New(msg.Result(), qrcode.Medium); m.Assert(e) {
w.Header().Set("Content-Type", "image/png")
m.Assert(qr.Write(256, w))
}
case "result":
w.Header().Set("Content-Type", kit.Select("text/html", msg.Append("type")))
fmt.Fprint(w, msg.Result())
default:
fmt.Fprint(w, msg.Formats("meta"))
}
if msg.Option("proxy") != "" {
msg.Cmd(ice.WEB_PROXY, msg.Option("proxy"), msg.Option(ice.MSG_USERURL), cmds)
} else {
switch msg.Append("_output") {
case "status":
msg.Info("status %s", msg.Result())
w.WriteHeader(kit.Int(kit.Select("200", msg.Result())))
msg.Target().Run(msg, cmd, msg.Option(ice.MSG_USERURL), cmds...)
}
// 输出响应
switch msg.Append("_output") {
case "void":
case "status":
msg.Info("status %s", msg.Result())
w.WriteHeader(kit.Int(kit.Select("200", msg.Result(0))))
case "redirect":
http.Redirect(w, r, msg.Result(), 302)
case "file":
msg.Info("_output: %s %s", msg.Append("_output"), msg.Append("file"))
w.Header().Set("Content-Disposition", fmt.Sprintf("filename=%s", kit.Select(msg.Append("name"), msg.Append("story"))))
w.Header().Set("Content-Type", kit.Select("text/html", msg.Append("type")))
http.ServeFile(w, r, msg.Append("file"))
case "qrcode":
if qr, e := qrcode.New(msg.Result(), qrcode.Medium); m.Assert(e) {
w.Header().Set("Content-Type", "image/png")
m.Assert(qr.Write(256, w))
}
case "result":
w.Header().Set("Content-Type", kit.Select("text/html", msg.Append("type")))
fmt.Fprint(w, msg.Result())
default:
fmt.Fprint(w, msg.Formats("meta"))
}
})
})
@ -1517,6 +1522,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
ice.WEB_ROUTE: {Name: "route", Help: "路由", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
}},
ice.WEB_PROXY: {Name: "proxy", Help: "代理", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmdy(ice.WEB_SPACE, arg[0], arg[1:])
}},
ice.WEB_GROUP: {Name: "group", Help: "分组", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
}},

View File

@ -47,6 +47,8 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
"公积金", "https://grwsyw.gjj.beijing.gov.cn/ish/flow/menu/PPLGRZH0102?_r=0.6644871172745264",
"社保", "http://fuwu.rsj.beijing.gov.cn/csibiz/indinfo/index.jsp",
"个税", "https://its.beijing.chinatax.gov.cn:8443/zmsqjl.html",
), "word", kit.Dict(
"type", kit.Dict("流水", 0), "name", kit.Dict("晚餐", 0), "text", kit.Dict("泡面", 0), "value", kit.Dict("4500", 0),
))},
},
Commands: map[string]*ice.Command{
@ -67,7 +69,7 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
"spend": {Name: "spend", Help: "支出", List: kit.List(
kit.MDB_INPUT, "text", "name", "account", "figure", "key",
kit.MDB_INPUT, "text", "name", "name", "figure", "key",
kit.MDB_INPUT, "text", "name", "value", "cb", "money",
kit.MDB_INPUT, "text", "name", "value", "figure", "key",
kit.MDB_INPUT, "button", "name", "记录",
kit.MDB_INPUT, "textarea", "name", "text", "figure", "key",
), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
@ -80,17 +82,16 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
return
}
// 添加流水
amount := kit.Int(arg[3])
m.Cmdy("asset", arg[0], "", "支出", arg[1], arg[2], -amount, arg[4:])
m.Cmdy("asset", "流水", "", "支出", arg[1], arg[2], -amount, arg[4:])
amount := kit.Int(arg[2])
m.Cmdy("asset", arg[0], "", "支出", arg[1], arg[3], -amount, arg[4:])
m.Cmdy("asset", "流水", "", "支出", arg[1], arg[3], -amount, arg[4:])
}},
"trans": {Name: "trans", Help: "转账", List: kit.List(
kit.MDB_INPUT, "text", "name", "account", "figure", "key",
kit.MDB_INPUT, "text", "name", "to", "figure", "key",
kit.MDB_INPUT, "text", "name", "name", "figure", "key",
kit.MDB_INPUT, "text", "name", "text", "figure", "key",
kit.MDB_INPUT, "text", "name", "value", "cb", "money",
kit.MDB_INPUT, "text", "name", "value", "figure", "key",
kit.MDB_INPUT, "button", "name", "记录",
kit.MDB_INPUT, "textarea", "name", "text", "figure", "key",
), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
// 输入补全
if input(m, arg...) {
@ -102,18 +103,18 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
return
}
// 添加流水
amount := kit.Int(arg[4])
m.Cmdy("asset", arg[0], "", "转出", arg[2], arg[3], -amount, arg[5:])
m.Cmd("asset", arg[1], "", "转入", arg[2], arg[3], amount, arg[5:])
m.Cmd("asset", "流水", "", "转出", arg[2], arg[3], -amount, arg[5:])
m.Cmd("asset", "流水", "", "转入", arg[2], arg[3], amount, arg[5:])
amount := kit.Int(arg[2])
m.Cmdy("asset", arg[0], "", "转出", arg[1], arg[3], -amount, arg[4:])
m.Cmdy("asset", arg[1], "", "转入", arg[0], arg[3], amount, arg[4:])
m.Cmd("asset", "流水", "", "转出", arg[1], arg[3], -amount, arg[4:])
m.Cmd("asset", "流水", "", "转入", arg[0], arg[3], amount, arg[4:])
}},
"bonus": {Name: "bonus", Help: "收入", List: kit.List(
kit.MDB_INPUT, "text", "name", "account", "figure", "key",
kit.MDB_INPUT, "text", "name", "name", "figure", "key",
kit.MDB_INPUT, "text", "name", "text", "figure", "key",
kit.MDB_INPUT, "text", "name", "value", "cb", "money",
kit.MDB_INPUT, "text", "name", "value", "figure", "key",
kit.MDB_INPUT, "button", "name", "记录",
kit.MDB_INPUT, "textarea", "name", "text", "figure", "key",
), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
// 输入补全
if input(m, arg...) {
@ -125,16 +126,23 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
return
}
// 添加流水
m.Cmdy("asset", arg[0], "", "收入", arg[1:])
m.Cmdy("asset", "流水", "", "收入", arg[1:])
amount := kit.Int(arg[2])
m.Cmdy("asset", arg[0], "", "收入", arg[1], arg[3], amount, arg[4:])
m.Cmdy("asset", "流水", "", "收入", arg[1], arg[3], amount, arg[4:])
}},
"month": {Name: "month", Help: "工资", List: kit.List(
kit.MDB_INPUT, "text", "name", "month",
kit.MDB_INPUT, "text", "name", "value",
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", "记录",
), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
data := map[string]int{"个税方案": 6, "基本工资": 0, "个税": 0,
// 输入补全
if input(m, arg...) {
return
}
data := map[string]int64{"个税方案": 6, "基本工资": 0, "个税": 0,
"公积金比例": 1200, "养老保险比例": 800, "医疗保险比例": 200, "失业保险比例": 20, "工伤保险比例": 2, "生育保险比例": 0,
"公积金金额": 0, "养老保险金额": 0, "医疗保险金额": 0, "失业保险金额": 0, "工伤保险金额": 0, "生育保险金额": 0,
@ -142,28 +150,33 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
"企业公积金金额": 0, "企业养老保险金额": 0, "企业医疗保险金额": 0, "企业失业保险金额": 0, "企业工伤保险金额": 0, "企业生育保险金额": 0,
}
for i := 2; i < len(arg)-1; i += 2 {
for i := 3; i < len(arg)-1; i += 2 {
if _, ok := data[arg[i]]; ok {
data[arg[i]] = kit.Int(arg[i+1])
data[arg[i]] = kit.Int64(arg[i+1])
arg[i] = ""
}
}
// data["养老保险比例"] = 725
// data["失业保险比例"] = 20
//
salary := kit.Int(arg[1])
data["养老保险比例"] = 725
data["失业保险比例"] = 18
salary := kit.Int64(arg[1])
data["个税"] = kit.Int64(arg[2])
base := data["基本工资"]
if base == 0 {
base = salary
}
// 五险一金
amount := 0
amount := int64(0)
for _, k := range []string{"公积金", "养老保险", "医疗保险", "失业保险", "工伤保险"} {
m.Push("名目", k)
value := -base * kit.Int(data[k+"比例"]) / 10000
value := -base * kit.Int64(data[k+"比例"]) / 10000
m.Info("%v %v: %v %v", base, k, base*kit.Int64(data[k+"比例"]), value)
if m.Push("比例", data[k+"比例"]); data[k+"金额"] == 0 {
if k == "医疗保险" {
value -= 300
}
data[k+"金额"] = value
} else {
value = data[k+"金额"]
@ -173,10 +186,10 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
}
// 企业五险一金
company := 0
company := int64(0)
for _, k := range []string{"企业公积金", "企业养老保险", "企业医疗保险", "企业失业保险", "企业工伤保险", "企业生育保险"} {
m.Push("名目", k)
value := -base * kit.Int(data[k+"比例"]) / 10000
value := -base * kit.Int64(data[k+"比例"]) / 10000
if m.Push("比例", data[k+"比例"]); data[k+"金额"] == 0 {
data[k+"金额"] = value
}
@ -188,12 +201,12 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
m.Push("金额", company)
// 其它津贴
for i := 2; i < len(arg)-1; i += 2 {
for i := 3; i < len(arg)-1; i += 2 {
if arg[i] != "" && data[arg[i]] == 0 {
m.Push("名目", arg[i])
m.Push("比例", "")
m.Push("金额", arg[i+1])
amount += kit.Int(arg[i+1])
amount += kit.Int64(arg[i+1])
}
}
salary += amount
@ -202,10 +215,10 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
m.Push("比例", "")
m.Push("金额", salary)
tax, amount := 0, salary
tax, amount := int64(0), salary
if data["个税方案"] == 6 {
// 2011年个税法案
month := []int{
month := []int64{
8350000, 4500,
5850000, 3500,
3850000, 3000,
@ -247,26 +260,26 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
case "计算":
case "记录":
// 收入
m.Cmd("bonus", "工资", "企业承担", arg[0], company)
m.Cmd("bonus", "工资", "基本工资", arg[0], arg[1])
for i := 2; i < len(arg)-1; i += 2 {
if arg[i] != "" {
m.Cmd("bonus", "工资", arg[i], arg[0], arg[i+1])
m.Cmd("bonus", "工资", "企业承担", company, arg[0])
m.Cmd("bonus", "工资", "基本工资", arg[1], arg[0])
for i := 3; i < len(arg)-1; i += 2 {
if arg[i] != "" && data[arg[i]] == 0 {
m.Cmd("bonus", "工资", arg[i], arg[i+1], arg[0])
}
}
// 转账
m.Cmd("trans", "工资", "公积金", "企业公积金", arg[0], -data["企业公积金金额"])
m.Cmd("trans", "工资", "公积金", -data["企业公积金金额"], arg[0])
for _, k := range []string{"企业养老保险", "企业医疗保险", "企业失业保险", "企业工伤保险", "企业生育保险"} {
m.Cmd("trans", "工资", "社保", k, arg[0], -data[k+"金额"])
m.Cmd("trans", "工资", k, -data[k+"金额"], arg[0])
}
m.Cmd("trans", "工资", "公积金", "个人公积金", arg[0], -data["公积金金额"])
m.Cmd("trans", "工资", "公积金", -data["公积金金额"], arg[0])
for _, k := range []string{"养老保险", "医疗保险", "失业保险"} {
m.Cmd("trans", "工资", "社保", k, arg[0], -data[k+"金额"])
m.Cmd("trans", "工资", k, -data[k+"金额"], arg[0])
}
// 个税
m.Cmd("trans", "工资", "个税", "工资个税", arg[0], tax)
m.Cmd("trans", "工资", "个税", tax, arg[0])
}
}},
"asset": {Name: "asset account type name value", Help: []string{"资产",
@ -415,6 +428,7 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
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])
@ -422,7 +436,7 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
data := kit.Dict(
"type", arg[2], "name", arg[3], "text", arg[4], "value", amount, "extra", extra,
)
for i := 6; i < len(arg); i += 2 {
for i := 6; i < len(arg)-1; i += 2 {
if arg[i] == "time" {
kit.Value(data, arg[i], arg[i+1])
} else {

View File

@ -11,6 +11,12 @@ import (
"time"
)
func DateZero(m *ice.Message, day time.Time) time.Time {
_, z := day.Zone()
day = day.Truncate(time.Hour * 24).Add(-time.Duration(z) * time.Second)
return day
}
func ShowDay(m *ice.Message, day time.Time) string {
if day.Day() == 1 {
if day.Month() == 1 {
@ -32,7 +38,7 @@ var Index = &ice.Context{Name: "team", Help: "团队中心",
"plan": {Name: "plan", Help: "计划", Value: kit.Data(kit.MDB_SHORT, "zone",
"head", []interface{}{"周日", "周一", "周二", "周三", "周四", "周五", "周六"},
"template", kit.Dict(
"day", `<div class="task {{.status}}" data-zone="%s" data-id="{{.id}}" data-begin_time="{{.begin_time}}">{{.name}}: {{.text}}</div>`,
"day", `<div class="task {{.status}}" data-zone="%s" data-id="{{.id}}" data-begin_time="{{.begin_time}}">{{.status}} {{.name}}: {{.text}}</div>`,
"week", `<div class="task {{.status}}" data-zone="%s" data-id="{{.id}}" data-begin_time="{{.begin_time}}" title="{{.text}}">{{.name}}</div>`,
"month", `<div class="task {{.status}}" data-zone="%s" data-id="{{.id}}" data-begin_time="{{.begin_time}}" title="{{.text}}">{{.name}}</div>`,
"year", `<div class="task {{.status}}" data-zone="%s" data-id="{{.id}}" data-begin_time="{{.begin_time}}">{{.name}}: {{.text}}</div>`,
@ -112,20 +118,22 @@ var Index = &ice.Context{Name: "team", Help: "团队中心",
})
case "process":
m.Richs(cmd, nil, kit.Select(m.Option("zone"), arg, 3), func(key string, account map[string]interface{}) {
m.Grows(cmd, kit.Keys("hash", key), "id", arg[2], func(index int, current map[string]interface{}) {
m.Grows(cmd, kit.Keys("hash", key), "id", kit.Select(m.Option("id"), arg, 2), func(index int, current map[string]interface{}) {
if kit.Format(kit.Value(current, "status")) == "prepare" {
m.Log(ice.LOG_MODIFY, "%s: %s %s: %s->%s", key, index, kit.Value(current, "status"), "status", "process")
kit.Value(current, "begin_time", m.Time())
kit.Value(current, "status", "process")
m.Echo(arg[1])
}
})
})
case "finish", "cancel":
m.Richs(cmd, nil, kit.Select(m.Option("zone"), arg, 3), func(key string, account map[string]interface{}) {
m.Grows(cmd, kit.Keys("hash", key), "id", arg[2], func(index int, current map[string]interface{}) {
m.Log(ice.LOG_MODIFY, "%s: %s %s: %s->%s", key, index, kit.Value(current, "status"), "status", arg[1])
m.Grows(cmd, kit.Keys("hash", key), "id", kit.Select(m.Option("id"), arg, 2), func(index int, current map[string]interface{}) {
m.Log(ice.LOG_MODIFY, "%s: %d %s: %s->%s", key, index, kit.Value(current, "status"), "status", arg[1])
kit.Value(current, "close_time", m.Time())
kit.Value(current, "status", arg[1])
m.Echo(arg[1])
})
})
}
@ -209,8 +217,10 @@ var Index = &ice.Context{Name: "team", Help: "团队中心",
m.Echo("%s: %d", kit.Value(value, "meta.zone"), n)
})
}},
"plan": {Name: "plan day|week|month|year", Help: "计划", Meta: kit.Dict("remote", "you", "display", "team/plan"), List: kit.List(
kit.MDB_INPUT, "select", "name", "scale", "value", "week", "values", []string{"day", "week", "month", "months", "year", "long"}, "action", "auto",
"plan": {Name: "plan day|week|month|year", Help: "计划", Meta: kit.Dict(
"remote", "you", "display", "team/plan", "detail", []string{"process", "finish", "cancel"},
), List: kit.List(
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", "end_time", "figure", "date", "action", "auto",
kit.MDB_INPUT, "button", "name", "查看", "action", "auto",
@ -222,12 +232,14 @@ var Index = &ice.Context{Name: "team", Help: "团队中心",
if len(arg) > 1 {
first = time.Unix(int64(kit.Time(arg[1])), 0)
}
first = DateZero(m, first)
// 结束日期
last := time.Now()
if len(arg) > 2 {
last = time.Unix(int64(kit.Time(arg[2])), 0)
}
last = DateZero(m, last)
switch head := kit.Simple(m.Confv(cmd, "meta.head")); arg[0] {
case "action":
@ -246,6 +258,8 @@ var Index = &ice.Context{Name: "team", Help: "团队中心",
for i := 6; i < 24; i++ {
m.Push("hour", kit.Format("%02d", i))
m.Push("task", "")
m.Push("_id", "")
m.Push("_zone", "")
}
match := first.Format("2006-01-02")
@ -256,8 +270,8 @@ var Index = &ice.Context{Name: "team", Help: "团队中心",
b, _ := kit.Render(kit.Format(template, key), value)
m.Push("hour", strings.Split(now, " ")[1][:2])
m.Push("task", string(b))
} else {
m.Info("what %v->%v %v:%v", match, now, value["name"], value["text"])
m.Push("_id", value["id"])
m.Push("_zone", key)
}
})
})
@ -330,6 +344,7 @@ var Index = &ice.Context{Name: "team", Help: "团队中心",
// 本月日期
for day := one; day.Before(end); day = day.AddDate(0, 0, 1) {
note := []string{ShowDay(m, day)}
m.Info("what %v", note)
index := day.Format("2006-01-02")
if arg[0] == "month" {
@ -353,6 +368,7 @@ var Index = &ice.Context{Name: "team", Help: "团队中心",
// 下月开头
tail := end.AddDate(0, 0, 6-int(end.Weekday())+1)
for day := end; end.Weekday() != 0 && day.Before(tail); day = day.AddDate(0, 0, 1) {
m.Info("what %v", day)
m.Push(head[int(day.Weekday())], ShowDay(m, day))
}
@ -440,7 +456,7 @@ var Index = &ice.Context{Name: "team", Help: "团队中心",
})
m.Push("zone", kit.Value(value, "meta.zone"))
for _, k := range []string{"prepare", "process", "cancel", "finish", "total"} {
for _, k := range []string{"prepare", "process", "finish", "total"} {
m.Push(k, stat[k])
}
m.Push("sum", kit.FmtTime(int64(stat["sum"])*int64(time.Second)))

View File

@ -363,6 +363,9 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心",
), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) > 0 && arg[0] == "action" {
switch arg[1] {
case "保存":
m.Cmd("nfs.save", path.Join(m.Conf(cmd, "meta.path"), kit.Select("hi.svg", arg[2])), arg[3:])
case "执行":
list := []string{"red", "green", "yellow", "cyan", "blue", "white", "black"}
switch kit.Select("", arg, 2) {
@ -373,8 +376,6 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心",
x := kit.Int(m.Option("x"))%300 + 10
m.Push("x", x)
}
case "保存":
m.Cmd("nfs.save", path.Join(m.Conf(cmd, "meta.path"), kit.Select(arg[2], "hi.svg")), arg[3:])
}
return
}