コード例 #1
0
ファイル: admin.go プロジェクト: zacklin923/GoCMS
//根据Id获取管理员信息
func (a *Admin) GetById(Id int64) *Admin {
	admin := new(Admin)
	//返回的结果为两个参数,一个has为该条记录是否存在,
	//第二个参数err为是否有错误。不管err是否为nil,has都有可能为true或者false。
	has, err := DB_Read.Id(Id).Get(admin)

	if err != nil {
		revel.WARN.Println(has)
		revel.WARN.Printf("错误: %v", err)
	} else {
		role := new(Role)
		admin.Role = role.GetById(admin.Roleid)
		admin.LastipAddress = utils.GetIpAddress(admin.Lastloginip)
	}

	return admin
}
コード例 #2
0
ファイル: logs.go プロジェクト: zacklin923/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
}