select( 'id', 'title', 'start_time', 'end_time', 'status', 'master_id' ); // 使用 whereIn 方法筛选 lecture_id 在 $lectureIdArr 数组中的记录 // 搜索 if (isset($condition['keywords']) && $condition['keywords']) { $query->where('title', 'like', '%' . $condition['keywords'] . '%'); } // 排序 $query->orderBy($sort, $sortable); // 执行查询并返回结果 return self::JsonPage($query); } public function getListForExpert($condition, $sort = 'id', $sortable = 'desc') { $userId = auth('expert')->user()->id; $userLectureIdArr = UserLectureRelation::query()->where('user_id', $userId)->pluck('lecture_id')->toArray(); if(empty($userLectureIdArr)){ return [ 'list' => [], 'count' => 0, 'current_page' => 1, 'page_size' => 15, ]; } $query = Lecture::query(); $query->select( 'id', 'title', 'start_time', 'end_time', 'status' ); // 使用 whereIn 方法筛选 lecture_id 在 $lectureIdArr 数组中的记录 $query->whereIn('id', $userLectureIdArr); // 搜索 if (isset($condition['keywords']) && $condition['keywords']) { $query->where('title', 'like', '%' . $condition['keywords'] . '%'); } if (isset($condition['status']) && $condition['status'] !== NULL) { $query->where('status', $condition['status']); } // 排序 $query->orderBy($sort, $sortable); // 执行查询并返回结果 return self::JsonPage($query); } public function getListForGrider($condition, $sort = 'id', $sortable = 'desc') { $userId = auth('grider')->user()->id; $userLectureIdArr = UserLectureRelation::query()->where('user_id', $userId)->pluck('lecture_id')->toArray(); $workstationLectureIdArr = WorkstationLectureRelation::query()->where('workstation_id', 'abc')->pluck('lecture_id')->toArray(); $lectureIdArr = array_merge($userLectureIdArr, $workstationLectureIdArr); if(empty($lectureIdArr)){ return [ 'list' => [], 'count' => 0, 'current_page' => 1, 'page_size' => 15, ]; } $query = Lecture::query(); $query->select( 'id', 'title', 'start_time', 'end_time', 'status' ); // 使用 whereIn 方法筛选 lecture_id 在 $lectureIdArr 数组中的记录 $query->whereIn('id', $lectureIdArr); // 搜索 if (isset($condition['keywords']) && $condition['keywords']) { $query->where('title', 'like', '%' . $condition['keywords'] . '%'); } if (isset($condition['status']) && $condition['status'] !== NULL) { $query->where('status', $condition['status']); } // 排序 $query->orderBy($sort, $sortable); // 执行查询并返回结果 return self::JsonPage($query); } }