Chapter.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. 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();
  15. }
  16. /**
  17. * 获取章节列表
  18. * @param $bid
  19. * @return mixed
  20. */
  21. public static function getChapterLists($bid){
  22. 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();
  23. }
  24. /**
  25. * 获取章节列表分页
  26. * @param $bid
  27. * @return mixed
  28. */
  29. public static function getChapterListsPage($bid,$page_size=15){
  30. 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);
  31. }
  32. /**
  33. * 获取章节名称
  34. * @param $chapter_id
  35. * @return mixed
  36. */
  37. public static function getChapterNameById($chapter_id){
  38. return self::where('id',$chapter_id)->select('id','bid','name','sequence','size','is_vip','prev_cid','next_cid','recent_update_at')->first();
  39. }
  40. /**
  41. * 获取前5章内容
  42. * @param $bid
  43. * @return mixed
  44. */
  45. public static function getTopFiveChapter($bid){
  46. $limit = 8;
  47. return self::where('bid',$bid)->select('id','bid','name','sequence','size','is_vip','prev_cid','next_cid','recent_update_at','content','ly_chapter_id')
  48. ->orderBy('sequence','asc')->limit($limit)->get();
  49. }
  50. /**
  51. * 修改vip章节
  52. * @param $bid
  53. * @return mixed
  54. */
  55. public static function editVip($bid,$seq){
  56. $res1 = self::where('bid',$bid)->where('sequence','>=',$seq)->update(['is_vip'=>1]);
  57. $res2 = self::where('bid',$bid)->where('sequence','<',$seq)->update(['is_vip'=>0]);
  58. return $res1 && $res2;
  59. }
  60. /**
  61. * 获取章节分页 有章节内容,仅供后台使用后台
  62. * @param $bid
  63. * @return mixed
  64. */
  65. public static function getChapterPage($bid,$page_size=15){
  66. 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);
  67. }
  68. }