Book.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Modules\Book\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Book extends Model
  5. {
  6. protected $table = 'books';
  7. protected $fillable = ['ly_bid','name','author','intro','cover','category_name','keyword',
  8. 'category_id','status','chapter_count','first_cid','last_cid','size','last_chapter','sequence'];
  9. /**
  10. * 获取分类id
  11. * @return array
  12. */
  13. public static function getCategoryId(){
  14. $res = self::select('category_id')->distinct()->get()->toArray();
  15. $data = [];
  16. foreach ($res as $v){
  17. array_push($data,$v['category_id']);
  18. }
  19. return $data;
  20. }
  21. /**
  22. * 获取book
  23. * @return array
  24. */
  25. public static function getBook($bid){
  26. $res = self::select('*')->where('id',$bid)->first();
  27. return $res;
  28. }
  29. /**
  30. * @param $bids
  31. * @return mixed
  32. */
  33. public static function getBooksByIds($bids)
  34. {
  35. if (empty($bids)) {
  36. return [];
  37. }
  38. return self::whereIn('id', $bids)->get();
  39. }
  40. }