package app import ( . "../../../hotime" . "../../../hotime/common" "time" ) var product_spot_checkCtr = 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("product_spot_check", Map{"[><]product": "product_spot_check.product_id=product.id", "[><]produce": "product_spot_check.produce_id=produce.id", }, "id,img,product_id,product.name AS product_name,admin_id,"+ "modify_time,state,rule,produce_id,produce.name AS produce_name", 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") sn := that.Req.FormValue("sn") rule := that.Req.FormValue("rule_spot_check") description := that.Req.FormValue("description") produceProductId := ObjToInt(that.Req.FormValue("produce_product_id")) //count := ObjToInt(that.Req.FormValue("count")) state := ObjToInt(that.Req.FormValue("state")) if rule == "" || produceProductId == 0 { that.Display(3, "参数不足,请补充参数") return } produceProduct := that.Db.Get("produce_product", "*", Map{"id": produceProductId}) if produceProduct == nil { that.Display(4, "找不到成品记录,无法进行抽检") return } //判断是否已经抽检了 alreadyCheck := that.Db.Get("product_spot_check", "id", Map{"produce_product_id": produceProductId}) if alreadyCheck == nil { that.Db.Update("product", Map{"spot_check_count[#]": "spot_check_count+1"}, Map{"id": produceProduct.GetCeilInt("product_id")}) that.Db.Update("produce", Map{"spot_check_count[#]": "spot_check_count+1"}, Map{"id": produceProduct.GetCeilInt("produce_id")}) } data := Map{ "sn": sn, "rule": rule, "admin_id": adminID, "create_time": time.Now().Unix(), "modify_time": time.Now().Unix(), "product_id": produceProduct.GetCeilInt("product_id"), "produce_id": produceProduct.GetCeilInt("produce_id"), "produce_product_id": produceProductId, "description": description, "state": state, } id := that.Db.Insert("product_spot_check", data) if id == 0 { that.Display(4, "添加抽检记录失败,请重新添加") return } data["id"] = id that.Display(0, data) }, "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")) productId := ObjToInt(that.Req.FormValue("id")) if page < 1 { page = 1 } if pageSize <= 0 { pageSize = 10 } columnStr := "product_spot_check.id,product_spot_check.product_id,product_spot_check.sn,product.name,product_spot_check.img,product_spot_check.admin_id,admin.name AS admin_name,product_spot_check.modify_time,product_spot_check.state" leftJoin := Map{"[><]product": "product_spot_check.product_id=product.id", "[><]admin": "product_spot_check.admin_id=admin.id", } where := Map{"ORDER": "id DESC"} if productId != 0 { where["product_id"] = productId } count := that.Db.Count("product_spot_check", where) reData := that.Db.Page(page, pageSize). PageSelect("product_spot_check", leftJoin, columnStr, where) that.Display(0, Map{"count": count, "data": reData}) }, }