LifeBookCourse.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 LifeBookCourse extends Model
  11. {
  12. const IS_DEL_YES = 1;
  13. const IS_DEL_NO = 0;
  14. const COURSE_IS_SHOW = [
  15. self::IS_DEL_YES => '已删除',
  16. self::IS_DEL_NO => '未删除'
  17. ];
  18. /**
  19. * The table associated with the model.
  20. *
  21. * @var string
  22. */
  23. protected $table = 'life_book_course';
  24. public $timestamps = false;
  25. /**
  26. * Notes:获取课程目录列表
  27. * @param string $keywords
  28. * @param int $page
  29. * @param int $limit
  30. * @return array
  31. * User: ZQ
  32. * Date: 2022/10/14
  33. */
  34. public static function getBookCourseList(int $page, int $limit, string $keywords)
  35. {
  36. $list = static::select(['life_book_course.*','life_book.life_book_name'])
  37. ->where(['course_is_del'=>static::IS_DEL_NO])
  38. ->when($keywords != '', function ($query) use ($keywords){
  39. $query->where('course_name', 'like', '%' . $keywords . '%');
  40. })
  41. ->leftJoin('life_book','life_book_id','=','life_book_course.course_book_id')
  42. ->orderBy('course_create_time','DESC')
  43. ->forPage($page, $limit)
  44. ->get();
  45. $count = static::where(['course_is_del'=>static::IS_DEL_NO])
  46. ->when($keywords != '', function ($query) use ($keywords){
  47. $query->where('course_name', 'like', '%' . $keywords . '%');
  48. })
  49. ->count();
  50. return [$list, $count];
  51. }
  52. /**
  53. * Notes:获取所有课程
  54. * @return array
  55. * User: ZQ
  56. * Date: 2022/10/14
  57. */
  58. public static function getBookAll()
  59. {
  60. $list = static::select(['course_id','course_name'])
  61. ->where(['course_is_del'=>static::IS_DEL_NO])
  62. ->orderBy('course_create_time','DESC')
  63. ->get();
  64. return $list;
  65. }
  66. /**
  67. * Notes:获取课程目录名称
  68. * @param string $account
  69. * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
  70. * User: ZQ
  71. * Date: 2022/10/14
  72. */
  73. public static function courseMation($admin_cinema)
  74. {
  75. $where = [];
  76. $where['course_is_del'] = static::IS_DEL_NO;
  77. $mation = static::where($where)
  78. ->when($admin_cinema != '', function ($query) use ($admin_cinema){
  79. $query->whereIn('course_id', $admin_cinema);
  80. })
  81. ->get('course_name');
  82. return $mation;
  83. }
  84. }