exists(); } /** * 是否可查看指定课程的本班通讯录 */ public static function canViewCourseTxl(int $userId, int $courseId): bool { return CourseSign::where('user_id', $userId) ->where('course_id', $courseId) ->where('status', 1) ->exists(); } /** * 审核通过且满足校友库准入条件的报名查询 */ public static function qualifyingCourseSignsQuery(int $userId) { return CourseSign::where('user_id', $userId) ->where('status', 1) ->where(function ($schoolmateQuery) { $schoolmateQuery->whereHas('course', function ($courseQuery) { $courseQuery->where('is_fee', 1); })->orWhereHas('course', function ($courseQuery) { $courseQuery->where('is_fee', 0) ->where('free_enter_schoolmate', 1); }); }); } /** * 为列表用户计算 open_mobile 标记 */ public static function applyOpenMobileFlags(Collection $users, int $viewerUserId, ?Course $course = null): void { $userCourseSigns = CourseSign::where('user_id', $viewerUserId)->where('status', 1)->get(); $coursesTypeIds = Course::whereIn('id', $userCourseSigns->pluck('course_id'))->pluck('type')->toArray(); $courseShowMobile = $course ? (int) ($course->show_mobile ?? 0) : null; foreach ($users as $user) { $user->open_mobile = false; $courseIds = $user->courseSigns->where('status', 1)->pluck('course_id')->toArray(); if (count(array_intersect($courseIds, $userCourseSigns->pluck('course_id')->toArray())) > 0) { $user->open_mobile = true; } else { $openCourseTypes = array_filter(explode(',', (string) ($user->open_course_types ?? ''))); if (count(array_intersect($coursesTypeIds, $openCourseTypes)) > 0) { $user->open_mobile = true; } } if ($courseShowMobile !== null && $courseShowMobile === 0) { $user->open_mobile = false; } } } }