Chapter.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace App\Modules\Book\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Chapter extends Model
  5. {
  6. protected $table = 'chapters';
  7. protected $fillable = ['bid', 'name', 'sequence', 'size', 'is_vip', 'prev_cid', 'next_cid', 'recent_update_at', 'content', 'ly_chapter_id'];
  8. /**
  9. * 获取章节内容
  10. * @param $chapter_id
  11. * @return mixed
  12. */
  13. public static function getChapterById($chapter_id)
  14. {
  15. return self::where('id', $chapter_id)->select('id', 'bid', 'name', 'sequence', 'size', 'is_vip', 'prev_cid', 'next_cid', 'recent_update_at', 'content', 'ly_chapter_id')->first();
  16. }
  17. /**
  18. * 获取章节列表
  19. * @param $bid
  20. * @return mixed
  21. */
  22. public static function getChapterLists($bid)
  23. {
  24. return self::where('bid', $bid)->select('id', 'bid', 'name', 'sequence', 'size', 'is_vip', 'prev_cid', 'next_cid', 'recent_update_at', 'ly_chapter_id')->orderBy('sequence', 'asc')->get();
  25. }
  26. /**
  27. * 获取章节列表分页
  28. * @param $bid
  29. * @return mixed
  30. */
  31. public static function getChapterListsPage($bid, $page_size = 15)
  32. {
  33. return self::where('bid', $bid)->select('id', 'bid', 'name', 'sequence', 'size', 'is_vip', 'prev_cid', 'next_cid', 'recent_update_at', 'ly_chapter_id')->orderBy('sequence', 'asc')->paginate($page_size);
  34. }
  35. /**
  36. * 获取章节名称
  37. * @param $chapter_id
  38. * @return mixed
  39. */
  40. public static function getChapterNameById($chapter_id)
  41. {
  42. return self::where('id', $chapter_id)->select('id', 'bid', 'name', 'sequence', 'size', 'is_vip', 'prev_cid', 'next_cid', 'recent_update_at')->first();
  43. }
  44. /**
  45. * 获取前5章内容
  46. * @param $bid
  47. * @return mixed
  48. */
  49. public static function getTopFiveChapter($bid)
  50. {
  51. $limit = 8;
  52. return self::where('bid', $bid)->select('id', 'bid', 'name', 'sequence', 'size', 'is_vip', 'prev_cid', 'next_cid', 'recent_update_at', 'content', 'ly_chapter_id')
  53. ->orderBy('sequence', 'asc')->limit($limit)->get();
  54. }
  55. /**
  56. * 修改vip章节
  57. * @param $bid
  58. * @return mixed
  59. */
  60. public static function editVip($bid, $seq)
  61. {
  62. $res1 = self::where('bid', $bid)->where('sequence', '>=', $seq)->update(['is_vip' => 1]);
  63. $res2 = self::where('bid', $bid)->where('sequence', '<', $seq)->update(['is_vip' => 0]);
  64. return $res1 && $res2;
  65. }
  66. /**
  67. * 获取章节分页 有章节内容,仅供后台使用后台
  68. * @param $bid
  69. * @return mixed
  70. */
  71. public static function getChapterPage($bid, $page_size = 15)
  72. {
  73. return self::where('bid', $bid)->select('id', 'bid', 'name', 'sequence', 'size', 'is_vip', 'prev_cid', 'next_cid', 'recent_update_at', 'ly_chapter_id', 'content')->orderBy('sequence', 'asc')->paginate($page_size);
  74. }
  75. /**
  76. * 获取章节
  77. * @param $bid
  78. * @return mixed
  79. */
  80. public static function getChapterByBidAndSeq($bid, $seq)
  81. {
  82. return self::where('bid', $bid)->where('sequence', $seq)->first();
  83. }
  84. }