Delete 删除书籍.
()
| 761 | |
| 762 | // Delete 删除书籍. |
| 763 | func (this *BookController) Delete() { |
| 764 | |
| 765 | bookResult, err := this.IsPermission() |
| 766 | if err != nil { |
| 767 | this.JsonResult(6001, err.Error()) |
| 768 | } |
| 769 | |
| 770 | if bookResult.RoleId != conf.BookFounder { |
| 771 | this.JsonResult(6002, "只有创始人才能删除书籍") |
| 772 | } |
| 773 | |
| 774 | //用户密码 |
| 775 | pwd := this.GetString("password") |
| 776 | if m, err := models.NewMember().Login(this.Member.Account, pwd); err != nil || m.MemberId == 0 { |
| 777 | this.JsonResult(1, "书籍删除失败,您的登录密码不正确") |
| 778 | } |
| 779 | |
| 780 | err = models.NewBook().ThoroughDeleteBook(bookResult.BookId) |
| 781 | if err == orm.ErrNoRows { |
| 782 | this.JsonResult(6002, "书籍不存在") |
| 783 | } |
| 784 | |
| 785 | if err != nil { |
| 786 | logs.Error("删除书籍 => ", err) |
| 787 | this.JsonResult(6003, "删除失败") |
| 788 | } |
| 789 | |
| 790 | go func() { |
| 791 | client := models.NewElasticSearchClient() |
| 792 | if errDel := client.DeleteIndex(bookResult.BookId, true); errDel != nil && client.On { |
| 793 | beego.Error(errDel.Error()) |
| 794 | } |
| 795 | }() |
| 796 | go models.CountCategory() |
| 797 | this.JsonResult(0, "ok") |
| 798 | } |
| 799 | |
| 800 | // 发布书籍. |
| 801 | func (this *BookController) Release() { |
no test coverage detected