LifeBook.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace app\admin\model;
  3. use support\Db;
  4. use support\Model;
  5. /**
  6. * 万悦书院模型
  7. * Class Users
  8. * @package app\admin\model
  9. */
  10. class LifeBook extends Model
  11. {
  12. const ROLE_STATUS = 1;
  13. const IS_DEL_YES = 1;
  14. const IS_DEL_NO = 0;
  15. const BOOK_IS_SHOW = [
  16. self::IS_DEL_YES => '已删除',
  17. self::IS_DEL_NO => '未删除'
  18. ];
  19. /**
  20. * The table associated with the model.
  21. *
  22. * @var string
  23. */
  24. protected $table = 'life_book';
  25. public $timestamps = false;
  26. /**
  27. * Notes:获取课程列表
  28. * @param string $keywords
  29. * @param int $page
  30. * @param int $limit
  31. * @return array
  32. * User: ZQ
  33. * Date: 2022/10/14
  34. */
  35. public static function getBookList(int $page, int $limit, string $keywords)
  36. {
  37. $list = static::select(['life_book.*','category.category_name','teacher.teacher_name'])
  38. ->where(['life_book_is_del'=>static::IS_DEL_NO])
  39. ->when($keywords != '', function ($query) use ($keywords){
  40. $query->where('life_book_name', 'like', '%' . $keywords . '%');
  41. })
  42. ->leftJoin('category','category_id','=','life_book.life_book_category_id')
  43. ->leftJoin('teacher','teacher_id','=','life_book.life_book_teacher_id')
  44. ->orderBy('life_book_create_time','DESC')
  45. ->forPage($page, $limit)
  46. ->get();
  47. $count = static::where(['life_book_is_del'=>static::IS_DEL_NO])
  48. ->when($keywords != '', function ($query) use ($keywords){
  49. $query->where('life_book_name', 'like', '%' . $keywords . '%');
  50. })
  51. ->count();
  52. return [$list, $count];
  53. }
  54. /**
  55. * Notes:获取所有课程
  56. * @return array
  57. * User: ZQ
  58. * Date: 2022/10/14
  59. */
  60. public static function getBookAll()
  61. {
  62. $list = static::select(['life_book_id','life_book_name'])
  63. ->where(['life_book_is_del'=>static::IS_DEL_NO])
  64. ->orderBy('life_book_create_time','DESC')
  65. ->get();
  66. return $list;
  67. }
  68. /**
  69. * Notes:获取课程名称
  70. * @param string $account
  71. * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
  72. * User: ZQ
  73. * Date: 2022/10/14
  74. */
  75. public static function bookMation($admin_cinema)
  76. {
  77. $where = [];
  78. $where['life_book_is_del'] = static::IS_DEL_NO;
  79. $mation = static::where($where)
  80. ->when($admin_cinema != '', function ($query) use ($admin_cinema){
  81. $query->whereIn('life_book_id', $admin_cinema);
  82. })
  83. ->get('life_book_name');
  84. return $mation;
  85. }
  86. }