ZxcZxc123 2 years ago
parent
commit
6887159324
2 changed files with 72 additions and 39 deletions
  1. 71 38
      app/api/controller/Education.php
  2. 1 1
      app/api/route/education.php

+ 71 - 38
app/api/controller/Education.php

@@ -44,44 +44,44 @@ class Education
     }
 
 
-    /**
-     * 获取课程详情
-     * @param $gr_id
-     * @return mixed
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\DbException
-     * @throws \think\db\exception\ModelNotFoundException
-     */
-    public function getCourseDetail($gr_id)
-    {
-        $course = EducationCourse::where('gr_id', $gr_id)
-            ->where('course_status', 1)
-            ->where('course_audit', 1)
-            ->find();
-
-        if (!$course) {
-            return app('json')->fail('课程不存在');
-        }
-
-        $course = $course->toArray();
-
-        $education = \app\model\api\Education::where('gr_id', $course['gr_id'])
-            ->where('audit', 1)
-            ->find();
-
-        if (!$education) {
-            return app('json')->fail('课程不存在或未通过审核');
-        }
-
-        $education = $education->toArray();
-
-        $course['edu_name'] = $education['name'];
-        $course['edu_logo'] = $education['logo'];
-        $course['edu_type1'] = $education['type1'];
-        $course['edu_type2'] = $education['type2'];
-
-        return app('json')->success($course);
-    }
+//    /**
+//     * 获取课程详情
+//     * @param $gr_id
+//     * @return mixed
+//     * @throws \think\db\exception\DataNotFoundException
+//     * @throws \think\db\exception\DbException
+//     * @throws \think\db\exception\ModelNotFoundException
+//     */
+//    public function getCourseDetail($gr_id)
+//    {
+//        $course = EducationCourse::where('gr_id', $gr_id)
+//            ->where('course_status', 1)
+//            ->where('course_audit', 1)
+//            ->find();
+//
+//        if (!$course) {
+//            return app('json')->fail('课程不存在');
+//        }
+//
+//        $course = $course->toArray();
+//
+//        $education = \app\model\api\Education::where('gr_id', $course['gr_id'])
+//            ->where('audit', 1)
+//            ->find();
+//
+//        if (!$education) {
+//            return app('json')->fail('课程不存在或未通过审核');
+//        }
+//
+//        $education = $education->toArray();
+//
+//        $course['edu_name'] = $education['name'];
+//        $course['edu_logo'] = $education['logo'];
+//        $course['edu_type1'] = $education['type1'];
+//        $course['edu_type2'] = $education['type2'];
+//
+//        return app('json')->success($course);
+//    }
 
 
     /**
@@ -122,6 +122,39 @@ class Education
     }
 
 
+    /**
+     * 获取课程详细信息
+     * @param $gr_id
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function getCourseInfo($gr_id) {
+        $courses = EducationCourse::where('course_status', 1)
+            ->where('gr_id', $gr_id)
+            ->where('course_audit', 1)
+            ->select();
+        $course_list = [];
+        foreach ($courses as $course) {
+            $course_info = [
+                'course_id' => $course->id,
+                'course_name' => $course->course_name,
+                'course_cover' => $course->course_cover,
+                // 其他课程相关信息
+            ];
+            $course_list[] = $course_info;
+        }
+        $count_and_all = $this->getCountAndAlll([$gr_id]);
+        $result = [
+            'course_list' => $course_list,
+            'count' => $count_and_all[0]['count'],
+            'alll' => $count_and_all[0]['alll']
+        ];
+        return $result;
+    }
+
+
 
 
 }

+ 1 - 1
app/api/route/education.php

@@ -19,7 +19,7 @@ Route::group('Education', function () {
     //获取轮播列表
     Route::rule('recommend','Education/recommend');
     //获取课程详情
-    Route::rule('getCourseDetail','Education/getCourseDetail');
+    Route::rule('getCourseInfo','Education/getCourseInfo');