Bookshelf.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\main\constants\BookConstants;
  5. use app\main\constants\ErrorCodeConstants;
  6. use app\main\service\BookService;
  7. use think\Cookie;
  8. class Bookshelf extends Api
  9. {
  10. public function _initialize()
  11. {
  12. parent::_initialize();
  13. }
  14. public function insert()
  15. {
  16. $bookId = $this->request->post('book_id');
  17. $chapterId = $this->request->post('chapter_id', 0);
  18. $idx = $this->request->post('idx', 0);
  19. if (!Cookie::has('user_id')) {
  20. $this->error('用户没有登录');
  21. }
  22. $result = BookService::instance()->setBookShelf($bookId);
  23. if ($result->code == ErrorCodeConstants::SUCCESS) {
  24. $this->success();
  25. } else {
  26. $this->error($result->msg);
  27. }
  28. }
  29. public function delbooks(){
  30. if ($this->request->isAjax()) {
  31. $bookIds = $this->request->post('bookIds');
  32. $bookArr = \GuzzleHttp\json_decode($bookIds, true);
  33. $data = BookService::instance()->delBookShelf($bookArr);
  34. return json(['err' => 0]);
  35. }
  36. }
  37. }