forked from x/icebergs
add loan.go
This commit is contained in:
parent
96d30d7beb
commit
6a6939fa6c
@ -28,7 +28,7 @@ func _serve_start(m *ice.Message) {
|
||||
kit.If(m.Option(aaa.USERNAME), func() { aaa.UserRoot(m, m.Option(aaa.USERNICK), m.Option(aaa.USERNAME)) })
|
||||
kit.If(m.Option(tcp.PORT) == tcp.RANDOM, func() { m.Option(tcp.PORT, m.Cmdx(tcp.PORT, aaa.RIGHT)) })
|
||||
kit.If(runtime.GOOS == cli.WINDOWS || m.Cmdx(cli.SYSTEM, "lsof", "-i", ":"+m.Option(tcp.PORT)) != "", func() {
|
||||
m.Go(func() { m.Cmd(SPIDE, ice.OPS, _serve_address(m)+"/exit", ice.Maps{CLIENT_TIMEOUT: "30ms"}) }).Sleep30ms()
|
||||
m.Go(func() { m.Cmd(SPIDE, ice.OPS, _serve_address(m)+"/exit", ice.Maps{CLIENT_TIMEOUT: "300ms"}) }).Sleep300ms()
|
||||
})
|
||||
cli.NodeInfo(m, kit.Select(ice.Info.Hostname, m.Option(tcp.NODENAME)), SERVER)
|
||||
m.Start("", m.OptionSimple(tcp.HOST, tcp.PORT)...)
|
||||
|
1
conf.go
1
conf.go
@ -117,6 +117,7 @@ const ( // DIR
|
||||
SHARE_LOCAL = "/share/local/"
|
||||
|
||||
ISH_PLUGED = ".ish/pluged/"
|
||||
USR_PACKAGE = "usr/package.json"
|
||||
USR_MODULES = "usr/node_modules/"
|
||||
USR_GEOAREA = "usr/geoarea/"
|
||||
USR_RELEASE = "usr/release/"
|
||||
|
@ -20,7 +20,7 @@ func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
APPLICATIONS: {Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
FinderAppend(m, APPLICATIONS, m.PrefixKey())
|
||||
FinderAppend(m, "", m.PrefixKey())
|
||||
defer Notify(m, "Infomation.png", cli.RUNTIME, "系统启动成功", ctx.INDEX, cli.RUNTIME)
|
||||
m.Travel(func(p *ice.Context, c *ice.Context, key string, cmd *ice.Command) {
|
||||
kit.If(cmd.Icon, func() {
|
||||
@ -42,8 +42,13 @@ func init() {
|
||||
})
|
||||
}
|
||||
func install(m *ice.Message, cmd, icon, index string, arg ...string) {
|
||||
name := kit.TrimExt(path.Base(icon), nfs.PNG, nfs.JPG)
|
||||
name := kit.TrimExt(path.Base(icon), nfs.PNG, nfs.JPG, nfs.JPEG)
|
||||
if icon != "" {
|
||||
nfs.Exists(m, ice.USR_ICONS+icon, func(p string) { icon = p })
|
||||
if m.Warn(!strings.HasPrefix(icon, web.HTTP) && !nfs.Exists(m, icon)) {
|
||||
return
|
||||
}
|
||||
}
|
||||
m.Cmd(Prefix(cmd), mdb.CREATE, mdb.NAME, name, mdb.ICON, icon, ctx.INDEX, index, arg)
|
||||
}
|
||||
func AppInstall(m *ice.Message, icon, index string, arg ...string) {
|
||||
|
@ -3,6 +3,7 @@ Volcanos(chat.ONIMPORT, {
|
||||
var item = can.onimport.item(can, value, function(event) { if (can.onmotion.cache(can, function() { return value.name }, can.ui.content)) { return }
|
||||
can.runActionCommand(event, value.index, [], function(msg) {
|
||||
switch (value.name) {
|
||||
case ".":
|
||||
case "applications": can.onimport.icons(can, msg, can.ui.content); break
|
||||
default: can.onappend.table(can, msg, null, can.ui.content)
|
||||
} can.onimport.layout(can)
|
||||
|
@ -62,7 +62,14 @@ func init() {
|
||||
ice.REQUIRE_USR: {Hand: func(m *ice.Message, arg ...string) { web.ShareLocalFile(m, ice.USR, path.Join(arg...)) }},
|
||||
ice.REQUIRE_MODULES: {Hand: func(m *ice.Message, arg ...string) {
|
||||
p := path.Join(ice.USR_MODULES, path.Join(arg...))
|
||||
kit.If(!nfs.Exists(m, p), func() { m.Cmd(cli.SYSTEM, "npm", INSTALL, arg[0], kit.Dict(cli.CMD_DIR, ice.USR)) })
|
||||
kit.If(!nfs.Exists(m, p), func() {
|
||||
if kit.IsIn(m.Option(ice.MSG_USERROLE), aaa.TECH, aaa.ROOT) {
|
||||
kit.If(!nfs.Exists(m, ice.USR_PACKAGE), func() {
|
||||
m.Cmd(nfs.SAVE, ice.USR_PACKAGE, kit.Formats(kit.Dict(mdb.NAME, "usr", nfs.VERSION, "0.0.1")))
|
||||
})
|
||||
m.Cmd(cli.SYSTEM, "npm", INSTALL, arg[0], kit.Dict(cli.CMD_DIR, ice.USR))
|
||||
}
|
||||
})
|
||||
m.RenderDownload(p)
|
||||
}},
|
||||
})
|
||||
|
86
core/mall/loan.go
Normal file
86
core/mall/loan.go
Normal file
@ -0,0 +1,86 @@
|
||||
package mall
|
||||
|
||||
import (
|
||||
"math"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const LOAN = "loan"
|
||||
|
||||
func init() {
|
||||
const (
|
||||
YEAR = "year"
|
||||
RATE = "rate"
|
||||
MONTH = "month"
|
||||
PAYMENT = "payment"
|
||||
PRESENT = "present"
|
||||
INTEREST = "interest"
|
||||
INTERESTS = "interests"
|
||||
PRESENTS = "presents"
|
||||
)
|
||||
Index.MergeCommands(ice.Commands{
|
||||
LOAN: {Name: "loan auto loan1 loan2", Help: "分期贷款", Meta: kit.Dict(
|
||||
ice.CTX_TRANS, kit.Dict(html.INPUT, kit.Dict(
|
||||
YEAR, "年数", RATE, "利率", MONTH, "期数", PAYMENT, "月供",
|
||||
PRESENT, "本金", INTEREST, "利息", INTERESTS, "累积利息", PRESENTS, "还欠本金",
|
||||
AMOUNT, "累积还款",
|
||||
)),
|
||||
), Actions: ice.MergeActions(ice.Actions{
|
||||
"loan1": {Name: "load present=300 year=30 rate=4.2", Help: "等额本息", Hand: func(m *ice.Message, arg ...string) {
|
||||
//〔贷款本金×月利率×(1+月利率)^还款月数〕÷〔(1+月利率)^还款月数 - 1〕
|
||||
number, rate := kit.Float(m.Option(YEAR))*12, kit.Float(m.Option(RATE))/100/12
|
||||
present := kit.Float(m.Option(PRESENT)) * 10000
|
||||
pow := math.Pow((1 + rate), number)
|
||||
p := present * rate * pow / (pow - 1)
|
||||
var interests, presents float64
|
||||
presents = present
|
||||
for i := float64(0); i < number; i++ {
|
||||
_p := presents * rate
|
||||
interests += _p
|
||||
presents -= (present / number)
|
||||
m.Push(MONTH, kit.Int(i+1)).Push(PAYMENT, p)
|
||||
m.Push(PRESENT, p-_p).Push(INTEREST, _p)
|
||||
m.Push(INTERESTS, interests)
|
||||
m.Push(PRESENTS, presents)
|
||||
m.Push(AMOUNT, p*(i+1))
|
||||
}
|
||||
m.Status(kit.Dict(
|
||||
PAYMENT, kit.Format("%0.2f 元", p),
|
||||
PRESENT, kit.Format("%0.2f 万", present/10000),
|
||||
INTEREST, kit.Format("%0.2f 万", p*number/10000-present/10000),
|
||||
AMOUNT, kit.Format("%0.2f 万", p*number/10000),
|
||||
MONTH, kit.Format("%v 期", number),
|
||||
))
|
||||
}},
|
||||
"loan2": {Name: "load present=300 year=30 rate=4.2", Help: "等额本金", Hand: func(m *ice.Message, arg ...string) {
|
||||
// 每月还款金额 =(贷款本金 ÷ 还款月数)+(本金 — 已归还本金累计额)×每月利率
|
||||
present := kit.Float(m.Option(PRESENT)) * 10000
|
||||
number, rate := kit.Float(m.Option(YEAR))*12, kit.Float(m.Option(RATE))/100/12
|
||||
var interests, presents, amount, payment float64
|
||||
presents = present
|
||||
for i := float64(0); i < number; i++ {
|
||||
p := present/number + (present-i*(present/number))*rate
|
||||
interests += (present - i*(present/number)) * rate
|
||||
presents -= present / number
|
||||
amount += p
|
||||
kit.If(i == 0, func() { payment = p })
|
||||
m.Push(MONTH, kit.Int(i+1)).Push(PAYMENT, p)
|
||||
m.Push(PRESENT, present/number).Push(INTEREST, (present-i*(present/number))*rate)
|
||||
m.Push(INTERESTS, interests)
|
||||
m.Push(PRESENTS, presents)
|
||||
m.Push(AMOUNT, amount)
|
||||
}
|
||||
m.Status(kit.Dict(
|
||||
PAYMENT, kit.Format("%0.2f 元", payment),
|
||||
PRESENT, kit.Format("%0.2f 万", present/10000),
|
||||
INTEREST, kit.Format("%0.2f 万", amount/10000-present/10000),
|
||||
AMOUNT, kit.Format("%0.2f 万", amount/10000),
|
||||
MONTH, kit.Format("%v 期", number),
|
||||
))
|
||||
}},
|
||||
})},
|
||||
})
|
||||
}
|
@ -24,7 +24,7 @@ const WORD = "word"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
WORD: {Name: "word path=src/main.shy@key auto play", Icon: "Books.png", Help: "上下文", Actions: ice.MergeActions(ice.Actions{
|
||||
WORD: {Name: "word path=src/main.shy@key auto play", Help: "上下文", Icon: "Books.png", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
WordAlias(m, NAVMENU, TITLE, NAVMENU)
|
||||
WordAlias(m, PREMENU, TITLE, PREMENU)
|
||||
|
Loading…
x
Reference in New Issue
Block a user