forked from golang/hotime
139 lines
3.8 KiB
Go
139 lines
3.8 KiB
Go
package app
|
|
|
|
import (
|
|
. "../../../hotime"
|
|
. "../../../hotime/common"
|
|
"time"
|
|
)
|
|
|
|
var productCtr = Ctr{
|
|
"info": func(that *Context) {
|
|
data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()})
|
|
str, inData := that.MakeCode.Info(that.RouterString[1], data, that.Db)
|
|
where := Map{"id": that.RouterString[2]}
|
|
|
|
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(that.RouterString[1], str, where)
|
|
|
|
if re == nil {
|
|
that.Display(4, "找不到对应信息")
|
|
return
|
|
}
|
|
|
|
for k, v := range re {
|
|
column := that.MakeCode.TableColumns[that.RouterString[1]][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)
|
|
},
|
|
"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)
|
|
|
|
if re == 0 {
|
|
that.Display(4, "无法插入对应数据")
|
|
return
|
|
}
|
|
//索引管理,便于检索以及权限
|
|
if inData.Get("parent_id") != nil && inData.GetString("index") != "" {
|
|
index := that.Db.Get(that.RouterString[1], "`index`", Map{"id": inData.Get("parent_id")})
|
|
inData["index"] = index.GetString("index") + ObjToStr(re) + ","
|
|
that.Db.Update(that.RouterString[1], Map{"index": inData["index"]}, Map{"id": re})
|
|
} else if inData.GetString("index") != "" {
|
|
inData["index"] = "," + ObjToStr(re) + ","
|
|
that.Db.Update(that.RouterString[1], Map{"index": inData["index"]}, Map{"id": re})
|
|
}
|
|
|
|
that.Display(0, re)
|
|
},
|
|
"update": func(that *Context) {
|
|
adminID := that.Session("id").ToInt()
|
|
|
|
if adminID == 0 {
|
|
that.Display(2, "登录失效,请重新登录")
|
|
return
|
|
}
|
|
|
|
id := ObjToInt(that.Req.FormValue("id"))
|
|
//抽检更新
|
|
ruleSpotCheck := that.Req.FormValue("rule_spot_check")
|
|
if ruleSpotCheck != "" {
|
|
spotCheckPercentage := ObjToInt(that.Req.FormValue("spot_check_percentage"))
|
|
if id == 0 || ruleSpotCheck == "" {
|
|
that.Display(3, "请求参数不足,请检查参数")
|
|
return
|
|
}
|
|
|
|
re := that.Db.Update("product", Map{"rule_spot_check": ruleSpotCheck, "spot_check_percentage": spotCheckPercentage, "modify_time": time.Now().Unix()}, Map{"id": id})
|
|
if re == 0 {
|
|
that.Display(4, "更新失败,无法更新抽检参数")
|
|
return
|
|
}
|
|
} else {
|
|
//质检更新
|
|
ruleCheck := that.Req.FormValue("rule_check")
|
|
if id == 0 || ruleCheck == "" {
|
|
that.Display(3, "请求参数不足,请检查参数")
|
|
return
|
|
}
|
|
|
|
re := that.Db.Update("product", Map{"rule_check": ruleCheck, "modify_time": time.Now().Unix()}, Map{"id": id})
|
|
|
|
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 = 10
|
|
}
|
|
|
|
leftJoin := Map{"[><]admin": "product.admin_id=admin.id"}
|
|
columnStr := "product.id,product.name,product.img,product.count,product.used,product.saved,product.spot_check_count,product.admin_id,admin.name AS admin_name,product.modify_time,product.state"
|
|
where := Map{"ORDER": "modify_time DESC"}
|
|
count := that.Db.Count("product", where)
|
|
reData := that.Db.Page(page, pageSize).
|
|
PageSelect("product", leftJoin, columnStr, where)
|
|
|
|
that.Display(0, Map{"count": count, "data": reData})
|
|
},
|
|
}
|