diff --git a/example/app/article.go b/example/app/article.go deleted file mode 100644 index 5731087..0000000 --- a/example/app/article.go +++ /dev/null @@ -1,104 +0,0 @@ -package app - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" - "time" -) - -var ArticleCtr = Ctr{ - "info": func(that *Context) { - sn := that.Req.FormValue("sn") - article := that.Db.Get("article", Map{"[><]ctg_article": "article.id=ctg_article.article_id"}, "article.*,ctg_article.ctg_id AS sctg_id", Map{"ctg_article.sn": sn}) - if article == nil { - that.Display(4, "找不到对应数据") - return - } - ctgId := article.GetCeilInt64("sctg_id") - ctg := that.Db.Get("ctg", "*", Map{"id": ctgId}) - parents := []Map{} - parentId := ctg.GetCeilInt64("parent_id") - article["tongji"] = that.Db.Select("ctg", "sn,name,img,parent_id", Map{"parent_id": parentId}) - for true { - - if parentId == 0 { - break - } - - parent := that.Db.Get("ctg", "sn,name,img,parent_id", Map{"id": parentId}) - if parent == nil { - break - } - - parents = append(parents, parent) - parentId = parent.GetCeilInt64("parent_id") - - } - - ctg["parents"] = parents - - article["ctg"] = ctg - that.Display(0, article) - }, - "list": func(that *Context) { - sn := that.Req.FormValue("ctg_sn") //ctgsn - page := ObjToInt(that.Req.FormValue("page")) - pageSize := ObjToInt(that.Req.FormValue("pageSize")) - - if page == 0 { - page = 1 - } - if pageSize == 0 { - pageSize = 10 - } - - keywords := that.Req.FormValue("keywords") - - lunbo := ObjToInt(that.Req.FormValue("lunbo")) - - sort := that.Req.FormValue("sort") - - where := Map{"article.push_time[<]": time.Now().Format("2006-01-02 15:04"), "article.state": 0} - if sn != "" { - ctg := that.Db.Get("ctg", "id", Map{"sn": sn}) - if ctg != nil { - where["ctg_article.ctg_id"] = ctg.GetCeilInt("id") - } - } - - startTime := that.Req.FormValue("start_time") //ctgsn - finishTime := that.Req.FormValue("finish_time") //ctgsn - - if lunbo != 0 { - where["article.lunbo"] = lunbo - } - - if len(startTime) > 5 { - where["article.push_time[>=]"] = startTime - } - if len(finishTime) > 5 { - where["article.push_time[<=]"] = finishTime - } - - if keywords != "" { - where["OR"] = Map{"article.title[~]": keywords, "article.description[~]": keywords, "article.author[~]": keywords, "article.sn[~]": keywords, "article.origin[~]": keywords, "article.url[~]": keywords} - } - - if len(where) > 1 { - where = Map{"AND": where} - } - - if sort == "" { - where["ORDER"] = Slice{"article.sort DESC", "article.push_time DESC"} - } - - if sort == "time" { - where["ORDER"] = "article.push_time DESC" - } - count := that.Db.Count("article", Map{"[><]ctg_article": "article.id=ctg_article.article_id"}, where) - article := that.Db.Page(page, pageSize).PageSelect("article", Map{"[><]ctg_article": "article.id=ctg_article.article_id"}, "ctg_article.sn,article.img,article.title,article.description,article.push_time,article.lunbo,article.author,article.origin,article.url", where) - - that.Display(0, Map{"count": count, "data": article}) - - }, -} diff --git a/example/app/ctg.go b/example/app/ctg.go deleted file mode 100644 index 2773e63..0000000 --- a/example/app/ctg.go +++ /dev/null @@ -1,77 +0,0 @@ -package app - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" -) - -var CtgCtr = Ctr{ - "info": func(that *Context) { - sn := that.Req.FormValue("sn") - ctg := that.Db.Get("ctg", "*", Map{"sn": sn}) - parents := []Map{} - parentId := ctg.GetCeilInt64("parent_id") - ctg["tongji"] = that.Db.Select("ctg", "sn,name,img,parent_id", Map{"parent_id": parentId}) - for true { - - if parentId == 0 { - break - } - - parent := that.Db.Get("ctg", "sn,name,img,parent_id", Map{"id": parentId}) - if parent == nil { - break - } - - parents = append(parents, parent) - parentId = parent.GetCeilInt64("parent_id") - - } - - if ctg.GetCeilInt64("article_id") != 0 { - ctg["article"] = that.Db.Get("article", "*", Map{"id": ctg.GetCeilInt64("article_id")}) - } - - ctg["parents"] = parents - that.Display(0, ctg) - }, - "list": func(that *Context) { - sn := that.Req.FormValue("sn") //ctgsn - page := ObjToInt(that.Req.FormValue("page")) - pageSize := ObjToInt(that.Req.FormValue("pageSize")) - - if page == 0 { - page = 1 - } - if pageSize == 0 { - pageSize = 50 - } - - keywords := that.Req.FormValue("keywords") - - //sort:=that.Req.FormValue("sort") - - where := Map{"state": 0} - if sn != "" { - ctg := that.Db.Get("ctg", "id", Map{"sn": sn}) - if ctg != nil { - where["parent_id"] = ctg.GetCeilInt("id") - } - } - - if keywords != "" { - where["OR"] = Map{"name[~]": keywords, "url[~]": keywords, "sn[~]": keywords} - } - - if len(where) > 1 { - where = Map{"AND": where} - } - - where["ORDER"] = Slice{"sort DESC", "id DESC"} - - article := that.Db.Page(page, pageSize).PageSelect("ctg", "name,sn,sort,url,img", where) - - that.Display(0, article) - - }, -} diff --git a/example/app/init.go b/example/app/init.go deleted file mode 100644 index 51cbb00..0000000 --- a/example/app/init.go +++ /dev/null @@ -1,127 +0,0 @@ -package app - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" - "time" -) - -var AppProj = Proj{ - "article": ArticleCtr, - "org": OrgCtr, - "ctg": CtgCtr, - "mail": MailCtr, - "test": { - "test": func(that *Context) { - //data:=that.Db.Table("admin").Order("id DESC").Select("*") - //data1:=that.Db.Table("admin").Where(Map{"name[~]":"m"}).Order("id DESC").Select("*") - // - //data3:=that.Db.Select("admin","*",Map{"name[~]":"m"}) - data2 := that.Db.Table("article").Where(Map{"title[~]": "m"}).Order("id DESC").Page(1, 10).Select("*") - c := that.Db.Table("article").Where(Map{"title[~]": "m"}).Order("id DESC").Group("title").Select("*") - //that.Display(0,Slice{data1,data,data3,data2}) - that.Display(0, Slice{data2, c}) - }, - "res": func(that *Context) { - ebw_res := that.Db.Select("ebw_res", "*") - - for _, v := range ebw_res { - data := Map{"id": v.GetCeilInt("id"), "name": v.GetString("name"), - "parent_id": v.GetCeilInt64("pid"), - "sn": v.GetString("url"), "create_time": time.Now().Format("2006-01-02 15:04"), - "modify_time": time.Now().Format("2006-01-02 15:04"), "admin_id": 1} - if data.GetCeilInt("parent_id") == 0 { - data["parent_id"] = nil - } - that.Db.Insert("ctg", data) - } - - that.Db.Exec("UPDATE ctg SET parent_id =NULL WHERE parent_id=id") - - ss(0, that) - - that.Display(0, len(ebw_res)) - - }, - "news": func(that *Context) { - ebw_news := that.Db.Select("ebw_news", "*") - - for _, v := range ebw_news { - ctg := that.Db.Get("ctg", "*", Map{"sn": v.GetString("type")}) - data := Map{"sn": v.GetString("id"), "title": v.GetString("title"), - "content": v.GetString("content"), "push_time": v.GetString("timedate"), - "author": v.GetString("owner"), "origin": v.GetString("source"), "click_num": v.GetString("readtime"), - "sort": v.GetCeilInt("zhiding"), "create_time": time.Now().Format("2006-01-02 15:04"), - "modify_time": time.Now().Format("2006-01-02 15:04"), "admin_id": 1} - if ctg != nil { - data["ctg_id"] = ctg.GetCeilInt("id") - } - that.Db.Insert("article", data) - } - - that.Display(0, len(ebw_news)) - - }, - "res2news": func(that *Context) { - ebw_news_addition_res := that.Db.Select("ebw_news_addition_res", "*") - - for _, v := range ebw_news_addition_res { - ctg := that.Db.Get("ctg", "*", Map{"sn": v.GetString("fk_res")}) - article := that.Db.Get("article", "*", Map{"sn": v.GetString("fk_newsid")}) - data := Map{"sn": Md5(ObjToStr(time.Now().UnixNano()) + ObjToStr(RandX(10000, 100000))), - "create_time": time.Now().Format("2006-01-02 15:04"), - "modify_time": time.Now().Format("2006-01-02 15:04"), "admin_id": 1} - if ctg != nil { - data["ctg_id"] = ctg.GetCeilInt("id") - } - if article != nil { - data["article_id"] = article.GetCeilInt("id") - } - that.Db.Insert("ctg_article", data) - } - - that.Display(0, len(ebw_news_addition_res)) - }, - //将文章没有关联的ctg_article进行关联 - "article": func(that *Context) { - articles := that.Db.Select("article", "id,ctg_id") - for _, v := range articles { - ctg_article := that.Db.Get("ctg_article", "id", Map{"article_id": v.GetCeilInt("id")}) - if ctg_article == nil { - - data := Map{"sn": Md5(ObjToStr(time.Now().UnixNano()) + ObjToStr(RandX(10000, 100000))), - "create_time": time.Now().Format("2006-01-02 15:04"), - "modify_time": time.Now().Format("2006-01-02 15:04"), "admin_id": 1} - if v.GetCeilInt("ctg_id") == 0 || v.GetCeilInt("id") == 0 { - continue - } - data["ctg_id"] = v.GetCeilInt("ctg_id") - data["article_id"] = v.GetCeilInt("id") - that.Db.Insert("ctg_article", data) - } - - } - that.Display(0, len(articles)) - - }, - }, -} - -func ss(parent_id int, that *Context) { - var ctgs []Map - ctg := that.Db.Get("ctg", "*", Map{"id": parent_id}) - if parent_id == 0 { - ctgs = that.Db.Select("ctg", "*", Map{"parent_id": nil}) - } else { - ctgs = that.Db.Select("ctg", "*", Map{"parent_id": parent_id}) - } - - for _, v := range ctgs { - if ctg == nil { - ctg = Map{"parent_ids": ","} - } - ids := ctg.GetString("parent_ids") + ObjToStr(v.GetCeilInt("id")) + "," - that.Db.Update("ctg", Map{"parent_ids": ids}, Map{"id": v.GetCeilInt("id")}) - ss(v.GetCeilInt("id"), that) - } -} diff --git a/example/app/mail.go b/example/app/mail.go deleted file mode 100644 index a7b9502..0000000 --- a/example/app/mail.go +++ /dev/null @@ -1,96 +0,0 @@ -package app - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" - "time" -) - -var MailCtr = Ctr{ - "add": func(that *Context) { - title := that.Req.FormValue("title") - name := that.Req.FormValue("name") - phone := that.Req.FormValue("phone") - content := that.Req.FormValue("content") - - tp := ObjToInt(that.Req.FormValue("type")) - show := ObjToInt(that.Req.FormValue("show")) - - if len(title) < 5 { - that.Display(3, "标题过短") - return - } - if len(name) < 2 { - that.Display(3, "姓名错误") - return - } - if len(phone) < 8 { - that.Display(3, "联系方式错误") - return - } - if len(content) < 10 { - that.Display(3, "内容过短") - return - } - - data := Map{ - "sn": Md5(ObjToStr(time.Now().UnixNano()) + ObjToStr(RandX(10000, 100000))), - "name": name, "title": title, "phone": phone, "content": content, "type": tp, "show": show, - "modify_time[#]": "NOW()", "create_time[#]": "NOW()", - } - id := that.Db.Insert("mail", data) - if id == 0 { - that.Display(4, "创建失败") - return - } - - that.Display(0, "成功") - return - - }, - "info": func(that *Context) { - sn := that.Req.FormValue("sn") - - mail := that.Db.Get("mail", "*", Map{"sn": sn}) - - that.Display(0, mail) - }, - "list": func(that *Context) { - page := ObjToInt(that.Req.FormValue("page")) - pageSize := ObjToInt(that.Req.FormValue("pageSize")) - - if page == 0 { - page = 1 - } - if pageSize == 0 { - pageSize = 10 - } - - //keywords:=that.Req.FormValue("keywords") - - //sort:=that.Req.FormValue("sort") - - where := Map{"state": 0, "show": 1} - - //if keywords!=""{ - // where["OR"]=Map{"title[~]":keywords,"description[~]":keywords,"author[~]":keywords,"sn[~]":keywords,"origin[~]":keywords,"url[~]":keywords} - //} - - if len(where) > 1 { - where = Map{"AND": where} - } - - //if sort==""{ - // where["ORDER"]=Slice{"sort DESC","push_time DESC"} - //} - // - //if sort=="time"{ - where["ORDER"] = "create_time DESC" - //} - count := that.Db.Count("mail", where) - mail := that.Db.Page(page, pageSize).PageSelect("mail", "*", where) - - that.Display(0, Map{"count": count, "data": mail}) - - }, -} diff --git a/example/app/org.go b/example/app/org.go deleted file mode 100644 index f5908f5..0000000 --- a/example/app/org.go +++ /dev/null @@ -1,60 +0,0 @@ -package app - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" - "time" -) - -var OrgCtr = Ctr{ - "info": func(that *Context) { - sn := that.Req.FormValue("sn") - article := that.Db.Get("article", "*", Map{"sn": sn}) - that.Display(0, article) - }, - "list": func(that *Context) { - sn := that.Req.FormValue("sn") //orgsn - page := ObjToInt(that.Req.FormValue("page")) - pageSize := ObjToInt(that.Req.FormValue("pageSize")) - - if page == 0 { - page = 1 - } - if pageSize == 0 { - pageSize = 50 - } - - keywords := that.Req.FormValue("keywords") - - sort := that.Req.FormValue("sort") - - where := Map{"push_time[<=]": time.Now().Format("2006-01-02 15:04"), "state": 0} - if sn != "" { - org := that.Db.Get("org", "id", Map{"sn": sn}) - if org != nil { - where["org_id"] = org.GetCeilInt("id") - } - } - - if keywords != "" { - where["OR"] = Map{"title[~]": keywords, "description[~]": keywords, "author[~]": keywords, "sn[~]": keywords, "origin[~]": keywords, "url[~]": keywords} - } - - if len(where) > 1 { - where = Map{"AND": where} - } - - if sort == "" { - where["ORDER"] = Slice{"sort DESC", "id DESC"} - } - - if sort == "time" { - where["ORDER"] = "push_time DESC" - } - - article := that.Db.Page(page, pageSize).PageSelect("article", "sn,title,description,push_time,lunbo,author,origin,url", where) - - that.Display(0, article) - - }, -}