164 lines
4.4 KiB
Go
164 lines
4.4 KiB
Go
|
package app
|
||
|
|
||
|
import (
|
||
|
. "../../../hotime"
|
||
|
. "../../../hotime/common"
|
||
|
"strings"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
var material_inoutCtr = Ctr{
|
||
|
"info": func(that *Context) {
|
||
|
adminID := that.Session("id").ToInt()
|
||
|
|
||
|
if adminID == 0 {
|
||
|
that.Display(2, "登录失效,请重新登录")
|
||
|
return
|
||
|
}
|
||
|
|
||
|
id := ObjToInt(that.Req.FormValue("id"))
|
||
|
if id == 0 {
|
||
|
that.Display(3, "请求参数不足,请检查参数")
|
||
|
return
|
||
|
}
|
||
|
|
||
|
re := that.Db.Get("material_inout", "*", Map{"id": id})
|
||
|
|
||
|
if re == nil {
|
||
|
that.Display(4, "找不到对应信息")
|
||
|
return
|
||
|
}
|
||
|
|
||
|
that.Display(0, re)
|
||
|
},
|
||
|
"add": func(that *Context) {
|
||
|
|
||
|
adminID := that.Session("id").ToInt()
|
||
|
|
||
|
if adminID == 0 {
|
||
|
that.Display(2, "登录失效,请重新登录")
|
||
|
return
|
||
|
}
|
||
|
|
||
|
img := that.Req.FormValue("img")
|
||
|
rule := that.Req.FormValue("rule")
|
||
|
materialId := ObjToInt(that.Req.FormValue("material_id"))
|
||
|
produceId := ObjToInt(that.Req.FormValue("produce_id"))
|
||
|
count := ObjToInt(that.Req.FormValue("count"))
|
||
|
state := ObjToInt(that.Req.FormValue("state"))
|
||
|
if rule == "" || materialId == 0 || count == 0 {
|
||
|
that.Display(3, "参数不足,请补充参数")
|
||
|
return
|
||
|
}
|
||
|
if state > 0 {
|
||
|
count = -count
|
||
|
}
|
||
|
|
||
|
that.Db.Update("material", Map{"count[#]": "count+" + ObjToStr(count), "saved[#]": "saved+" + ObjToStr(count)}, Map{"id": materialId})
|
||
|
material := that.Db.Get("material", "*", Map{"id": materialId})
|
||
|
data := Map{
|
||
|
"img": img,
|
||
|
"rule": rule,
|
||
|
"admin_id": adminID,
|
||
|
"material_id": materialId,
|
||
|
"count": count,
|
||
|
"saved": material.GetCeilInt("count"),
|
||
|
"create_time": time.Now().Unix(),
|
||
|
"modify_time": time.Now().Unix(),
|
||
|
"produce_id": produceId,
|
||
|
"state": state,
|
||
|
}
|
||
|
|
||
|
id := that.Db.Insert("material_inout", data)
|
||
|
if id == 0 {
|
||
|
that.Display(4, "添加出入库记录失败,请重新添加")
|
||
|
return
|
||
|
}
|
||
|
|
||
|
data["id"] = id
|
||
|
|
||
|
that.Display(0, data)
|
||
|
},
|
||
|
"update": func(that *Context) {
|
||
|
inData := that.MakeCode.Edit(that.RouterString[1], that.Req)
|
||
|
if inData == nil {
|
||
|
that.Display(3, "没有找到要更新的数据")
|
||
|
return
|
||
|
}
|
||
|
|
||
|
//索引管理,便于检索以及权限
|
||
|
if inData.Get("parent_id") != nil && inData.GetString("index") != "" {
|
||
|
Index := that.Db.Get(that.RouterString[1], "`index`", Map{"id": that.RouterString[2]})
|
||
|
parentIndex := that.Db.Get(that.RouterString[1], "`index`", Map{"id": inData.Get("parent_id")})
|
||
|
inData["index"] = parentIndex.GetString("index") + that.RouterString[2] + ","
|
||
|
|
||
|
childNodes := that.Db.Select(that.RouterString[1], "id,`index`", Map{"index[~]": "," + that.RouterString[2] + ","})
|
||
|
|
||
|
for _, v := range childNodes {
|
||
|
v["index"] = strings.Replace(v.GetString("index"), Index.GetString("index"), inData.GetString("index"), -1)
|
||
|
that.Db.Update(that.RouterString[1], Map{"index": v["index"]}, Map{"id": v.GetCeilInt("id")})
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
re := that.Db.Update(that.RouterString[1], inData, Map{"id": that.RouterString[2]})
|
||
|
|
||
|
if re == 0 {
|
||
|
that.Display(4, "更新数据失败")
|
||
|
return
|
||
|
}
|
||
|
|
||
|
that.Display(0, re)
|
||
|
},
|
||
|
"remove": func(that *Context) {
|
||
|
inData := that.MakeCode.Delete(that.RouterString[1], that.Req)
|
||
|
if inData == nil {
|
||
|
that.Display(3, "请求参数不足")
|
||
|
return
|
||
|
}
|
||
|
re := int64(0)
|
||
|
//索引管理,便于检索以及权限
|
||
|
if inData.Get("parent_id") != nil && inData.GetSlice("index") != nil {
|
||
|
re = that.Db.Delete(that.RouterString[1], Map{"index[~]": "," + that.RouterString[2] + ","})
|
||
|
} else {
|
||
|
re = that.Db.Delete(that.RouterString[1], Map{"id": that.RouterString[2]})
|
||
|
}
|
||
|
|
||
|
if re == 0 {
|
||
|
that.Display(4, "删除数据失败")
|
||
|
return
|
||
|
}
|
||
|
that.Display(0, "删除成功")
|
||
|
},
|
||
|
|
||
|
"search": func(that *Context) {
|
||
|
|
||
|
adminID := that.Session("id").ToInt()
|
||
|
|
||
|
if adminID == 0 {
|
||
|
that.Display(2, "登录失效,请重新登录")
|
||
|
return
|
||
|
}
|
||
|
page := ObjToInt(that.Req.FormValue("page"))
|
||
|
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
|
||
|
|
||
|
if page < 1 {
|
||
|
page = 1
|
||
|
}
|
||
|
|
||
|
if pageSize <= 0 {
|
||
|
pageSize = 20
|
||
|
}
|
||
|
columnStr := "sn,material.name,img,count,saved,admin_id,admin.name AS admin_name,modify_time,state"
|
||
|
leftJoin := Map{"[><]material": "material_inout.material_id=material.id",
|
||
|
"[><]admin": "material_inout.admin_id=admin.id",
|
||
|
}
|
||
|
where := Map{"ORDER": "modify_time DESC"}
|
||
|
count := that.Db.Count("material_inout", "id", where)
|
||
|
reData := that.Db.Page(page, pageSize).
|
||
|
PageSelect("material_inout", leftJoin, columnStr, where)
|
||
|
|
||
|
that.Display(0, Map{"count": count, "data": reData})
|
||
|
},
|
||
|
}
|