package app import ( . "../../../hotime" . "../../../hotime/common" "strings" ) var produceCtr = 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) { 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, "删除成功") }, "check": func(that *Context) { adminID := that.Session("id").ToInt() if adminID == 0 { that.Display(2, "登录失效,请重新登录") return } data := ObjToMap(that.Req.FormValue("data")) texts := data.GetSlice("text") textData := []Map{} for k, _ := range texts { v := texts.GetString(k) if len(v) < 3 { continue } vs := that.Db.Select("produce", Map{"[>]product": "produce.product_id=product.id"}, "produce.name,produce.id,produce.product_id,product.name AS product_name,product.rule_check,product.rule_spot_check", Map{"produce.sn[~]": v[:len(v)/2+1]}) for _, v1 := range vs { if len(textData) == 0 { textData = append(textData, v1) } for _, vt := range textData { if v1.GetString("id") != vt.GetString("id") { add := true for _, vt1 := range textData { if vt1.GetCeilInt("id") == v1.GetCeilInt("id") { add = false break } } if add { v1["count"] = 1 textData = append(textData, v1) } } else { vt["count"] = vt.GetCeilInt("count") + 1 } } } } qrcode := data.GetSlice("qrcode") for k, _ := range qrcode { v := qrcode.GetString(k) if len(v) < 3 { continue } vs := that.Db.Select("produce", Map{"[>]product": "produce.product_id=product.id"}, "produce.name,produce.id,produce.product_id,product.name AS product_name,product.rule_check,product.rule_spot_check", Map{"produce.sn[~]": v[:len(v)/2+1]}) for _, v1 := range vs { if len(textData) == 0 { textData = append(textData, v1) } for _, vt := range textData { if v1.GetString("id") != vt.GetString("id") { v1["count"] = 1 textData = append(textData, v1) } else { vt["count"] = vt.GetCeilInt("count") + 1 } } } } that.Display(0, textData) }, "search": func(that *Context) { adminID := that.Session("id").ToInt() if adminID == 0 { that.Display(2, "登录失效,请重新登录") return } columnStr := "produce.id,produce.sn,produce.name,produce.state,produce.product_id,product.name AS product_name" where := Map{"produce.state[!]": 0, "ORDER": "produce.modify_time DESC"} reData := that.Db.Select("produce", Map{"[>]product": "produce.product_id=product.id"}, columnStr, where) that.Display(0, reData) }, }