|
|
@ -187,18 +187,32 @@ class CoachStudentService extends BaseApiService |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 获取教练负责的学员ID集合 |
|
|
* 获取教练负责的学员ID集合(带缓存) |
|
|
* @param int $coachId 教练ID |
|
|
* @param int $coachId 教练ID |
|
|
* @param array $data 查询条件 |
|
|
* @param array $data 查询条件 |
|
|
* @return array |
|
|
* @return array |
|
|
*/ |
|
|
*/ |
|
|
private function getCoachStudentIds($coachId, $data = []) |
|
|
private function getCoachStudentIds($coachId, $data = []) |
|
|
{ |
|
|
{ |
|
|
// 1. 从 school_student_courses 表中查询 main_coach_id 或 education_id 是当前教练的学员 |
|
|
// 检查缓存 |
|
|
|
|
|
$cacheKey = "coach_student_ids:{$coachId}"; |
|
|
|
|
|
$cachedIds = cache($cacheKey); |
|
|
|
|
|
|
|
|
|
|
|
if ($cachedIds !== null && is_array($cachedIds)) { |
|
|
|
|
|
return $cachedIds; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 1. 从 school_student_courses 表中查询相关学员 |
|
|
$courseStudentIds = Db::table('school_student_courses') |
|
|
$courseStudentIds = Db::table('school_student_courses') |
|
|
->where(function($query) use ($coachId) { |
|
|
->where(function($query) use ($coachId) { |
|
|
$query->where('main_coach_id', $coachId) |
|
|
$query->where('main_coach_id', $coachId) |
|
|
->whereOr('education_id', $coachId); |
|
|
->whereOr('education_id', $coachId) |
|
|
|
|
|
->whereOr(function($q) use ($coachId) { |
|
|
|
|
|
// 查询 assistant_ids 字段中包含当前教练ID的记录 |
|
|
|
|
|
$q->whereNotNull('assistant_ids') |
|
|
|
|
|
->where('assistant_ids', '<>', '') |
|
|
|
|
|
->whereRaw("FIND_IN_SET(?, assistant_ids)", [$coachId]); |
|
|
|
|
|
}); |
|
|
}) |
|
|
}) |
|
|
->column('student_id'); |
|
|
->column('student_id'); |
|
|
|
|
|
|
|
|
@ -207,7 +221,13 @@ class CoachStudentService extends BaseApiService |
|
|
->leftJoin('school_course_schedule cs', 'pcs.schedule_id = cs.id') |
|
|
->leftJoin('school_course_schedule cs', 'pcs.schedule_id = cs.id') |
|
|
->where(function($query) use ($coachId) { |
|
|
->where(function($query) use ($coachId) { |
|
|
$query->where('cs.education_id', $coachId) |
|
|
$query->where('cs.education_id', $coachId) |
|
|
->whereOr('cs.coach_id', $coachId); |
|
|
->whereOr('cs.coach_id', $coachId) |
|
|
|
|
|
->whereOr(function($q) use ($coachId) { |
|
|
|
|
|
// 查询 assistant_ids 字段中包含当前教练ID的记录 |
|
|
|
|
|
$q->whereNotNull('cs.assistant_ids') |
|
|
|
|
|
->where('cs.assistant_ids', '<>', '') |
|
|
|
|
|
->whereRaw("FIND_IN_SET(?, cs.assistant_ids)", [$coachId]); |
|
|
|
|
|
}); |
|
|
}) |
|
|
}) |
|
|
->where('pcs.person_type', 'student') |
|
|
->where('pcs.person_type', 'student') |
|
|
->where('pcs.deleted_at', 0) |
|
|
->where('pcs.deleted_at', 0) |
|
|
@ -217,8 +237,12 @@ class CoachStudentService extends BaseApiService |
|
|
// 3. 合并并去重学生ID |
|
|
// 3. 合并并去重学生ID |
|
|
$allStudentIds = array_merge($courseStudentIds, $scheduleStudentIds); |
|
|
$allStudentIds = array_merge($courseStudentIds, $scheduleStudentIds); |
|
|
$uniqueStudentIds = array_unique($allStudentIds); |
|
|
$uniqueStudentIds = array_unique($allStudentIds); |
|
|
|
|
|
$result = array_values($uniqueStudentIds); |
|
|
|
|
|
|
|
|
|
|
|
// 4. 缓存结果(1小时 = 3600秒) |
|
|
|
|
|
cache($cacheKey, $result, 3600); |
|
|
|
|
|
|
|
|
return array_values($uniqueStudentIds); |
|
|
return $result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -387,13 +411,13 @@ class CoachStudentService extends BaseApiService |
|
|
if (empty($token)) { |
|
|
if (empty($token)) { |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 去掉Bearer前缀 |
|
|
// 去掉Bearer前缀 |
|
|
$token = str_replace('Bearer ', '', $token); |
|
|
$token = str_replace('Bearer ', '', $token); |
|
|
|
|
|
|
|
|
// 使用项目的TokenAuth类解析token,类型为personnel(员工端) |
|
|
// 使用项目的TokenAuth类解析token,类型为personnel(员工端) |
|
|
$tokenInfo = \core\util\TokenAuth::parseToken($token, 'personnel'); |
|
|
$tokenInfo = \core\util\TokenAuth::parseToken($token, 'personnel'); |
|
|
|
|
|
|
|
|
if (!empty($tokenInfo)) { |
|
|
if (!empty($tokenInfo)) { |
|
|
// 从jti中提取用户ID(格式:用户ID_类型) |
|
|
// 从jti中提取用户ID(格式:用户ID_类型) |
|
|
$jti = $tokenInfo['jti'] ?? ''; |
|
|
$jti = $tokenInfo['jti'] ?? ''; |
|
|
@ -404,10 +428,33 @@ class CoachStudentService extends BaseApiService |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return 0; |
|
|
return 0; |
|
|
} catch (\Exception $e) { |
|
|
} catch (\Exception $e) { |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 清除教练学员关系缓存 |
|
|
|
|
|
* @param int|array $coachId 教练ID或教练ID数组 |
|
|
|
|
|
* @return bool |
|
|
|
|
|
*/ |
|
|
|
|
|
public static function clearCoachStudentCache($coachId) |
|
|
|
|
|
{ |
|
|
|
|
|
try { |
|
|
|
|
|
if (is_array($coachId)) { |
|
|
|
|
|
// 批量清除缓存 |
|
|
|
|
|
foreach ($coachId as $id) { |
|
|
|
|
|
cache("coach_student_ids:{$id}", null); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
// 清除单个教练缓存 |
|
|
|
|
|
cache("coach_student_ids:{$coachId}", null); |
|
|
|
|
|
} |
|
|
|
|
|
return true; |
|
|
|
|
|
} catch (\Exception $e) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |