CourseModel.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace app\model\api;
  3. use think\facade\Db;
  4. use think\model;
  5. class CourseModel
  6. {
  7. protected $table = 'table_education_course';
  8. /**
  9. * 添加课程
  10. * @param $data
  11. * @return mixed
  12. */
  13. public function addCourse($data)
  14. {
  15. $result = Db::table($this->table)->insert($data);
  16. return $result;
  17. }
  18. /**
  19. * 获取所有课程
  20. *
  21. * @param string $keyword 模糊查询关键字
  22. * @return mixed
  23. */
  24. public function getCourse($keyword = '')
  25. {
  26. $query = Db::table($this->table)
  27. ->order('course_create_time', 'desc')
  28. ->field('course_id, course_topic, course_speaker, course_speaker_intro, course_price, course_play_count, course_create_time, course_audit, course_cover');
  29. if (!empty($keyword)) {
  30. $query->where('course_topic', 'like', "%{$keyword}%");
  31. }
  32. $courseList = $query->select();
  33. return $courseList;
  34. }
  35. /**
  36. * 删除课程
  37. * @param $course_id
  38. * @return mixed
  39. */
  40. public function deleteCourse($course_id)
  41. {
  42. $result = Db::table($this->table)->where('course_id', $course_id)->delete();
  43. return $result;
  44. }
  45. /**
  46. * 查找课程
  47. * @param $keyword
  48. * @return mixed
  49. */
  50. public function searchCourse($keyword)
  51. {
  52. $result = Db::table($this->table)->where('title', 'like', '%' . $keyword . '%')->select();
  53. return $result;
  54. }
  55. /**
  56. * 修改课程状态
  57. * @param $course_id
  58. * @param $course_status
  59. * @return mixed
  60. */
  61. public function updateCourseStatus($course_id, $course_status)
  62. {
  63. $result = Db::table($this->table)->where('course_id', $course_id)->update(['status' => $course_status]);
  64. return $result;
  65. }
  66. /**
  67. * 修改课程信息
  68. * @param $course_id
  69. * @param $data
  70. * @return mixed
  71. */
  72. public function updateCourseInfo($course_id, $data)
  73. {
  74. $result = Db::table($this->table)->where('course_id', $course_id)->update($data);
  75. return $result;
  76. }
  77. }