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") rule := that.Req.FormValue("rule") produceProductId := ObjToInt(that.Req.FormValue("produce_product_id")) count := ObjToInt(that.Req.FormValue("count")) state := ObjToInt(that.Req.FormValue("state")) if rule == "" || produceProductId == 0 || count == 0 { that.Display(3, "参数不足,请补充参数") return } if state > 0 { count = -count } produceProduct := that.Db.Get("produce_product", "*", Map{"id": produceProductId}) that.Db.Update("product", Map{"spot_check_count[#]": "spot_check_count+" + ObjToStr(count), "spot_check_saved[#]": "spot_check_saved+" + ObjToStr(count)}, Map{"id": produceProduct.GetCeilInt("product_id")}) that.Db.Update("produce", Map{"spot_check_count[#]": "spot_check_count+" + ObjToStr(count), "spot_check_saved[#]": "spot_check_saved+" + ObjToStr(count)}, Map{"id": produceProduct.GetCeilInt("produce_id")}) data := Map{ "img": img, "rule": rule, "admin_id": adminID, "create_time": time.Now().Unix(), "modify_time": time.Now().Unix(), "produce_id": produceProduct.GetCeilInt("produce_id"), "produce_product_id": produceProductId, "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")) if page < 1 { page = 1 } if pageSize <= 0 { pageSize = 20 } columnStr := "sn,product.name,img,count,saved,admin_id,admin.name AS admin_name,modify_time,state" leftJoin := Map{"[><]product": "product_spot_check.product_id=product.id", "[><]admin": "product_spot_check.admin_id=admin.id", } where := Map{"ORDER": "modify_time DESC"} count := that.Db.Count("product_spot_check", "id", where) reData := that.Db.Page(page, pageSize). PageSelect("product_spot_check", leftJoin, columnStr, where) that.Display(0, Map{"count": count, "data": reData}) }, }