BookConfigService.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace App\Modules\Book\Services;
  3. use App\Modules\Book\BookConfig;
  4. use App\Modules\Book\Book;
  5. use Redis;
  6. use DB;
  7. class BookConfigService
  8. {
  9. /**
  10. * 根据id获取图书
  11. * @param $bid
  12. * @return mixed
  13. */
  14. public static function getBookById($bid)
  15. {
  16. $res = BookConfig::getBookById($bid);
  17. return $res;
  18. }
  19. /**
  20. * 根据bid数组获取多本图书
  21. * @param $where
  22. * @param null $order
  23. * @return mixed
  24. */
  25. public static function getBooksByIds(array $where, $order = [],$is_on_shelf = '')
  26. {
  27. if(empty($where)){
  28. return (object)array();
  29. }
  30. if ($order)
  31. $res = BookConfig::getBooksByIds($where, $order,$is_on_shelf);
  32. else
  33. $res = BookConfig::getBooksByIds($where,$order,$is_on_shelf);
  34. return $res;
  35. }
  36. //阅读记录用到的图书信息 bid cover last_chapter
  37. public static function getBookSimpleInfoFroReadRecord(array $bid){
  38. return BookConfig::join('books', 'book_configs.bid', '=', 'books.id')
  39. ->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
  40. ->select('book_configs.bid', 'book_configs.cover', 'book_configs.book_name', 'books.chapter_count','books.last_chapter','book_categories.channel_name')
  41. ->whereIn('book_configs.bid', $bid)
  42. ->get();
  43. }
  44. public static function getBookSimpleInfoByBidAndFields($bid,$field){
  45. return BookConfig::join('books', 'book_configs.bid', '=', 'books.id')
  46. ->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
  47. ->select($field)
  48. ->where('book_configs.bid', $bid)
  49. ->first();
  50. }
  51. /**
  52. *
  53. * 根据条件获取图书
  54. * @param array $where ['key'=>'根据关键词查询','category_id'=>'根据分类id查询','is_on_shelf'=>上下架查询,'channel_name'=>'频道查询(男频女频)']
  55. * @param array $order 排序 默认是bid排序
  56. * @param int $page_size
  57. * @return mixed
  58. */
  59. public static function getBooks(array $where, array $order = [], $page_size = 15)
  60. {
  61. return BookConfig::getBooks($where, $order, $page_size);
  62. }
  63. }