mirror of
https://shylinux.com/x/icebergs
synced 2025-04-28 18:22:02 +08:00
opt asset
This commit is contained in:
parent
250a1ab132
commit
71eeef4da3
@ -2,32 +2,69 @@ package mall
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
ice "github.com/shylinux/icebergs"
|
ice "github.com/shylinux/icebergs"
|
||||||
|
"github.com/shylinux/icebergs/base/ctx"
|
||||||
"github.com/shylinux/icebergs/base/mdb"
|
"github.com/shylinux/icebergs/base/mdb"
|
||||||
|
"github.com/shylinux/icebergs/base/web"
|
||||||
kit "github.com/shylinux/toolkits"
|
kit "github.com/shylinux/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
func _asset_create(m *ice.Message, account string) {
|
func _sub_key(m *ice.Message, account string) string {
|
||||||
if msg := m.Cmd(mdb.SELECT, ASSET, "", mdb.HASH, ACCOUNT, account); len(msg.Appendv(kit.MDB_HASH)) == 0 {
|
return kit.Keys(kit.MDB_HASH, kit.Hashs(account))
|
||||||
m.Conf(ASSET, kit.Keys(m.Option(ice.MSG_DOMAIN), kit.MDB_META, kit.MDB_SHORT), ACCOUNT)
|
}
|
||||||
m.Cmdy(mdb.INSERT, ASSET, "", mdb.HASH, ACCOUNT, account)
|
func _asset_list(m *ice.Message, account string, id string) {
|
||||||
|
if account == "" {
|
||||||
|
m.Option(mdb.FIELDS, "time,account,amount,count")
|
||||||
|
} else {
|
||||||
|
m.Option(mdb.FIELDS, kit.Select("time,id,type,amount,name,text", mdb.DETAIL, id != ""))
|
||||||
|
}
|
||||||
|
m.Cmdy(mdb.SELECT, ASSET, "", mdb.ZONE, account, id)
|
||||||
|
if id != "" {
|
||||||
|
m.PushAction(mdb.PLUGIN)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func _asset_create(m *ice.Message, account string) {
|
||||||
|
m.Cmdy(mdb.INSERT, ASSET, "", mdb.HASH, ACCOUNT, account)
|
||||||
|
}
|
||||||
func _asset_insert(m *ice.Message, account string, arg ...string) {
|
func _asset_insert(m *ice.Message, account string, arg ...string) {
|
||||||
m.Richs(ASSET, kit.Keys(kit.MDB_HASH, m.Optionv(ice.MSG_DOMAIN)), account, func(key string, value map[string]interface{}) {
|
msg := m.Cmd(mdb.SELECT, ASSET, "", mdb.HASH, ACCOUNT, account)
|
||||||
for i := 0; i < len(arg)-1; i += 2 {
|
amount := kit.Int(msg.Append(AMOUNT))
|
||||||
if arg[i] == "amount" {
|
for i := 0; i < len(arg)-1; i += 2 {
|
||||||
kit.Value(value, "meta.amount", kit.Int(kit.Value(value, "meta.amount"))+kit.Int(arg[i+1]))
|
if arg[i] == "amount" {
|
||||||
}
|
amount += kit.Int(arg[i+1])
|
||||||
}
|
}
|
||||||
id := m.Grow(ASSET, kit.Keys(kit.MDB_HASH, m.Optionv(ice.MSG_DOMAIN), kit.MDB_HASH, key), kit.Dict(
|
}
|
||||||
kit.MDB_EXTRA, kit.Dict(),
|
m.Cmdy(mdb.INSERT, ASSET, _sub_key(m, account), mdb.LIST, arg)
|
||||||
arg,
|
m.Cmdy(mdb.MODIFY, ASSET, "", mdb.HASH, ACCOUNT, account, AMOUNT, amount)
|
||||||
))
|
}
|
||||||
m.Log_INSERT(ACCOUNT, account, kit.MDB_ID, id, arg[0], arg[1])
|
func _asset_modify(m *ice.Message, account, id, field, value string, arg ...string) {
|
||||||
m.Echo("%d", id)
|
m.Cmdy(mdb.MODIFY, ASSET, _sub_key(m, account), mdb.LIST, kit.MDB_ID, id, field, value, arg)
|
||||||
})
|
}
|
||||||
|
func _asset_export(m *ice.Message, file string) {
|
||||||
|
m.Option(mdb.FIELDS, "account,id,time,type,name,text,amount,extra")
|
||||||
|
m.Cmdy(mdb.EXPORT, ASSET, "", mdb.ZONE, file)
|
||||||
|
}
|
||||||
|
func _asset_import(m *ice.Message, file string) {
|
||||||
|
m.Option(mdb.FIELDS, "account")
|
||||||
|
m.Cmdy(mdb.IMPORT, ASSET, "", mdb.ZONE, file)
|
||||||
|
}
|
||||||
|
func _asset_inputs(m *ice.Message, field, value string) {
|
||||||
|
switch field {
|
||||||
|
case "from", "to", ACCOUNT:
|
||||||
|
m.Cmdy(mdb.INPUTS, ASSET, "", mdb.HASH, ACCOUNT, value)
|
||||||
|
default:
|
||||||
|
m.Cmdy(mdb.INPUTS, ASSET, _sub_key(m, m.Option(kit.MDB_ZONE)), mdb.LIST, field, value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
ACCOUNT = "account"
|
||||||
|
AMOUNT = "amount"
|
||||||
|
|
||||||
|
SPEND = "spend"
|
||||||
|
TRANC = "tranc"
|
||||||
|
BONUS = "bonus"
|
||||||
|
)
|
||||||
const ASSET = "asset"
|
const ASSET = "asset"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -36,11 +73,30 @@ func init() {
|
|||||||
ASSET: {Name: ASSET, Help: "资产", Value: kit.Data(kit.MDB_SHORT, ACCOUNT)},
|
ASSET: {Name: ASSET, Help: "资产", Value: kit.Data(kit.MDB_SHORT, ACCOUNT)},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
ASSET: {Name: "asset account id auto insert export import", Help: "资产", Action: map[string]*ice.Action{
|
ASSET: {Name: "asset account id auto spend tranc bonus export import", Help: "资产", Action: map[string]*ice.Action{
|
||||||
mdb.INSERT: {Name: "insert account type=spend,trans,bonus amount name text", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
SPEND: {Name: "spend account amount time@date name text", 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:]...)
|
if amount := kit.Int(arg[3]); amount > 0 {
|
||||||
|
arg[3] = kit.Format(-amount)
|
||||||
|
}
|
||||||
|
_asset_insert(m, arg[1], kit.Simple(kit.MDB_TYPE, "支出", arg[2:])...)
|
||||||
}},
|
}},
|
||||||
|
TRANC: {Name: "tranc from to amount time@date text", Help: "转账", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
_asset_create(m, arg[3])
|
||||||
|
_asset_insert(m, arg[3], kit.Simple(kit.MDB_TYPE, "转入", kit.MDB_NAME, arg[1], arg[4:])...)
|
||||||
|
|
||||||
|
_asset_create(m, arg[1])
|
||||||
|
if amount := kit.Int(arg[5]); amount > 0 {
|
||||||
|
arg[5] = kit.Format(-amount)
|
||||||
|
}
|
||||||
|
_asset_insert(m, arg[1], kit.Simple(kit.MDB_TYPE, "转出", kit.MDB_NAME, arg[3], arg[4:])...)
|
||||||
|
|
||||||
|
}},
|
||||||
|
BONUS: {Name: "bonus account amount time@date name text", Help: "收入", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
_asset_create(m, arg[1])
|
||||||
|
_asset_insert(m, arg[1], kit.Simple(kit.MDB_TYPE, "收入", arg[2:])...)
|
||||||
|
}},
|
||||||
|
|
||||||
mdb.MODIFY: {Name: "modify", Help: "编辑", Hand: func(m *ice.Message, arg ...string) {
|
mdb.MODIFY: {Name: "modify", Help: "编辑", Hand: func(m *ice.Message, arg ...string) {
|
||||||
_asset_modify(m, m.Option(ACCOUNT), m.Option(kit.MDB_ID), arg[0], arg[1])
|
_asset_modify(m, m.Option(ACCOUNT), m.Option(kit.MDB_ID), arg[0], arg[1])
|
||||||
}},
|
}},
|
||||||
@ -51,7 +107,29 @@ func init() {
|
|||||||
_asset_import(m, m.Option(kit.MDB_FILE))
|
_asset_import(m, m.Option(kit.MDB_FILE))
|
||||||
}},
|
}},
|
||||||
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
||||||
_asset_inputs(m, kit.Select("", arg, 0), kit.Select("", arg, 1))
|
switch arg[0] {
|
||||||
|
case "pod", "extra.pod":
|
||||||
|
m.Cmdy(web.ROUTE)
|
||||||
|
case "ctx", "extra.ctx":
|
||||||
|
m.Cmdy(ctx.CONTEXT)
|
||||||
|
case "cmd", "extra.cmd":
|
||||||
|
m.Cmdy(ctx.CONTEXT, kit.Select(m.Option("ctx"), m.Option("extra.ctx")), ctx.COMMAND)
|
||||||
|
case "arg":
|
||||||
|
|
||||||
|
default:
|
||||||
|
_asset_inputs(m, kit.Select("", arg, 0), kit.Select("", arg, 1))
|
||||||
|
}
|
||||||
|
}},
|
||||||
|
|
||||||
|
mdb.PLUGIN: {Name: "plugin extra.pod extra.ctx extra.cmd extra.arg", Help: "插件", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
_asset_modify(m, m.Option(ACCOUNT), m.Option(kit.MDB_ID), kit.MDB_TIME, m.Time(), kit.Simple(kit.Dict(arg))...)
|
||||||
|
}},
|
||||||
|
ctx.COMMAND: {Name: "command", Help: "命令", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
if arg[0] == "run" {
|
||||||
|
m.Cmdy(arg[1], arg[2:])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
m.Cmdy(ctx.COMMAND, arg[0])
|
||||||
}},
|
}},
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
_asset_list(m, kit.Select("", arg, 0), kit.Select("", arg, 1))
|
_asset_list(m, kit.Select("", arg, 0), kit.Select("", arg, 1))
|
||||||
|
@ -4,440 +4,158 @@ import (
|
|||||||
ice "github.com/shylinux/icebergs"
|
ice "github.com/shylinux/icebergs"
|
||||||
"github.com/shylinux/icebergs/base/web"
|
"github.com/shylinux/icebergs/base/web"
|
||||||
kit "github.com/shylinux/toolkits"
|
kit "github.com/shylinux/toolkits"
|
||||||
|
|
||||||
"encoding/csv"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func _asset_list(m *ice.Message, account string, id string, field ...interface{}) {
|
const MALL = "mall"
|
||||||
fields := strings.Split(kit.Select("time,account,id,type,amount,name,text", m.Option("fields")), ",")
|
|
||||||
m.Richs(ASSET, kit.Keys(kit.MDB_HASH, m.Optionv(ice.MSG_DOMAIN)), kit.Select(kit.MDB_FOREACH, account), func(key string, val map[string]interface{}) {
|
|
||||||
if account == "" {
|
|
||||||
m.Push(key, val["meta"], []string{kit.MDB_TIME, kit.MDB_COUNT, ACCOUNT, AMOUNT})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if account = kit.Format(kit.Value(val, "meta.account")); id == "" {
|
|
||||||
m.Grows(ASSET, kit.Keys(kit.MDB_HASH, m.Optionv(ice.MSG_DOMAIN), kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
|
||||||
m.Push(account, value, fields, val["meta"])
|
|
||||||
})
|
|
||||||
m.Sort("id", "int_r")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
m.Grows(ASSET, kit.Keys(kit.MDB_HASH, m.Optionv(ice.MSG_DOMAIN), kit.MDB_HASH, key), kit.MDB_ID, id, func(index int, value map[string]interface{}) {
|
|
||||||
m.Push("detail", value)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
func _asset_modify(m *ice.Message, account, id, pro, set string) {
|
|
||||||
m.Richs(ASSET, kit.Keys(kit.MDB_HASH, m.Optionv(ice.MSG_DOMAIN)), kit.Select(kit.MDB_FOREACH, account), func(key string, val map[string]interface{}) {
|
|
||||||
m.Grows(ASSET, kit.Keys(kit.MDB_HASH, m.Optionv(ice.MSG_DOMAIN), kit.MDB_HASH, key), kit.MDB_ID, id, func(index int, value map[string]interface{}) {
|
|
||||||
switch pro {
|
|
||||||
case ACCOUNT, kit.MDB_ID, kit.MDB_TIME:
|
|
||||||
m.Info("not allow %v", key)
|
|
||||||
default:
|
|
||||||
m.Log_MODIFY(ACCOUNT, account, kit.MDB_ID, id, kit.MDB_KEY, pro, kit.MDB_VALUE, set)
|
|
||||||
kit.Value(value, pro, set)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
func _asset_export(m *ice.Message, file string) {
|
|
||||||
f, p, e := kit.Create(file)
|
|
||||||
m.Assert(e)
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
w := csv.NewWriter(f)
|
var Index = &ice.Context{Name: MALL, Help: "贸易中心",
|
||||||
defer w.Flush()
|
|
||||||
|
|
||||||
m.Assert(w.Write([]string{
|
|
||||||
ACCOUNT, kit.MDB_ID, kit.MDB_TIME,
|
|
||||||
kit.MDB_TYPE, kit.MDB_NAME, kit.MDB_TEXT,
|
|
||||||
AMOUNT, kit.MDB_EXTRA,
|
|
||||||
}))
|
|
||||||
count := 0
|
|
||||||
m.Option("cache.limit", -2)
|
|
||||||
m.Richs(ASSET, kit.Keys(kit.MDB_HASH, m.Optionv(ice.MSG_DOMAIN)), kit.MDB_FOREACH, func(key string, val map[string]interface{}) {
|
|
||||||
m.Grows(ASSET, kit.Keys(kit.MDB_HASH, m.Optionv(ice.MSG_DOMAIN), kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
|
||||||
m.Assert(w.Write(kit.Simple(
|
|
||||||
kit.Format(kit.Value(val, "meta.account")),
|
|
||||||
kit.Format(value[kit.MDB_ID]),
|
|
||||||
kit.Format(value[kit.MDB_TIME]),
|
|
||||||
kit.Format(value[kit.MDB_TYPE]),
|
|
||||||
kit.Format(value[kit.MDB_NAME]),
|
|
||||||
kit.Format(value[kit.MDB_TEXT]),
|
|
||||||
kit.Format(value[AMOUNT]),
|
|
||||||
kit.Format(value[kit.MDB_EXTRA]),
|
|
||||||
)))
|
|
||||||
count++
|
|
||||||
})
|
|
||||||
})
|
|
||||||
m.Log_EXPORT("file", p, "count", count)
|
|
||||||
m.Echo(p)
|
|
||||||
}
|
|
||||||
func _asset_import(m *ice.Message, file string) {
|
|
||||||
f, e := os.Open(file)
|
|
||||||
m.Assert(e)
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
r := csv.NewReader(f)
|
|
||||||
heads, _ := r.Read()
|
|
||||||
count := 0
|
|
||||||
for {
|
|
||||||
lines, e := r.Read()
|
|
||||||
if e != nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
account := ""
|
|
||||||
data := kit.Dict()
|
|
||||||
for i, k := range heads {
|
|
||||||
switch k {
|
|
||||||
case ACCOUNT:
|
|
||||||
account = lines[i]
|
|
||||||
case kit.MDB_ID:
|
|
||||||
continue
|
|
||||||
case kit.MDB_EXTRA:
|
|
||||||
kit.Value(data, k, kit.UnMarshal(lines[i]))
|
|
||||||
default:
|
|
||||||
kit.Value(data, k, lines[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_asset_create(m, account)
|
|
||||||
m.Richs(ASSET, kit.Keys(kit.MDB_HASH, m.Optionv(ice.MSG_DOMAIN)), account, func(key string, value map[string]interface{}) {
|
|
||||||
kit.Value(value, "meta.amount", kit.Int(kit.Value(value, "meta.amount"))+kit.Int(data[AMOUNT]))
|
|
||||||
|
|
||||||
id := m.Grow(ASSET, kit.Keys(kit.MDB_HASH, m.Optionv(ice.MSG_DOMAIN), kit.MDB_HASH, key), data)
|
|
||||||
m.Log_INSERT(ACCOUNT, account, kit.MDB_ID, id)
|
|
||||||
count++
|
|
||||||
})
|
|
||||||
}
|
|
||||||
m.Log_IMPORT("file", file, "count", count)
|
|
||||||
m.Echo(file)
|
|
||||||
}
|
|
||||||
func _asset_inputs(m *ice.Message, key, value string) {
|
|
||||||
switch key {
|
|
||||||
case ACCOUNT:
|
|
||||||
m.Richs(ASSET, kit.Keys(kit.MDB_HASH, m.Optionv(ice.MSG_DOMAIN)), kit.MDB_FOREACH, func(key string, val map[string]interface{}) {
|
|
||||||
m.Push("account", kit.Value(val, "meta.account"))
|
|
||||||
m.Push("count", kit.Select("0", kit.Format(kit.Value(val, "meta.count"))))
|
|
||||||
})
|
|
||||||
|
|
||||||
case "name", "text":
|
|
||||||
list := map[string]int{}
|
|
||||||
m.Option("cache.limit", 10)
|
|
||||||
m.Richs(ASSET, kit.Keys(kit.MDB_HASH, m.Optionv(ice.MSG_DOMAIN)), kit.MDB_FOREACH, func(k string, val map[string]interface{}) {
|
|
||||||
m.Grows(ASSET, kit.Keys(kit.MDB_HASH, m.Optionv(ice.MSG_DOMAIN), kit.MDB_HASH, k), "", "", func(index int, value map[string]interface{}) {
|
|
||||||
list[kit.Format(value[key])]++
|
|
||||||
})
|
|
||||||
})
|
|
||||||
for k, i := range list {
|
|
||||||
m.Push("key", k)
|
|
||||||
m.Push("count", i)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m.Sort("count", "int_r")
|
|
||||||
}
|
|
||||||
|
|
||||||
func _asset_search(m *ice.Message, kind, name, text string, arg ...string) {
|
|
||||||
m.Richs(ASSET, kit.Keys(kit.MDB_HASH, m.Optionv(ice.MSG_DOMAIN)), kit.MDB_FOREACH, func(key string, val map[string]interface{}) {
|
|
||||||
m.Grows(ASSET, kit.Keys(kit.MDB_HASH, m.Optionv(ice.MSG_DOMAIN), kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
|
||||||
if value[kit.MDB_NAME] == name || strings.Contains(kit.Format(value[kit.MDB_TEXT]), name) {
|
|
||||||
m.Push("pod", m.Option(ice.MSG_USERPOD))
|
|
||||||
m.Push("ctx", m.Prefix())
|
|
||||||
m.Push("cmd", ASSET)
|
|
||||||
m.Push("time", value[kit.MDB_TIME])
|
|
||||||
m.Push("size", 1)
|
|
||||||
m.Push("type", ASSET)
|
|
||||||
m.Push("name", value[kit.MDB_NAME])
|
|
||||||
m.Push("text", kit.Format("%s:%d", kit.Value(val, "meta.zone"), kit.Int(value[kit.MDB_ID])))
|
|
||||||
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
func _asset_render(m *ice.Message, kind, name, text string, arg ...string) {
|
|
||||||
ls := strings.Split(text, ":")
|
|
||||||
m.Richs(ASSET, kit.Keys(kit.MDB_HASH, m.Optionv(ice.MSG_DOMAIN)), ls[0], func(key string, val map[string]interface{}) {
|
|
||||||
m.Grows(ASSET, kit.Keys(kit.MDB_HASH, m.Optionv(ice.MSG_DOMAIN), kit.MDB_HASH, key), "id", ls[1], func(index int, value map[string]interface{}) {
|
|
||||||
m.Push("detail", value)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
func _asset_action(m *ice.Message, status interface{}, action ...string) string {
|
|
||||||
return strings.Join(action, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
var _input_spend = kit.List(
|
|
||||||
"_input", "text", "name", "account", "value", "@key",
|
|
||||||
"_input", "select", "name", "type", "values", []interface{}{
|
|
||||||
"支出", "转账", "收入",
|
|
||||||
},
|
|
||||||
"_input", "text", "name", "amount",
|
|
||||||
"_input", "text", "name", "name", "value", "@key",
|
|
||||||
"_input", "text", "name", "text", "value", "@key",
|
|
||||||
)
|
|
||||||
var _input_trans = kit.List(
|
|
||||||
"_input", "text", "name", "account", "value", "@key",
|
|
||||||
"_input", "select", "name", "type", "values", []interface{}{
|
|
||||||
"转账", "支出", "收入",
|
|
||||||
},
|
|
||||||
"_input", "text", "name", "amount",
|
|
||||||
"_input", "text", "name", "name", "value", "@key",
|
|
||||||
"_input", "text", "name", "text", "value", "@key",
|
|
||||||
)
|
|
||||||
var _input_bonus = kit.List(
|
|
||||||
"_input", "text", "name", "account", "value", "@key",
|
|
||||||
"_input", "select", "name", "type", "values", []interface{}{
|
|
||||||
"收入", "转账", "支出",
|
|
||||||
},
|
|
||||||
"_input", "text", "name", "amount",
|
|
||||||
"_input", "text", "name", "name", "value", "@key",
|
|
||||||
"_input", "text", "name", "text", "value", "@key",
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
BONUS = "bonus"
|
|
||||||
SPEND = "spend"
|
|
||||||
)
|
|
||||||
const (
|
|
||||||
AMOUNT = "amount"
|
|
||||||
ACCOUNT = "account"
|
|
||||||
EXPORT = "usr/export/web.mall.asset/"
|
|
||||||
)
|
|
||||||
|
|
||||||
var Index = &ice.Context{Name: "mall", Help: "贸易中心",
|
|
||||||
Caches: map[string]*ice.Cache{},
|
|
||||||
Configs: map[string]*ice.Config{},
|
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Load() }},
|
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Load() }},
|
||||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save() }},
|
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save() }},
|
||||||
|
|
||||||
"spend": {Name: "spend account=@key to=@key name=@key 记录:button text:textarea value=@key time=@date",
|
"month": {Name: "month month value value 计算:button 记录:button", Help: "工资", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
Help: "支出", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
|
||||||
if input(m, arg...) {
|
data := map[string]int64{"个税方案": 6, "基本工资": 0, "个税": 0,
|
||||||
// 输入补全
|
"公积金比例": 1200, "养老保险比例": 800, "医疗保险比例": 200, "失业保险比例": 20, "工伤保险比例": 2, "生育保险比例": 0,
|
||||||
return
|
"公积金金额": 0, "养老保险金额": 0, "医疗保险金额": 0, "失业保险金额": 0, "工伤保险金额": 0, "生育保险金额": 0,
|
||||||
|
|
||||||
|
"企业公积金比例": 1200, "企业养老保险比例": 2000, "企业医疗保险比例": 1000, "企业失业保险比例": 100, "企业工伤保险比例": 30, "企业生育保险比例": 80,
|
||||||
|
"企业公积金金额": 0, "企业养老保险金额": 0, "企业医疗保险金额": 0, "企业失业保险金额": 0, "企业工伤保险金额": 0, "企业生育保险金额": 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 3; i < len(arg)-1; i += 2 {
|
||||||
|
if _, ok := data[arg[i]]; ok {
|
||||||
|
data[arg[i]] = kit.Int64(arg[i+1])
|
||||||
|
arg[i] = ""
|
||||||
}
|
}
|
||||||
if len(arg) < 2 {
|
}
|
||||||
// 查看流水
|
|
||||||
m.Cmdy("asset", arg)
|
data["养老保险比例"] = 725
|
||||||
return
|
data["失业保险比例"] = 18
|
||||||
|
|
||||||
|
salary := kit.Int64(arg[1])
|
||||||
|
data["个税"] = kit.Int64(arg[2])
|
||||||
|
base := data["基本工资"]
|
||||||
|
if base == 0 {
|
||||||
|
base = salary
|
||||||
|
}
|
||||||
|
|
||||||
|
// 五险一金
|
||||||
|
amount := int64(0)
|
||||||
|
for _, k := range []string{"公积金", "养老保险", "医疗保险", "失业保险", "工伤保险"} {
|
||||||
|
m.Push("名目", k)
|
||||||
|
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+"金额"]
|
||||||
}
|
}
|
||||||
// 添加流水
|
amount += value
|
||||||
amount := kit.Int(arg[4])
|
m.Push("金额", data[k+"金额"])
|
||||||
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[2], arg[3], -amount, "time", arg[5:])
|
// 企业五险一金
|
||||||
m.Cmdy("asset", "流水", "", "支出", arg[2], arg[3], -amount, "time", arg[5:])
|
company := int64(0)
|
||||||
}},
|
for _, k := range []string{"企业公积金", "企业养老保险", "企业医疗保险", "企业失业保险", "企业工伤保险", "企业生育保险"} {
|
||||||
"trans": {Name: "trans account=@key to=@key name=@key 记录:button text:textarea value=@key time=@date",
|
m.Push("名目", k)
|
||||||
Help: "转账", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
value := -base * kit.Int64(data[k+"比例"]) / 10000
|
||||||
if input(m, arg...) {
|
if m.Push("比例", data[k+"比例"]); data[k+"金额"] == 0 {
|
||||||
// 输入补全
|
data[k+"金额"] = value
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if len(arg) < 2 {
|
company += -value
|
||||||
// 查看流水
|
m.Push("金额", data[k+"金额"])
|
||||||
m.Cmdy("asset", arg)
|
}
|
||||||
return
|
m.Push("名目", "企业承担")
|
||||||
|
m.Push("比例", "")
|
||||||
|
m.Push("金额", company)
|
||||||
|
|
||||||
|
// 其它津贴
|
||||||
|
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.Int64(arg[i+1])
|
||||||
}
|
}
|
||||||
// 添加流水
|
}
|
||||||
amount := kit.Int(arg[4])
|
salary += amount
|
||||||
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.Push("名目", "税前收入")
|
||||||
m.Cmd("asset", "流水", "", "转出", arg[2], arg[3], -amount, "time", arg[5:])
|
m.Push("比例", "")
|
||||||
m.Cmd("asset", "流水", "", "转入", arg[2], arg[3], amount, "time", arg[5:])
|
m.Push("金额", salary)
|
||||||
}},
|
|
||||||
"bonus": {Name: "bonus account=@key name=@key value=@key 记录:button text:textarea time=@date",
|
tax, amount := int64(0), salary
|
||||||
Help: "收入", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
if data["个税方案"] == 6 {
|
||||||
if input(m, arg...) {
|
// 2011年个税法案
|
||||||
// 输入补全
|
month := []int64{
|
||||||
return
|
8350000, 4500,
|
||||||
}
|
5850000, 3500,
|
||||||
if len(arg) < 2 {
|
3850000, 3000,
|
||||||
// 查看流水
|
1250000, 2500,
|
||||||
m.Cmdy("asset", arg)
|
800000, 2000,
|
||||||
return
|
500000, 1000,
|
||||||
}
|
350000, 300,
|
||||||
// 添加流水
|
|
||||||
amount := kit.Int(arg[2])
|
|
||||||
m.Cmdy("asset", arg[0], "", "收入", arg[1], arg[3], amount, "time", arg[4:])
|
|
||||||
m.Cmdy("asset", "流水", "", "收入", arg[1], arg[3], amount, "time", arg[4:])
|
|
||||||
}},
|
|
||||||
"month": {Name: "month month value value 计算:button 记录:button",
|
|
||||||
Help: "工资", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
|
||||||
// 输入补全
|
|
||||||
if input(m, arg...) {
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data := map[string]int64{"个税方案": 6, "基本工资": 0, "个税": 0,
|
for i := 0; i < len(month); i += 2 {
|
||||||
"公积金比例": 1200, "养老保险比例": 800, "医疗保险比例": 200, "失业保险比例": 20, "工伤保险比例": 2, "生育保险比例": 0,
|
if amount > month[i] {
|
||||||
"公积金金额": 0, "养老保险金额": 0, "医疗保险金额": 0, "失业保险金额": 0, "工伤保险金额": 0, "生育保险金额": 0,
|
tax, amount = tax+(amount-month[i])*month[i+1]/10000, month[i]
|
||||||
|
|
||||||
"企业公积金比例": 1200, "企业养老保险比例": 2000, "企业医疗保险比例": 1000, "企业失业保险比例": 100, "企业工伤保险比例": 30, "企业生育保险比例": 80,
|
|
||||||
"企业公积金金额": 0, "企业养老保险金额": 0, "企业医疗保险金额": 0, "企业失业保险金额": 0, "企业工伤保险金额": 0, "企业生育保险金额": 0,
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 3; i < len(arg)-1; i += 2 {
|
|
||||||
if _, ok := data[arg[i]]; ok {
|
|
||||||
data[arg[i]] = kit.Int64(arg[i+1])
|
|
||||||
arg[i] = ""
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if data["个税"] != 0 {
|
||||||
data["养老保险比例"] = 725
|
tax = data["个税"]
|
||||||
data["失业保险比例"] = 18
|
|
||||||
|
|
||||||
salary := kit.Int64(arg[1])
|
|
||||||
data["个税"] = kit.Int64(arg[2])
|
|
||||||
base := data["基本工资"]
|
|
||||||
if base == 0 {
|
|
||||||
base = salary
|
|
||||||
}
|
}
|
||||||
|
m.Push("名目", "个税")
|
||||||
// 五险一金
|
|
||||||
amount := int64(0)
|
|
||||||
for _, k := range []string{"公积金", "养老保险", "医疗保险", "失业保险", "工伤保险"} {
|
|
||||||
m.Push("名目", k)
|
|
||||||
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+"金额"]
|
|
||||||
}
|
|
||||||
amount += value
|
|
||||||
m.Push("金额", data[k+"金额"])
|
|
||||||
}
|
|
||||||
|
|
||||||
// 企业五险一金
|
|
||||||
company := int64(0)
|
|
||||||
for _, k := range []string{"企业公积金", "企业养老保险", "企业医疗保险", "企业失业保险", "企业工伤保险", "企业生育保险"} {
|
|
||||||
m.Push("名目", k)
|
|
||||||
value := -base * kit.Int64(data[k+"比例"]) / 10000
|
|
||||||
if m.Push("比例", data[k+"比例"]); data[k+"金额"] == 0 {
|
|
||||||
data[k+"金额"] = value
|
|
||||||
}
|
|
||||||
company += -value
|
|
||||||
m.Push("金额", data[k+"金额"])
|
|
||||||
}
|
|
||||||
m.Push("名目", "企业承担")
|
|
||||||
m.Push("比例", "")
|
m.Push("比例", "")
|
||||||
m.Push("金额", company)
|
m.Push("金额", tax)
|
||||||
|
|
||||||
// 其它津贴
|
m.Push("名目", "税后收入")
|
||||||
|
m.Push("比例", "")
|
||||||
|
m.Push("金额", salary-tax)
|
||||||
|
} else {
|
||||||
|
// 2019年个税法案
|
||||||
|
// year := []int{
|
||||||
|
// 96000000, 4500,
|
||||||
|
// 66000000, 3500,
|
||||||
|
// 42000000, 3000,
|
||||||
|
// 30000000, 2500,
|
||||||
|
// 14400000, 2000,
|
||||||
|
// 3600000, 1000,
|
||||||
|
// 0, 300,
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
switch m.Option("_action") {
|
||||||
|
case "计算":
|
||||||
|
case "记录":
|
||||||
|
// 收入
|
||||||
|
m.Cmd("bonus", "工资", "企业承担", company, arg[0])
|
||||||
|
m.Cmd("bonus", "工资", "基本工资", arg[1], arg[0])
|
||||||
for i := 3; i < len(arg)-1; i += 2 {
|
for i := 3; i < len(arg)-1; i += 2 {
|
||||||
if arg[i] != "" && data[arg[i]] == 0 {
|
if arg[i] != "" && data[arg[i]] == 0 {
|
||||||
m.Push("名目", arg[i])
|
m.Cmd("bonus", "工资", arg[i], arg[i+1], arg[0])
|
||||||
m.Push("比例", "")
|
|
||||||
m.Push("金额", arg[i+1])
|
|
||||||
amount += kit.Int64(arg[i+1])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
salary += amount
|
|
||||||
|
|
||||||
m.Push("名目", "税前收入")
|
// 转账
|
||||||
m.Push("比例", "")
|
m.Cmd("trans", "工资", "公积金", -data["企业公积金金额"], arg[0])
|
||||||
m.Push("金额", salary)
|
for _, k := range []string{"企业养老保险", "企业医疗保险", "企业失业保险", "企业工伤保险", "企业生育保险"} {
|
||||||
|
m.Cmd("trans", "工资", k, -data[k+"金额"], arg[0])
|
||||||
tax, amount := int64(0), salary
|
}
|
||||||
if data["个税方案"] == 6 {
|
m.Cmd("trans", "工资", "公积金", -data["公积金金额"], arg[0])
|
||||||
// 2011年个税法案
|
for _, k := range []string{"养老保险", "医疗保险", "失业保险"} {
|
||||||
month := []int64{
|
m.Cmd("trans", "工资", k, -data[k+"金额"], arg[0])
|
||||||
8350000, 4500,
|
|
||||||
5850000, 3500,
|
|
||||||
3850000, 3000,
|
|
||||||
1250000, 2500,
|
|
||||||
800000, 2000,
|
|
||||||
500000, 1000,
|
|
||||||
350000, 300,
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < len(month); i += 2 {
|
|
||||||
if amount > month[i] {
|
|
||||||
tax, amount = tax+(amount-month[i])*month[i+1]/10000, month[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if data["个税"] != 0 {
|
|
||||||
tax = data["个税"]
|
|
||||||
}
|
|
||||||
m.Push("名目", "个税")
|
|
||||||
m.Push("比例", "")
|
|
||||||
m.Push("金额", tax)
|
|
||||||
|
|
||||||
m.Push("名目", "税后收入")
|
|
||||||
m.Push("比例", "")
|
|
||||||
m.Push("金额", salary-tax)
|
|
||||||
} else {
|
|
||||||
// 2019年个税法案
|
|
||||||
// year := []int{
|
|
||||||
// 96000000, 4500,
|
|
||||||
// 66000000, 3500,
|
|
||||||
// 42000000, 3000,
|
|
||||||
// 30000000, 2500,
|
|
||||||
// 14400000, 2000,
|
|
||||||
// 3600000, 1000,
|
|
||||||
// 0, 300,
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch m.Option("_action") {
|
// 个税
|
||||||
case "计算":
|
m.Cmd("trans", "工资", "个税", tax, arg[0])
|
||||||
case "记录":
|
}
|
||||||
// 收入
|
}},
|
||||||
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", "工资", "公积金", -data["企业公积金金额"], arg[0])
|
|
||||||
for _, k := range []string{"企业养老保险", "企业医疗保险", "企业失业保险", "企业工伤保险", "企业生育保险"} {
|
|
||||||
m.Cmd("trans", "工资", k, -data[k+"金额"], arg[0])
|
|
||||||
}
|
|
||||||
m.Cmd("trans", "工资", "公积金", -data["公积金金额"], arg[0])
|
|
||||||
for _, k := range []string{"养老保险", "医疗保险", "失业保险"} {
|
|
||||||
m.Cmd("trans", "工资", k, -data[k+"金额"], arg[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
// 个税
|
|
||||||
m.Cmd("trans", "工资", "个税", tax, arg[0])
|
|
||||||
}
|
|
||||||
}},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { web.Index.Register(Index, &web.Frame{}) }
|
func init() { web.Index.Register(Index, &web.Frame{}, ASSET) }
|
||||||
func input(m *ice.Message, arg ...string) bool {
|
|
||||||
if len(arg) > 0 && arg[0] == "action" {
|
|
||||||
switch arg[1] {
|
|
||||||
case "input":
|
|
||||||
switch arg[2] {
|
|
||||||
case "account", "to":
|
|
||||||
m.Richs("asset", nil, "*", func(key string, value map[string]interface{}) {
|
|
||||||
m.Push(arg[2], kit.Value(value, "meta.account"))
|
|
||||||
m.Push("count", kit.Value(value, "meta.count"))
|
|
||||||
})
|
|
||||||
m.Sort("count", "int_r")
|
|
||||||
return true
|
|
||||||
case "type", "name", "text", "value":
|
|
||||||
m.Confm("asset", kit.Keys("meta.word", arg[2]), func(key string, value string) {
|
|
||||||
m.Push(arg[2], key)
|
|
||||||
m.Push("count", value)
|
|
||||||
})
|
|
||||||
m.Sort("count", "int_r")
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
@ -37,12 +37,12 @@ func init() {
|
|||||||
}},
|
}},
|
||||||
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
||||||
switch arg[0] {
|
switch arg[0] {
|
||||||
|
case "pod", "extra.pod":
|
||||||
|
m.Cmdy(web.ROUTE)
|
||||||
case "ctx", "extra.ctx":
|
case "ctx", "extra.ctx":
|
||||||
m.Cmdy(ctx.CONTEXT)
|
m.Cmdy(ctx.CONTEXT)
|
||||||
case "cmd", "extra.cmd":
|
case "cmd", "extra.cmd":
|
||||||
m.Cmdy(ctx.CONTEXT, kit.Select(m.Option("ctx"), m.Option("extra.ctx")), ctx.COMMAND)
|
m.Cmdy(ctx.CONTEXT, kit.Select(m.Option("ctx"), m.Option("extra.ctx")), ctx.COMMAND)
|
||||||
case "pod":
|
|
||||||
m.Cmdy(web.ROUTE)
|
|
||||||
case "arg":
|
case "arg":
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -13,7 +13,37 @@ import (
|
|||||||
func _sub_key(m *ice.Message, zone string) string {
|
func _sub_key(m *ice.Message, zone string) string {
|
||||||
return kit.Keys(kit.MDB_HASH, kit.Hashs(zone))
|
return kit.Keys(kit.MDB_HASH, kit.Hashs(zone))
|
||||||
}
|
}
|
||||||
|
func _task_scope(m *ice.Message, tz int, arg ...string) (time.Time, time.Time) {
|
||||||
|
begin_time := time.Now()
|
||||||
|
if len(arg) > 1 {
|
||||||
|
begin_time, _ = time.ParseInLocation(ice.MOD_TIME, arg[1], time.Local)
|
||||||
|
}
|
||||||
|
|
||||||
|
begin_time = begin_time.Add(time.Duration(tz) * time.Hour)
|
||||||
|
begin_time = begin_time.Add(-time.Duration(begin_time.UnixNano()) % (24 * time.Hour))
|
||||||
|
begin_time = begin_time.Add(-time.Duration(tz) * time.Hour)
|
||||||
|
|
||||||
|
end_time := begin_time
|
||||||
|
switch arg[0] {
|
||||||
|
case TaskScale.DAY:
|
||||||
|
end_time = begin_time.AddDate(0, 0, 1)
|
||||||
|
case TaskScale.WEEK:
|
||||||
|
begin_time = begin_time.AddDate(0, 0, -int(begin_time.Weekday()))
|
||||||
|
end_time = begin_time.AddDate(0, 0, 7)
|
||||||
|
case TaskScale.MONTH:
|
||||||
|
begin_time = begin_time.AddDate(0, 0, -begin_time.Day()+1)
|
||||||
|
end_time = begin_time.AddDate(0, 1, 0)
|
||||||
|
case TaskScale.YEAR:
|
||||||
|
begin_time = begin_time.AddDate(0, 0, -begin_time.YearDay()+1)
|
||||||
|
end_time = begin_time.AddDate(1, 0, 0)
|
||||||
|
case TaskScale.LONG:
|
||||||
|
begin_time = begin_time.AddDate(0, 0, -begin_time.YearDay()+1)
|
||||||
|
begin_time = begin_time.AddDate(-5, 0, 0)
|
||||||
|
end_time = begin_time.AddDate(10, 0, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
return begin_time, end_time
|
||||||
|
}
|
||||||
func _task_action(m *ice.Message, status interface{}, action ...string) string {
|
func _task_action(m *ice.Message, status interface{}, action ...string) string {
|
||||||
switch status {
|
switch status {
|
||||||
case TaskStatus.PREPARE:
|
case TaskStatus.PREPARE:
|
||||||
@ -25,6 +55,7 @@ func _task_action(m *ice.Message, status interface{}, action ...string) string {
|
|||||||
}
|
}
|
||||||
return strings.Join(action, ",")
|
return strings.Join(action, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
func _task_list(m *ice.Message, zone string, id string) {
|
func _task_list(m *ice.Message, zone string, id string) {
|
||||||
if zone == "" {
|
if zone == "" {
|
||||||
m.Option(mdb.FIELDS, "time,zone,count")
|
m.Option(mdb.FIELDS, "time,zone,count")
|
||||||
@ -37,10 +68,7 @@ func _task_list(m *ice.Message, zone string, id string) {
|
|||||||
m.Cmdy(mdb.SELECT, TASK, "", mdb.ZONE, zone, id)
|
m.Cmdy(mdb.SELECT, TASK, "", mdb.ZONE, zone, id)
|
||||||
}
|
}
|
||||||
func _task_create(m *ice.Message, zone string) {
|
func _task_create(m *ice.Message, zone string) {
|
||||||
if msg := m.Cmd(mdb.SELECT, TASK, "", mdb.HASH, kit.MDB_ZONE, zone); len(msg.Appendv(kit.MDB_HASH)) == 0 {
|
m.Cmdy(mdb.INSERT, TASK, "", mdb.HASH, kit.MDB_ZONE, zone)
|
||||||
m.Conf(TASK, kit.Keys(m.Option(ice.MSG_DOMAIN), kit.MDB_META, kit.MDB_SHORT), kit.MDB_ZONE)
|
|
||||||
m.Cmdy(mdb.INSERT, TASK, "", mdb.HASH, kit.MDB_ZONE, zone)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
func _task_insert(m *ice.Message, zone string, arg ...string) {
|
func _task_insert(m *ice.Message, zone string, arg ...string) {
|
||||||
m.Cmdy(mdb.INSERT, TASK, _sub_key(m, zone), mdb.LIST,
|
m.Cmdy(mdb.INSERT, TASK, _sub_key(m, zone), mdb.LIST,
|
||||||
@ -80,38 +108,6 @@ func _task_inputs(m *ice.Message, field, value string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func _task_scope(m *ice.Message, tz int, arg ...string) (time.Time, time.Time) {
|
|
||||||
begin_time := time.Now()
|
|
||||||
if len(arg) > 1 {
|
|
||||||
begin_time, _ = time.ParseInLocation(ice.MOD_TIME, arg[1], time.Local)
|
|
||||||
}
|
|
||||||
|
|
||||||
begin_time = begin_time.Add(time.Duration(tz) * time.Hour)
|
|
||||||
begin_time = begin_time.Add(-time.Duration(begin_time.UnixNano()) % (24 * time.Hour))
|
|
||||||
begin_time = begin_time.Add(-time.Duration(tz) * time.Hour)
|
|
||||||
|
|
||||||
end_time := begin_time
|
|
||||||
switch arg[0] {
|
|
||||||
case TaskScale.DAY:
|
|
||||||
end_time = begin_time.AddDate(0, 0, 1)
|
|
||||||
case TaskScale.WEEK:
|
|
||||||
begin_time = begin_time.AddDate(0, 0, -int(begin_time.Weekday()))
|
|
||||||
end_time = begin_time.AddDate(0, 0, 7)
|
|
||||||
case TaskScale.MONTH:
|
|
||||||
begin_time = begin_time.AddDate(0, 0, -begin_time.Day()+1)
|
|
||||||
end_time = begin_time.AddDate(0, 1, 0)
|
|
||||||
case TaskScale.YEAR:
|
|
||||||
begin_time = begin_time.AddDate(0, 0, -begin_time.YearDay()+1)
|
|
||||||
end_time = begin_time.AddDate(1, 0, 0)
|
|
||||||
case TaskScale.LONG:
|
|
||||||
begin_time = begin_time.AddDate(0, 0, -begin_time.YearDay()+1)
|
|
||||||
begin_time = begin_time.AddDate(-5, 0, 0)
|
|
||||||
end_time = begin_time.AddDate(10, 0, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
return begin_time, end_time
|
|
||||||
}
|
|
||||||
|
|
||||||
var TaskField = struct{ LEVEL, STATUS, SCORE, BEGIN_TIME, CLOSE_TIME string }{
|
var TaskField = struct{ LEVEL, STATUS, SCORE, BEGIN_TIME, CLOSE_TIME string }{
|
||||||
LEVEL: "level",
|
LEVEL: "level",
|
||||||
STATUS: "status",
|
STATUS: "status",
|
||||||
|
13
meta.go
13
meta.go
@ -99,12 +99,19 @@ func (m *Message) Push(key string, value interface{}, arg ...interface{}) *Messa
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 追加数据
|
// 追加数据
|
||||||
switch v := kit.Format(v); key {
|
switch vv := kit.Format(v); key {
|
||||||
case "detail":
|
case "detail":
|
||||||
|
if k == "extra" {
|
||||||
|
for k, v := range kit.KeyValue(map[string]interface{}{}, "", kit.UnMarshal(vv)) {
|
||||||
|
m.Add(MSG_APPEND, kit.MDB_KEY, "extra."+k)
|
||||||
|
m.Add(MSG_APPEND, kit.MDB_VALUE, kit.Format(v))
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
m.Add(MSG_APPEND, kit.MDB_KEY, k)
|
m.Add(MSG_APPEND, kit.MDB_KEY, k)
|
||||||
m.Add(MSG_APPEND, kit.MDB_VALUE, v)
|
m.Add(MSG_APPEND, kit.MDB_VALUE, vv)
|
||||||
default:
|
default:
|
||||||
m.Add(MSG_APPEND, k, v)
|
m.Add(MSG_APPEND, k, vv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
5
misc.go
5
misc.go
@ -96,11 +96,6 @@ func (m *Message) PushButton(arg ...string) {
|
|||||||
m.PushRender("action", "button", strings.Join(arg, ","))
|
m.PushRender("action", "button", strings.Join(arg, ","))
|
||||||
}
|
}
|
||||||
func (m *Message) PushAction(list ...interface{}) {
|
func (m *Message) PushAction(list ...interface{}) {
|
||||||
if len(m.meta[MSG_APPEND]) > 0 && m.meta[MSG_APPEND][0] == kit.MDB_KEY {
|
|
||||||
m.Push(kit.MDB_KEY, kit.MDB_ACTION)
|
|
||||||
m.PushRender(kit.MDB_VALUE, kit.MDB_BUTTON, strings.Join(kit.Simple(list...), ","))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
m.Table(func(index int, value map[string]string, head []string) {
|
m.Table(func(index int, value map[string]string, head []string) {
|
||||||
m.PushRender(kit.MDB_ACTION, kit.MDB_BUTTON, strings.Join(kit.Simple(list...), ","))
|
m.PushRender(kit.MDB_ACTION, kit.MDB_BUTTON, strings.Join(kit.Simple(list...), ","))
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user