예제 #1
0
파일: comment.go 프로젝트: zacklin923/GoCMS
//获取评论列表
func (c *Comment) GetCommentList(search string, Page int64, Perpage int64) (comment_arr []*Comment, html template.HTML, where map[string]interface{}) {

	comment_list := []*Comment{}

	//查询条件
	var WhereStr string = " 1 AND "

	if len(search) > 0 {

		//解码
		where = utils.DecodeSegment(search)

		revel.WARN.Println(where)

		if where["start_time"] != "" {
			WhereStr += " `regdate` >='" + fmt.Sprintf("%s", where["start_time"]) + " 00:00:00' AND "
		}
	}

	WhereStr += " 1 "

	//查询总数
	comment := new(Comment)
	Total, err := DB_Read.Table("comment").Where(WhereStr).Count(comment)
	if err != nil {
		revel.WARN.Printf("错误: %v", err)
	}

	//分页
	Pager := new(utils.Page)
	if len(search) > 0 {
		Pager.SubPage_link = "/Comment/" + search + "/"
	} else {
		Pager.SubPage_link = "/Comment/"
	}

	Pager.Nums = Total
	Pager.Perpage = Perpage
	Pager.Current_page = Page
	Pager.SubPage_type = 2
	pages := Pager.Show()

	DB_Read.Table("comment").Where(WhereStr).Limit(int(Perpage), int((Page-1)*Pager.Perpage)).Desc("id").Find(&comment_list)

	if len(comment_list) > 0 {
		user := new(User)
		for i, v := range comment_list {
			comment_list[i].User = user.GetById(v.Uid)
		}
	}

	return comment_list, pages, where
}
예제 #2
0
파일: user.go 프로젝트: JREAMLU/GoCMS
//获取会员组列表
func (u *User) GetUserList(search string, Page int64, Perpage int64) (user_arr []*User, html template.HTML, where map[string]string) {
	//初始化菜单
	user_list := []*User{}

	//查询条件
	var WhereStr string = " 1 AND "

	if len(search) > 0 {
		//解码
		where = utils.DecodeSegment(search)

		revel.WARN.Println(where)

		if len(where["start_time"]) > 0 {
			WhereStr += " `regdate` >='" + where["start_time"] + " 00:00:00' AND "
		}

		if len(where["end_time"]) > 0 {
			WhereStr += " `regdate` <='" + where["end_time"] + " 23:59:59' AND "
		}

		if len(where["islock"]) > 0 && where["islock"] != "0" {
			WhereStr += " `islock` =" + where["islock"]
		}

		if len(where["type"]) > 0 && len(where["keyword"]) > 0 {

			if where["type"] == "1" {
				//用户名
				WhereStr += " `username` ='" + where["keyword"] + "' AND "
			} else if where["type"] == "2" {
				//用户ID
				WhereStr += " `id` =" + where["keyword"] + " AND "
			} else if where["type"] == "3" {
				//邮箱
				WhereStr += " `email` ='" + where["keyword"] + "' AND "
			} else if where["type"] == "4" {
				//注册ip
				WhereStr += " `regip` ='" + where["keyword"] + "' AND "
			} else if where["type"] == "5" {
				//昵称
				WhereStr += " `nickname` like '%" + where["keyword"] + "%' AND "
			}
		}
	}

	WhereStr += " 1 "

	//查询总数
	user := new(User)
	Total, err := DB_Read.Table("user").Where(WhereStr).Count(user)
	if err != nil {
		revel.WARN.Printf("错误: %v", err)
	}

	//分页
	Pager := new(utils.Page)
	if len(search) > 0 {
		Pager.SubPage_link = "/User/" + search + "/"
	} else {
		Pager.SubPage_link = "/User/"
	}

	Pager.Nums = Total
	Pager.Perpage = Perpage
	Pager.Current_page = Page
	Pager.SubPage_type = 2
	pages := Pager.Show()

	DB_Read.Table("user").Where(WhereStr).Limit(int(Perpage), int((Page-1)*Pager.Perpage)).Desc("id").Find(&user_list)

	if len(user_list) > 0 {
		user_group := new(User_Group)
		for i, v := range user_list {
			user_list[i].UserGroup = user_group.GetById(v.Groupid)
		}
	}

	return user_list, pages, where
}
예제 #3
0
파일: focus.go 프로젝트: zacklin923/GoCMS
//获取焦点图列表
func (c *Focus) GetByAll(search string, Page int64, Perpage int64) (focus_arr []*Focus, html template.HTML, where map[string]interface{}) {
	focus_list := []*Focus{}

	//查询条件
	var WhereStr string = " 1 AND "

	if len(search) > 0 {

		//解码
		where = utils.DecodeSegment(search)

		revel.WARN.Println(where)

		if where["cid"] != "" {
			WhereStr += " `cid`='" + fmt.Sprintf("%d", where["cid"]) + "' AND "
		}

		if where["keyword"] != "" {
			//关键字
			keyword := fmt.Sprintf("%s", where["keyword"])
			WhereStr += " `title` like '%" + keyword + "%' AND "
		}
	}

	WhereStr += " 1 "

	//查询总数
	focus := new(Focus)
	Total, err := DB_Read.Where(WhereStr).Count(focus)
	if err != nil {
		revel.WARN.Printf("错误: %v", err)
	}

	//分页
	Pager := new(utils.Page)
	Pager.SubPage_link = "/Focus/"
	Pager.Nums = Total
	Pager.Perpage = Perpage
	Pager.Current_page = Page
	Pager.SubPage_type = 2
	pages := Pager.Show()

	//查询数据
	DB_Read.Where(WhereStr).Limit(int(Perpage), int((Page-1)*Pager.Perpage)).Desc("id").Find(&focus_list)

	if len(focus_list) > 0 {
		admin := new(Admin)
		focuscate := new(FocusCate)

		for i, v := range focus_list {
			focus_list[i].Admin = admin.GetById(v.Aid)

			//所属栏目
			focus_list[i].Focuscate = focuscate.GetById(v.Cid)

			if v.Img != "" {
				//判断是否是系统的分隔符
				separator := "/"
				if os.IsPathSeparator('\\') {
					separator = "\\"
				} else {
					separator = "/"
				}

				config_file := (revel.BasePath + "/conf/config.conf")
				config_file = strings.Replace(config_file, "/", separator, -1)
				config_conf, _ := config.ReadDefault(config_file)

				//前台网站地址
				sitedomain, _ := config_conf.String("website", "website.sitedomain")
				v.Img = sitedomain + v.Img
			}
		}
	}

	return focus_list, pages, where
}
예제 #4
0
파일: article.go 프로젝트: JREAMLU/GoCMS
//获取内容列表
func (a *Article) GetByList(Cid int64, Search string, Page int64, Perpage int64) (article_arr []*Article, html template.HTML, where map[string]string) {
	article_list := []*Article{}

	//查询条件
	var WhereStr string = " 1 AND "

	if len(Search) > 0 {

		//解码
		where = utils.DecodeSegment(Search)

		revel.WARN.Println(where)

		if where["cid"] != "0" {
			WhereStr += " `cid`='" + where["cid"] + "' AND "
		}

		if len(where["field"]) > 0 && len(where["keyword"]) > 0 {

			if where["field"] == "title" {
				//标题
				WhereStr += " `title` like %'" + where["keyword"] + "'% AND "

			} else if where["field"] == "keywords" {
				//关键词
				WhereStr += " `keywords` like %'" + where["keyword"] + "'% AND "
			} else if where["field"] == "description" {
				//描述
				WhereStr += " `description` like %'" + where["keyword"] + "'% AND "
			} else if where["field"] == "id" {
				//ID
				WhereStr += " `id`='" + where["keyword"] + "' AND "
			}

		}
	}

	WhereStr += " 1 "

	//查询总数
	article := new(Article)
	Total, err := DB_Read.Where(WhereStr).Count(article)
	if err != nil {
		revel.WARN.Printf("错误: %v", err)
	}

	//分页
	Pager := new(utils.Page)
	Pager.SubPage_link = "/Content/relationlist/" + strconv.FormatInt(Cid, 10) + "/"
	Pager.Nums = Total
	Pager.Perpage = Perpage
	Pager.Current_page = Page
	Pager.SubPage_type = 2
	pages := Pager.Show()

	//查询数据
	DB_Read.Where(WhereStr).Limit(int(Perpage), int((Page-1)*Pager.Perpage)).Find(&article_list)

	if len(article_list) > 0 {

		admin := new(Admin)
		category := new(Category)

		for i, v := range article_list {
			article_list[i].Admin = admin.GetById(v.Aid)

			//所属栏目
			article_list[i].Category = category.GetById(v.Cid)
		}
	}

	return article_list, pages, where
}
예제 #5
0
파일: article.go 프로젝트: JREAMLU/GoCMS
//获取内容列表
func (a *Article) GetByAll(search string, Cid int64, Page int64, Perpage int64) (article_arr []*Article, html template.HTML, where map[string]string) {
	article_list := []*Article{}

	//查询条件
	var WhereStr string = " 1 AND `cid`=" + strconv.FormatInt(Cid, 10) + " AND "

	if len(search) > 0 {

		//解码
		where = utils.DecodeSegment(search)

		revel.WARN.Println(where)

		if len(where["start_time"]) > 0 {
			WhereStr += " `createtime`='" + where["start_time"] + "' AND "
		}

		if len(where["start_time"]) > 0 {
			WhereStr += " `createtime`='" + where["end_time"] + "' AND "
		}

		if len(where["istop"]) > 0 {
			WhereStr += " `istop`='" + where["istop"] + "' AND "
		}

		if len(where["searchtype"]) > 0 && len(where["keyword"]) > 0 {

			if where["searchtype"] == "1" {
				//标题
				WhereStr += " `title` like '%" + where["keyword"] + "%' AND "
			} else if where["searchtype"] == "2" {
				//简介
				WhereStr += " `description` like '%" + where["keyword"] + "%' AND "
			} else if where["searchtype"] == "3" {

				//用户名
				Keyword, err := strconv.Atoi(where["keyword"])

				if err != nil {
					admin := new(Admin)
					admin_info := admin.GetByRealName(where["keyword"])

					if admin_info.Id > 0 {
						WhereStr += " `aid`='" + strconv.FormatInt(admin_info.Id, 10) + "' AND "
					}
				} else {
					revel.WARN.Println(Keyword)
					WhereStr += " `aid`='" + where["keyword"] + "' AND "
				}

			} else {
				//ID
				WhereStr += " `id`='" + where["keyword"] + "' AND "
			}
		}
	}

	WhereStr += " 1 "

	//查询总数
	article := new(Article)
	Total, err := DB_Read.Where(WhereStr).Count(article)
	if err != nil {
		revel.WARN.Printf("错误: %v", err)
	}

	//分页
	Pager := new(utils.Page)
	Pager.SubPage_link = "/Content/list/" + strconv.FormatInt(Cid, 10) + "/"
	Pager.Nums = Total
	Pager.Perpage = Perpage
	Pager.Current_page = Page
	Pager.SubPage_type = 2
	pages := Pager.Show()

	//查询数据
	DB_Read.Where(WhereStr).Limit(int(Perpage), int((Page-1)*Pager.Perpage)).Find(&article_list)

	if len(article_list) > 0 {
		admin := new(Admin)
		category := new(Category)

		for i, v := range article_list {
			article_list[i].Admin = admin.GetById(v.Aid)

			//所属栏目
			article_list[i].Category = category.GetById(v.Cid)
		}
	}

	return article_list, pages, where
}
예제 #6
0
파일: logs.go 프로젝트: JREAMLU/GoCMS
//获取日志列表
func (L *Logs) GetByAll(search string, Page int64, Perpage int64) (logs_arr []*Logs, html template.HTML, where map[string]string) {

	logs_list := []*Logs{}

	//查询条件
	var WhereStr string = " 1 AND "

	if len(search) > 0 {
		//解码
		where = utils.DecodeSegment(search)

		revel.WARN.Println(where)

		if len(where["module"]) > 0 {
			WhereStr += " `module`='" + where["module"] + "' AND "
		}

		if len(where["username"]) > 0 {
			admin := new(Admin)
			AdminInfo := admin.GetByName(where["username"])
			WhereStr += " `uid`=" + strconv.Itoa(int(AdminInfo.Id)) + " AND "
		}

		if len(where["realname"]) > 0 {
			admin := new(Admin)
			AdminInfo := admin.GetByRealName(where["realname"])
			WhereStr += " `uid`='" + strconv.Itoa(int(AdminInfo.Id)) + "' AND "
		}

		if len(where["start_time"]) > 0 {
			WhereStr += " `createtime` >='" + where["start_time"] + " 00:00:00' AND "
		}

		if len(where["end_time"]) > 0 {
			WhereStr += " `createtime` <='" + where["end_time"] + " 23:59:59' AND "
		}
	}

	WhereStr += " 1 "

	//查询总数
	logs := new(Logs)
	Total, err := DB_Read.Where(WhereStr).Count(logs)
	if err != nil {
		revel.WARN.Printf("错误: %v", err)
	}

	//分页
	Pager := new(utils.Page)
	if len(search) > 0 {
		Pager.SubPage_link = "/Logs/" + search + "/"
	} else {
		Pager.SubPage_link = "/Logs/"
	}

	Pager.Nums = Total
	Pager.Perpage = Perpage
	Pager.Current_page = Page
	Pager.SubPage_type = 2
	pages := Pager.Show()

	//查询数据
	DB_Read.Where(WhereStr).Limit(int(Perpage), int((Page-1)*Pager.Perpage)).Desc("id").Find(&logs_list)

	if len(logs_list) > 0 {
		admin := new(Admin)

		for i, v := range logs_list {
			logs_list[i].Admin = admin.GetById(v.Uid)
		}
	}

	return logs_list, pages, where
}