删除书籍.
()
| 477 | |
| 478 | // 删除书籍. |
| 479 | func (this *ManagerController) DeleteBook() { |
| 480 | var bookIds []int |
| 481 | beego.Debug(this.Ctx.Request.Form) |
| 482 | if ids, ok := this.Ctx.Request.Form["book_id"]; ok { |
| 483 | for _, id := range ids { |
| 484 | if v, _ := strconv.Atoi(id); v > 0 { |
| 485 | bookIds = append(bookIds, v) |
| 486 | } |
| 487 | } |
| 488 | } |
| 489 | if len(bookIds) <= 0 { |
| 490 | this.JsonResult(6001, "参数错误") |
| 491 | } |
| 492 | |
| 493 | //用户密码 |
| 494 | pwd := this.GetString("password") |
| 495 | if m, err := models.NewMember().Login(this.Member.Account, pwd); err != nil || m.MemberId == 0 { |
| 496 | this.JsonResult(1, "书籍删除失败,您的登录密码不正确") |
| 497 | } |
| 498 | identify := strings.TrimSpace(this.GetString("identify")) |
| 499 | book := models.NewBook() |
| 500 | client := models.NewElasticSearchClient() |
| 501 | for _, bookID := range bookIds { |
| 502 | if identify != "" { |
| 503 | if b, _ := book.FindByIdentify(identify, "book_id"); b.BookId != bookID { |
| 504 | this.JsonResult(6002, "书籍标识输入不正确") |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | err := book.ThoroughDeleteBook(bookID) |
| 509 | if err == orm.ErrNoRows { |
| 510 | this.JsonResult(6002, "书籍不存在") |
| 511 | } |
| 512 | if err != nil { |
| 513 | logs.Error("DeleteBook => ", err) |
| 514 | this.JsonResult(6003, "删除失败") |
| 515 | } |
| 516 | if errDel := client.DeleteIndex(bookID, true); errDel != nil && client.On { |
| 517 | beego.Error(errDel.Error()) |
| 518 | } |
| 519 | } |
| 520 | go models.CountCategory() |
| 521 | this.JsonResult(0, "书籍删除成功") |
| 522 | } |
| 523 | |
| 524 | // CreateToken 创建访问来令牌. |
| 525 | func (this *ManagerController) CreateToken() { |
nothing calls this directly
no test coverage detected