package provider import ( . "code.hoteas.com/golang/hotime" . "code.hoteas.com/golang/hotime/common" ) var TagCtr = Ctr{ "create": func(that *Context) { if that.Session("user_id").Data == nil { that.Display(2, "没有登录") return } name := that.Req.FormValue("name") oldTag := that.Db.Get("tag", "id", Map{"name": name}) if oldTag != nil { that.Display(4, "此标签已存在") return } re := that.Db.Insert("tag", Map{ "user_id": that.Session("user_id").Data, "name": name, "remark": "用户上传", "create_time[#]": "now()", "modify_time[#]": "now()", "state": 1, //先置为异常状态,等待审核通过 "del_flag": 0, }) if re == 0 { that.Display(4, "添加失败") return } that.Display(0, "添加成功") return }, //用户微信公众号或者小程序登录 "search": func(that *Context) { page := ObjToInt(that.Req.FormValue("page")) pageSize := ObjToInt(that.Req.FormValue("pageSize")) if page < 1 { page = 1 } if pageSize <= 0 { pageSize = 40 } data := Map{"del_flag": 0, "state": 0} keywords := that.Req.FormValue("keywords") if keywords != "" { data["OR"] = Map{"name[~]": keywords, "remark[~]": keywords} } 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("tag", data) res := that.Db.Page(page, pageSize).PageSelect("tag", "id,name,remark", data) that.Display(0, Map{"total": count, "data": res}) }, }