app

package
v1.2.48 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AppProj = Proj{
	"article": ArticleCtr,
	"org":     OrgCtr,
	"ctg":     CtgCtr,
	"mail":    MailCtr,
	"test": {
		"test": func(that *Context) {

			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{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))
		},

		"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))

		},
	},
}
View Source
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")
		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")
		finishTime := that.Req.FormValue("finish_time")

		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})

	},
}
View Source
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")
		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")

		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)

	},
}
View Source
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
		}

		where := Map{"state": 0, "show": 1}

		if len(where) > 1 {
			where = Map{"AND": where}
		}

		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})

	},
}
View Source
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")
		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)

	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳