コード例 #1
0
ファイル: comment.go プロジェクト: blackmady/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
ファイル: focus.go プロジェクト: blackmady/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
}
コード例 #3
0
ファイル: logs.go プロジェクト: blackmady/GoCMS
//获取日志列表
func (L *Logs) GetByAll(search string, Page int64, Perpage int64) (logs_arr []*Logs, html template.HTML, where map[string]interface{}) {

	logs_list := []*Logs{}

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

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

		revel.WARN.Println(where)

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

		if where["username"] != "" {
			admin := new(Admin)
			AdminInfo := admin.GetByName(fmt.Sprintf("%s", where["username"]))
			WhereStr += " `uid`=" + strconv.Itoa(int(AdminInfo.Id)) + " AND "
		}

		if where["realname"] != "" {
			admin := new(Admin)
			AdminInfo := admin.GetByRealName(fmt.Sprintf("%s", where["realname"]))
			WhereStr += " `uid`='" + strconv.Itoa(int(AdminInfo.Id)) + "' AND "
		}

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

		if where["end_time"] != "" {
			WhereStr += " `createtime` <='" + fmt.Sprintf("%s", 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)
			logs_list[i].IpAddress = utils.GetIpAddress(v.Ip)
		}
	}

	return logs_list, pages, where
}
コード例 #4
0
ファイル: article.go プロジェクト: blackmady/GoCMS
//获取内容列表
func (a *Article) GetByList(Cid int64, Search string, Page int64, Perpage int64) (article_arr []*Article, html template.HTML, where map[string]interface{}) {
	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`='" + fmt.Sprintf("%s", where["cid"]) + "' AND "
		}

		if where["field"] != "" && where["keyword"] != "" {

			if where["field"] == "title" {
				//标题
				WhereStr += " `title` like %'" + fmt.Sprintf("%s", where["keyword"]) + "'% AND "

			} else if where["field"] == "keywords" {
				//关键词
				WhereStr += " `keywords` like %'" + fmt.Sprintf("%s", where["keyword"]) + "'% AND "
			} else if where["field"] == "description" {
				//描述
				WhereStr += " `description` like %'" + fmt.Sprintf("%s", where["keyword"]) + "'% AND "
			} else if where["field"] == "id" {
				//ID
				WhereStr += " `id`='" + fmt.Sprintf("%s", 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)).Desc("id").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 プロジェクト: blackmady/GoCMS
//获取内容列表
func (a *Article) GetByAll(search string, Cid int64, Page int64, Perpage int64) (article_arr []*Article, html template.HTML, where map[string]interface{}) {
	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 where["start_time"] != "" {
			WhereStr += " `createtime`='" + fmt.Sprintf("%s", where["start_time"]) + "' AND "
		}

		if where["start_time"] != "" {
			WhereStr += " `createtime`='" + fmt.Sprintf("%s", where["end_time"]) + "' AND "
		}

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

		if where["searchtype"] != "" && where["keyword"] != "" {

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

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

				revel.WARN.Println(Keyword)

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

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

			} else {
				//ID
				WhereStr += " `id`='" + fmt.Sprintf("%s", 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)).Desc("id").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
ファイル: user.go プロジェクト: blackmady/GoCMS
//获取会员列表
func (u *User) GetUserList(search string, Page int64, Perpage int64) (user_arr []*User, html template.HTML, where map[string]interface{}) {
	//初始化菜单
	user_list := []*User{}

	//查询条件
	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 "
		}

		if where["end_time"] != "" {
			WhereStr += " `regdate` <='" + fmt.Sprintf("%s", where["end_time"]) + " 23:59:59' AND "
		}

		if where["islock"] != "" && where["islock"] != "0" {
			WhereStr += " `islock` =" + fmt.Sprintf("%s", where["islock"])
		}

		if where["type"] != "" && where["keyword"] != "" {

			if where["type"] == "1" {
				//用户名
				WhereStr += " `username` ='" + fmt.Sprintf("%s", where["keyword"]) + "' AND "
			} else if where["type"] == "2" {
				//用户ID
				WhereStr += " `id` =" + fmt.Sprintf("%s", where["keyword"]) + " AND "
			} else if where["type"] == "3" {
				//邮箱
				WhereStr += " `email` ='" + fmt.Sprintf("%s", where["keyword"]) + "' AND "
			} else if where["type"] == "4" {
				//注册ip
				WhereStr += " `regip` ='" + fmt.Sprintf("%s", where["keyword"]) + "' AND "
			} else if where["type"] == "5" {
				//昵称
				WhereStr += " `nickname` like '%" + fmt.Sprintf("%s", 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
}