SuperiorNewBooks.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\Modules\Book\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class SuperiorNewBooks extends Model
  5. {
  6. protected $table = 'superior_new_book';
  7. protected $fillable = ['id','bid', 'pid', 'category_id','status','created_at','updated_at','recommend_index','order_index'];
  8. public static function getSuperiorTotal($pid) {
  9. return self::where([['status','=',1],['pid','=',$pid]])->count('id');
  10. }
  11. public static function getLastSuperiorItem($pid) {
  12. return self::where([['status','=',1],['pid','=',$pid]])
  13. ->orderBy('created_at','asc')
  14. ->first();
  15. }
  16. public static function getSuperiorList($pid,$serach=[]){
  17. $filter = [
  18. ['superior_new_book.status','=',1],
  19. ['book_configs.is_on_shelf','>=',1],
  20. ['book_configs.is_on_shelf','<=',2]
  21. ];
  22. if($pid){
  23. $filter[] = ['superior_new_book.pid','=',$pid];
  24. }
  25. if($serach){
  26. $filter = array_merge($filter,$serach);
  27. }
  28. return self::where($filter)
  29. ->select(['superior_new_book.id','superior_new_book.bid','superior_new_book.recommend_index','superior_new_book.pid','superior_new_book.order_index','book_configs.book_name'])
  30. ->join('book_configs','book_configs.bid','=','superior_new_book.bid')
  31. //->join('books','books.id','=','superior_new_book.bid')
  32. ->orderBy('superior_new_book.order_index','desc')
  33. ->orderBy('superior_new_book.recommend_index','desc')
  34. ->get();
  35. }
  36. }