15 Star 61 Fork 10

e9ab98e991ab/GoBooks

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
UserController.go 4.26 KB
一键复制 编辑 原始数据 按行查看 历史
高鑫 提交于 2020-01-03 09:39 +08:00 . commit
package controllers
import (
"gitee.com/Godfeer/GoBooks/conf"
"gitee.com/Godfeer/GoBooks/models"
"gitee.com/Godfeer/GoBooks/utils"
"github.com/astaxie/beego"
)
type UserController struct {
BaseController
UcenterMember models.Member
}
func (this *UserController) Prepare() {
this.BaseController.Prepare()
username := this.GetString(":username")
this.UcenterMember, _ = new(models.Member).GetByUsername(username)
if this.UcenterMember.MemberId == 0 {
this.Abort("404")
return
}
this.Data["IsSelf"] = this.UcenterMember.MemberId == this.Member.MemberId
this.Data["User"] = this.UcenterMember
this.Data["Tab"] = "share"
}
//首页
func (this *UserController) Index() {
page, _ := this.GetInt("page")
pageSize := 10
if page < 1 {
page = 1
}
books, totalCount, _ := models.NewBook().FindToPager(page, pageSize, this.UcenterMember.MemberId, 0)
this.Data["Books"] = books
if totalCount > 0 {
html := utils.NewPaginations(conf.RollPage, totalCount, pageSize, page, beego.URLFor("UserController.Index", ":username", this.UcenterMember.Account), "")
this.Data["PageHtml"] = html
} else {
this.Data["PageHtml"] = ""
}
this.Data["Total"] = totalCount
this.GetSeoByPage("ucenter-share", map[string]string{
"title": "分享 - " + this.UcenterMember.Nickname,
"keywords": "用户主页," + this.UcenterMember.Nickname,
"description": this.Sitename + "专注于文档在线写作、协作、分享、阅读与托管,让每个人更方便地发布、分享和获得知识。",
})
this.TplName = "user/index.html"
}
//收藏
func (this *UserController) Collection() {
page, _ := this.GetInt("page")
pageSize := 10
if page < 1 {
page = 1
}
totalCount, books, _ := new(models.Star).List(this.UcenterMember.MemberId, page, pageSize)
this.Data["Books"] = books
if totalCount > 0 {
html := utils.NewPaginations(conf.RollPage, int(totalCount), pageSize, page, beego.URLFor("UserController.Collection", ":username", this.UcenterMember.Account), "")
this.Data["PageHtml"] = html
} else {
this.Data["PageHtml"] = ""
}
this.GetSeoByPage("ucenter-collection", map[string]string{
"title": "收藏 - " + this.UcenterMember.Nickname,
"keywords": "用户收藏," + this.UcenterMember.Nickname,
"description": this.Sitename + "专注于文档在线写作、协作、分享、阅读与托管,让每个人更方便地发布、分享和获得知识。",
})
this.Data["Total"] = totalCount
this.Data["Tab"] = "collection"
this.TplName = "user/collection.html"
}
//关注
func (this *UserController) Follow() {
page, _ := this.GetInt("page")
pageSize := 18
if page < 1 {
page = 1
}
fans, totalCount, _ := new(models.Fans).GetFollowList(this.UcenterMember.MemberId, page, pageSize)
if totalCount > 0 {
html := utils.NewPaginations(conf.RollPage, int(totalCount), pageSize, page, beego.URLFor("UserController.Follow", ":username", this.UcenterMember.Account), "")
this.Data["PageHtml"] = html
} else {
this.Data["PageHtml"] = ""
}
this.GetSeoByPage("ucenter-follow", map[string]string{
"title": "关注 - " + this.UcenterMember.Nickname,
"keywords": "用户关注," + this.UcenterMember.Nickname,
"description": this.Sitename + "专注于文档在线写作、协作、分享、阅读与托管,让每个人更方便地发布、分享和获得知识。",
})
this.Data["Fans"] = fans
this.Data["Tab"] = "follow"
this.TplName = "user/fans.html"
}
//粉丝和关注
func (this *UserController) Fans() {
page, _ := this.GetInt("page")
pageSize := 18
if page < 1 {
page = 1
}
fans, totalCount, _ := new(models.Fans).GetFansList(this.UcenterMember.MemberId, page, pageSize)
if totalCount > 0 {
html := utils.NewPaginations(conf.RollPage, int(totalCount), pageSize, page, beego.URLFor("UserController.Fans", ":username", this.UcenterMember.Account), "")
this.Data["PageHtml"] = html
} else {
this.Data["PageHtml"] = ""
}
this.GetSeoByPage("ucenter-fans", map[string]string{
"title": "粉丝 - " + this.UcenterMember.Nickname,
"keywords": "用户粉丝," + this.UcenterMember.Nickname,
"description": this.Sitename + "专注于文档在线写作、协作、分享、阅读与托管,让每个人更方便地发布、分享和获得知识。",
})
this.Data["Fans"] = fans
this.Data["Tab"] = "fans"
this.TplName = "user/fans.html"
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/Godfeer/GoBooks.git
git@gitee.com:Godfeer/GoBooks.git
Godfeer
GoBooks
GoBooks
cbd8ecaa8838

搜索帮助