CourseController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace app\system\controller;
  3. use app\model\api\CourseModel;
  4. use think\facade\Request;
  5. class CourseController
  6. {
  7. /**
  8. * 获取所有课程列表
  9. */
  10. public function getCourseList()
  11. {
  12. $educationModel = new CourseModel();
  13. $keyword = input('get.course_topic', ''); // 获取模糊查询关键字
  14. $courseList = $educationModel->getCourse($keyword);
  15. $data = ['data' => $courseList];
  16. return app('json')->success($data);
  17. }
  18. /**
  19. * 添加课程
  20. */
  21. public function addCourse()
  22. {
  23. $data = Request::param();
  24. $courseModel = new CourseModel();
  25. $result = $courseModel->addCourse($data);
  26. if ($result) {
  27. return json(['code' => 200, 'msg' => '添加成功', 'data' => $result]);
  28. } else {
  29. return json(['code' => 500, 'msg' => '添加失败', 'data' => '']);
  30. }
  31. }
  32. /**
  33. * 删除课程
  34. */
  35. public function deleteCourse()
  36. {
  37. $course_id = Request::param('course_id');
  38. $courseModel = new CourseModel();
  39. $result = $courseModel->deleteCourse($course_id);
  40. if ($result) {
  41. return json(['code' => 200, 'msg' => '删除成功', 'data' => $result]);
  42. } else {
  43. return json(['code' => 500, 'msg' => '删除失败', 'data' => '']);
  44. }
  45. }
  46. /**
  47. * 查找课程
  48. */
  49. public function searchCourse()
  50. {
  51. $course_id = Request::param('course_id');
  52. $courseModel = new CourseModel();
  53. $result = $courseModel->searchCourse($course_id);
  54. if ($result) {
  55. return json(['code' => 200, 'msg' => '查找成功', 'data' => $result]);
  56. } else {
  57. return json(['code' => 500, 'msg' => '查找失败', 'data' => '']);
  58. }
  59. }
  60. /**
  61. * 修改课程状态
  62. */
  63. public function updateCourseStatus()
  64. {
  65. $course_id = Request::param('course_id');
  66. $course_status = Request::param('course_status');
  67. $courseModel = new CourseModel();
  68. $result = $courseModel->updateCourseStatus($course_id, $course_status);
  69. if ($result) {
  70. return json(['code' => 200, 'msg' => '修改成功', 'data' => $result]);
  71. } else {
  72. return json(['code' => 500, 'msg' => '修改失败', 'data' => '']);
  73. }
  74. }
  75. /**
  76. * 修改课程信息
  77. */
  78. public function updateCourseInfo()
  79. {
  80. $course_id = Request::param('course_id');
  81. $data = Request::param();
  82. $courseModel = new CourseModel();
  83. $result = $courseModel->updateCourseInfo($course_id, $data);
  84. if ($result) {
  85. return json(['code' => 200, 'msg' => '修改成功', 'data' => $result]);
  86. } else {
  87. return json(['code' => 500, 'msg' => '修改失败', 'data' => '']);
  88. }
  89. }
  90. }