hotime/example/app/produce_product.go

95 lines
2.3 KiB
Go
Raw Normal View History

2021-12-11 15:53:47 +00:00
package app
import (
. "../../../hotime"
. "../../../hotime/common"
2021-12-15 01:24:41 +00:00
"time"
2021-12-11 15:53:47 +00:00
)
var produce_productCtr = Ctr{
"info": func(that *Context) {
adminID := that.Session("id").ToInt()
if adminID == 0 {
that.Display(2, "登录失效,请重新登录")
return
}
id := ObjToInt(that.Req.FormValue("id"))
sn := that.Req.FormValue("sn")
if id == 0 && sn == "" {
that.Display(3, "请求参数不足,请检查参数")
return
}
where := Map{}
if id != 0 {
2021-12-15 01:24:41 +00:00
where["produce_product.id"] = id
2021-12-11 15:53:47 +00:00
} else {
2021-12-15 01:24:41 +00:00
where["produce_product.sn"] = sn
2021-12-11 15:53:47 +00:00
}
re := that.Db.Get("produce_product",
2021-12-15 01:24:41 +00:00
Map{"[><]product": "produce_product.product_id=product.id",
"[><]produce": "produce_product.produce_id=produce.id",
2021-12-11 15:53:47 +00:00
},
2021-12-15 01:24:41 +00:00
"produce_product.id,produce_product.product_id,product.name AS product_name,produce_product.admin_id,"+
"produce_product.modify_time,produce_product.state,product.rule_spot_check,produce_product.produce_id,produce.name AS produce_name", where)
2021-12-11 15:53:47 +00:00
if re == nil {
that.Display(4, "找不到对应信息")
return
}
that.Display(0, re)
},
2021-12-15 01:24:41 +00:00
"add": func(that *Context) {
adminID := that.Session("id").ToInt()
if adminID == 0 {
that.Display(2, "登录失效,请重新登录")
return
}
sn := that.Req.FormValue("sn")
product_id := ObjToInt(that.Req.FormValue("product_id"))
produce_id := ObjToInt(that.Req.FormValue("produce_id"))
state := ObjToInt(that.Req.FormValue("state"))
rule_check := that.Req.FormValue("rule_check")
description := that.Req.FormValue("description")
if sn == "" || rule_check == "" {
that.Display(3, "参数不足,请补充参数")
return
}
data := Map{
"admin_id": adminID,
"sn": sn,
"product_id": product_id,
"produce_id": produce_id,
"create_time": time.Now().Unix(),
"modify_time": time.Now().Unix(),
}
id := that.Db.Insert("produce_product", data)
if id == 0 {
that.Display(4, "添加新成品失败,请重新添加")
return
}
//data["id"] = id
data["rule"] = rule_check
data["produce_product_id"] = id
data["state"] = state
data["description"] = description
id = that.Db.Insert("product_check", data)
if id == 0 {
that.Display(4, "添加质检失败,请重新添加")
return
}
that.Display(0, data)
},
2021-12-11 15:53:47 +00:00
}