hotime/example/admin/user.go

61 lines
1.4 KiB
Go
Raw Normal View History

2021-05-28 18:57:03 +00:00
package admin
import (
. "../../../hotime"
2021-05-29 16:01:15 +00:00
. "../../../hotime/common"
2021-05-28 18:57:03 +00:00
)
var UserCtr = Ctr{
"info": func(that *Context) {
re := that.Db.Get(that.RouterString[1], that.MakeCode.Info(that.RouterString[1]), Map{"id": that.RouterString[2]})
that.Display(0, re)
2021-05-28 18:57:03 +00:00
},
"add": func(that *Context) {
inData := that.MakeCode.Add(that.RouterString[1], that.Req)
if inData == nil {
that.Display(3, "请求参数不足")
return
}
re := that.Db.Insert(that.RouterString[1], inData)
2021-05-28 18:57:03 +00:00
if re == 0 {
that.Display(4, "无法插入对应数据")
return
}
that.Display(0, re)
2021-05-28 18:57:03 +00:00
},
"update": func(that *Context) {
inData := that.MakeCode.Edit(that.RouterString[1], that.Req)
if inData == nil {
that.Display(3, "没有找到要更新的数据")
return
}
re := that.Db.Update(that.RouterString[1], inData, Map{"id": that.RouterString[2]})
if re == 0 {
that.Display(4, "更新数据失败")
return
}
2021-05-28 18:57:03 +00:00
that.Display(0, re)
2021-05-28 18:57:03 +00:00
},
"remove": func(that *Context) {
re := that.Db.Delete(that.RouterString[1], Map{"id": that.RouterString[2]})
2021-05-28 18:57:03 +00:00
if re == 0 {
that.Display(4, "删除数据失败")
return
}
that.Display(0, re)
2021-05-28 18:57:03 +00:00
},
"search": func(that *Context) {
columnStr, where := that.MakeCode.Search(that.RouterString[1], that.Req)
reData := that.Db.Page(ObjToInt(that.Req.FormValue("page")), ObjToInt(that.Req.FormValue("pageRow"))).
Select(that.RouterString[1], columnStr, where)
that.Display(0, reData)
2021-05-28 18:57:03 +00:00
},
}