|
@@ -333,7 +333,7 @@ class AccountService
|
|
|
// 生成Redis键
|
|
|
$key = $coachId.'_'.$type;
|
|
|
|
|
|
- // 将���置信息写入Redis
|
|
|
+ // 将置信息写入Redis
|
|
|
$result = Redis::geoadd('coach_locations', $longitude, $latitude, $key);
|
|
|
|
|
|
// 同时写入数据库保存历史记录
|
|
@@ -825,4 +825,55 @@ class AccountService
|
|
|
throw $e;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取技师排班信息
|
|
|
+ *
|
|
|
+ * @param int $userId 用户ID
|
|
|
+ */
|
|
|
+ public function getSchedule(int $userId): array
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ // 获取技师信息
|
|
|
+ $user = MemberUser::with(['coach'])->findOrFail($userId);
|
|
|
+ $coach = $user->coach;
|
|
|
+ abort_if(! $coach, 404, '技师信息不存在');
|
|
|
+
|
|
|
+ // 先尝试从缓存获取
|
|
|
+ $cacheKey = "coach:schedule:{$coach->id}";
|
|
|
+ $cached = Redis::get($cacheKey);
|
|
|
+ if ($cached) {
|
|
|
+ return json_decode($cached, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 缓存不存在,从数据库获取
|
|
|
+ $schedule = CoachSchedule::where('coach_id', $coach->id)
|
|
|
+ ->where('state', 1)
|
|
|
+ ->first();
|
|
|
+
|
|
|
+ $result = [
|
|
|
+ 'time_ranges' => $schedule ? json_decode($schedule->time_ranges, true) : [],
|
|
|
+ 'updated_at' => $schedule ? $schedule->updated_at->toDateTimeString() : now()->toDateTimeString(),
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 写入缓存
|
|
|
+ Redis::setex($cacheKey, 86400, json_encode($result));
|
|
|
+
|
|
|
+ // 记录日志
|
|
|
+ Log::info('获取技师排班信息成功', [
|
|
|
+ 'coach_id' => $coach->id,
|
|
|
+ 'schedule' => $result,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ return $result;
|
|
|
+
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Log::error('获取技师排班信息失败', [
|
|
|
+ 'user_id' => $userId,
|
|
|
+ 'error' => $e->getMessage(),
|
|
|
+ 'trace' => $e->getTraceAsString(),
|
|
|
+ ]);
|
|
|
+ throw $e;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|