hotime/example/admin/init.go
2021-11-15 03:35:13 +08:00

81 lines
2.3 KiB
Go

package admin
import (
. "../../../hotime"
. "../../../hotime/common"
)
var ID = "b6e1eae6a28c3e962c4e5e6b4650209e"
// Project 管理端项目
var Project = Proj{
//"user": UserCtr,
"admin": adminCtr,
"category": categoryCtr,
"furnace_temperature": furnace_temperatureCtr,
"material": materialCtr,
"material_inout": material_inoutCtr,
"org": orgCtr,
"produce": produceCtr,
"produce_material": produce_materialCtr,
"produce_product": produce_productCtr,
"product": productCtr,
"product_check": product_checkCtr,
"product_line": product_lineCtr,
"product_spot_check": product_spot_checkCtr,
"role": roleCtr,
"user": userCtr,
"hotime": Ctr{
"login": func(this *Context) {
name := this.Req.FormValue("name")
password := this.Req.FormValue("password")
if name == "" || password == "" {
this.Display(3, "参数不足")
return
}
user := this.Db.Get("admin", "*", Map{"AND": Map{"OR": Map{"name": name, "phone": name}, "password": Md5(password)}})
if user == nil {
this.Display(5, "登录失败")
return
}
this.Session("admin_id", user.GetCeilInt("id"))
this.Session("admin_name", name)
this.Display(0, this.SessionId)
},
"logout": func(this *Context) {
this.Session("admin_id", nil)
this.Session("admin_name", nil)
this.Display(0, "退出登录成功")
},
"info": func(that *Context) {
data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()})
str, inData := that.MakeCode.Info("admin", data, that.Db)
where := Map{"id": that.Session("admin_id").ToCeilInt()}
if len(inData) == 1 {
inData["id"] = where["id"]
where = Map{"AND": inData}
} else if len(inData) > 1 {
where["OR"] = inData
where = Map{"AND": where}
}
re := that.Db.Get("admin", str, where)
if re == nil {
that.Display(4, "找不到对应信息")
return
}
for k, v := range re {
column := that.MakeCode.TableColumns["admin"][k]
if column == nil {
continue
}
if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" {
re[column.GetString("link")] = that.Db.Get(column.GetString("link"), "id,"+column.GetString("value"), Map{"id": v})
}
}
that.Display(0, re)
},
},
}