package provider import ( . "code.hoteas.com/golang/hotime" . "code.hoteas.com/golang/hotime/common" ) var MattersCtr = Ctr{ "info": func(that *Context) { if that.Session("salesman_id").Data == nil { that.Display(2, "没有登录") return } id := ObjToInt(that.Req.FormValue("id")) if id == 0 { that.Display(3, "请求参数异常") return } res := that.Db.Get("matters", "*", Map{"id": id}) if res == nil { that.Display(4, "找不到事项") return } if res.GetCeilInt("salesman_id") != that.Session("salesman_id").ToCeilInt() { that.Display(4, "不是你的事项") return } res["user"] = that.Db.Get("user", "id,name,nickname,company_id", Map{"id": res.GetCeilInt64("user_id")}) if res.GetMap("user") != nil && res.GetMap("user").GetCeilInt64("company_id") != 0 { res["company"] = that.Db.Get("company", "id,name", Map{"id": res.GetMap("user").GetCeilInt64("company_id")}) } that.Display(0, res) }, //用户微信公众号或者小程序登录 "search": func(that *Context) { if that.Session("salesman_id").Data == nil { that.Display(2, "没有登录") return } userId := ObjToInt(that.Req.FormValue("id")) page := ObjToInt(that.Req.FormValue("page")) pageSize := ObjToInt(that.Req.FormValue("pageSize")) tp := that.Req.FormValue("type") if page < 1 { page = 1 } if pageSize <= 0 { pageSize = 20 } data := Map{"del_flag": 0, "salesman_id": that.Session("salesman_id").Data} keywords := that.Req.FormValue("keywords") if keywords != "" { data["OR"] = Map{"title[~]": keywords, "description[~]": keywords, "content[~]": keywords} } if userId != 0 { user := that.Db.Get("user", "id", Map{"AND": Map{"id": userId, "salesman_id": that.Session("salesman_id").Data}}) if user != nil { data["user_id"] = userId } } if tp != "" { data["type"] = ObjToInt("tp") } startTime := that.Req.FormValue("starttime") finishTime := that.Req.FormValue("finishtime") if startTime != "" { data["modify_time[>=]"] = startTime } if finishTime != "" { data["modify_time[<=]"] = finishTime } if len(data) > 1 { data = Map{"AND": data} } count := that.Db.Count("matters", data) res := that.Db.Page(page, pageSize).PageSelect("matters", "*", data) for _, v := range res { if v.GetCeilInt64("user_id") != 0 { v["user"] = that.Db.Get("user", "id,avatar,name,nickname,company_id", Map{"id": v.GetCeilInt64("user_id")}) if v.GetMap("user") != nil && v.GetMap("user").GetCeilInt64("company_id") != 0 { v["company"] = that.Db.Get("company", "id,name", Map{"id": v.GetMap("user").GetCeilInt64("company_id")}) } } } that.Display(0, Map{"total": count, "data": res}) }, }