CourseModel.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace app\model\api;
  3. use think\facade\Db;
  4. use think\Model;
  5. class CourseModel extends Model
  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 $course_topic
  22. * @param int $page
  23. * @param int $pagesize
  24. * @return mixed
  25. */
  26. public function getCourse($course_topic = '', $page = 1, $pagesize = 10)
  27. {
  28. $query = $this->order('course_id ASC');
  29. if (!empty($course_topic)) {
  30. $query->whereLike('course_topic', '%' . $course_topic . '%');
  31. }
  32. $list = $query->paginate([
  33. 'page' => $page,
  34. 'list_rows' => $pagesize,
  35. ]);
  36. return $list;
  37. }
  38. /**
  39. * 删除课程
  40. * @param $course_id
  41. * @return mixed
  42. */
  43. public function deleteCourse($course_id)
  44. {
  45. $result = Db::table($this->table)->where('course_id', $course_id)->delete();
  46. return $result;
  47. }
  48. /**
  49. * 查找课程
  50. * @param $keyword
  51. * @return mixed
  52. */
  53. public function searchCourse($keyword)
  54. {
  55. $result = Db::table($this->table)->where('title', 'like', '%' . $keyword . '%')->select();
  56. return $result;
  57. }
  58. /**
  59. * 修改课程状态
  60. * @param $course_id
  61. * @param $course_status
  62. * @return mixed
  63. */
  64. public function updateCourseStatus($course_id, $course_status)
  65. {
  66. $result = Db::table($this->table)->where('course_id', $course_id)->update(['status' => $course_status]);
  67. return $result;
  68. }
  69. /**
  70. * 修改课程信息
  71. * @param $course_id
  72. * @param $data
  73. * @return mixed
  74. */
  75. public function updateCourseInfo($course_id, $data)
  76. {
  77. $result = Db::table($this->table)->where('course_id', $course_id)->update($data);
  78. return $result;
  79. }
  80. }