Chapter.php 2.7 KB

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