Przeglądaj źródła

新增 视频详情、免费课程列表 接口

liugc 1 rok temu
rodzic
commit
8810084011

+ 21 - 0
app/workerapi/controller/TrainingController.php

@@ -7,6 +7,7 @@ use app\common\model\dict\DictData;
 use app\workerapi\lists\MasterWorkerLists;
 use app\workerapi\lists\ServiceWorkLists;
 use app\workerapi\lists\TeamServiceWorkLists;
+use app\workerapi\lists\TrainingCourseLists;
 use app\workerapi\logic\LoginLogic;
 use app\workerapi\logic\MasterWorkerInfoLogic;
 use app\workerapi\logic\MasterWorkerLogic;
@@ -31,6 +32,15 @@ class TrainingController extends BaseApiController
         return $this->data($result);
     }
 
+    /**
+     * 获取免费的课程列表
+     * @return \think\response\Json
+     */
+    public function getFreeCourseList()
+    {
+        return $this->dataLists(new TrainingCourseLists());
+    }
+
     /**
      * 获取工程师的课程列表
      * @return \think\response\Json
@@ -41,6 +51,17 @@ class TrainingController extends BaseApiController
         return $this->data(TrainingLogic::getCourseList($this->userId,$params));
     }
 
+    /**
+     * 获取工程师的课程详情
+     * @return \think\response\Json
+     */
+    public function getCourseDetail()
+    {
+        $params  = request()->get();
+        return $this->data(TrainingLogic::getCourseDetail($this->userId,$params));
+    }
+
+
     /**
      * 修改学习视频记录状态
      * @return \think\response\Json

+ 47 - 0
app/workerapi/lists/TrainingCourseLists.php

@@ -0,0 +1,47 @@
+<?php
+namespace app\workerapi\lists;
+
+use app\common\lists\ListsSearchInterface;
+use app\common\model\training\TrainingCourse;
+use app\common\model\training\TrainingWorkerCourse;
+use DateTime;
+
+/**
+ * TrainingWorkerCourseLists列表
+ * Class TrainingWorkerCourseLists
+ * @package app\workerapi\listsworks
+ */
+class TrainingCourseLists extends BaseWorkerDataLists
+{
+
+    public function queryWhere(){
+        $where = [];
+        $where[] = ['course_lock','=',1];
+        return $where;
+    }
+    /**
+     * @notes 获取列表
+     */
+    public function lists(): array
+    {
+        return TrainingCourse::where($this->queryWhere())
+            ->field('*')
+            ->limit($this->limitOffset, $this->limitLength)
+            ->order(['create_time' => 'desc'])
+            ->select()
+            ->toArray();
+    }
+
+
+    /**
+     * @notes 获取数量
+     * @return int
+     * @author whitef
+     * @date 2024/07/10 15:06
+     */
+    public function count(): int
+    {
+        return TrainingCourse::where($this->queryWhere())->count();
+    }
+
+}

+ 19 - 1
app/workerapi/logic/TrainingLogic.php

@@ -77,7 +77,25 @@ class TrainingLogic extends  BaseLogic
         }
     }
 
-
+    /**
+     * 获取工程师的课程详情
+     * @param int $masterWorkerId
+     * @param array $params
+     * @return array id => 工程师的课程id
+     */
+    public static function getCourseDetail(int $masterWorkerId,$params = [])
+    {
+        try {
+            $info =  TrainingWorkerCourse::with(['trainingCourse'])->where('master_worker_id',$masterWorkerId)->where('id',$params['id'])->findOrEmpty()->toArray();
+            $info['course_name'] = $info['trainingCourse']['course_name'];
+            $info['course_picture'] = FileService::getFileUrl($info['trainingCourse']['course_picture']);
+            $info['course_url'] = FileService::getFileUrl($info['trainingCourse']['course_url']);
+            return $info;
+        } catch (\Exception $e) {
+            self::setError($e->getMessage());
+            return [];
+        }
+    }
     /**
      * 修改学习记录状态 播放开始 播放暂停 播放结束 考试开始 考试结束
      * @param array $params