//设置封面 func (this *PhotoController) Cover() { id, _ := this.GetInt64("albumid") cover := this.GetString("cover") album := models.Album{Id: id, Cover: cover} album.Update("cover") this.Redirect("/admin/album/list", 302) }
//删除相册 func (this *AlbumController) Delete() { id, _ := this.GetInt64("albumid") album := models.Album{Id: id} h, _ := strconv.Atoi(this.GetString("ishide")) album.Ishide = int8(h) if err := album.Update("ishide"); err != nil { this.showmsg(err.Error()) return } this.Redirect("/admin/album/list", 302) }
//相册展示 func (this *MainController) Album() { pagesize, _ := strconv.Atoi(this.getOption("albumsize")) if pagesize < 1 { pagesize = 12 } var list []*models.Album query := new(models.Album).Query().Filter("ishide", 0) count, _ := query.Count() if count > 0 { query.OrderBy("-rank", "-posttime").Limit(pagesize, (this.page-1)*pagesize).All(&list) } this.setHeadMetas("摄影作品") this.right = "" this.Data["list"] = list this.Data["pagebar"] = models.NewPager(int64(this.page), int64(count), int64(pagesize), "/album%d.html").ToString() this.display("album") }
//照片展示 func (this *MainController) Photo() { album := new(models.Album) album.Id = int64(this.page) err := album.Read() if err != nil || album.Ishide != 0 { this.Redirect("/404.html", 302) } this.setHeadMetas("相册 " + album.Name + " 内的照片") var list []*models.Photo new(models.Photo).Query().Filter("albumid", this.page).All(&list) this.right = "" for _, v := range list { v.Small = strings.Replace(v.Url, "bigpic", "smallpic", 1) } this.Data["list"] = list this.display("photo") }
//相册列表 func (this *AlbumController) List() { var page int64 var pagesize int64 = 6 var list []*models.Album var album models.Album if page, _ = this.GetInt64("page"); page < 1 { page = 1 } offset := (page - 1) * pagesize query := album.Query() count, _ := query.Count() if count > 0 { query.OrderBy("-rank", "-posttime").Limit(pagesize, offset).All(&list) } this.Data["list"] = list this.Data["pagebar"] = models.NewPager(page, count, pagesize, "/admin/album/list?page=%d").ToString() this.display() }
//修改 func (this *AlbumController) Edit() { id, _ := this.GetInt64("albumid") album := models.Album{Id: id} if album.Read() != nil { this.Abort("404") } if this.Ctx.Request.Method == "POST" { rank, _ := this.GetInt("rank") album.Cover = this.GetString("cover") album.Name = this.GetString("albumname") album.Rank = int8(rank) album.Update() this.Redirect("/admin/album/list", 302) } this.Data["album"] = album this.display() }
//创建相册 func (this *AlbumController) Add() { if this.Ctx.Request.Method == "POST" { rank, _ := this.GetInt("rank") var album models.Album album.Name = strings.TrimSpace(this.GetString("albumname")) album.Cover = strings.TrimSpace(this.GetString("cover")) album.Rank = int8(rank) album.Posttime = time.Now() if err := album.Insert(); err != nil { this.showmsg(err.Error()) } this.Redirect("/admin/album/list", 302) } this.display() }