$userId, 'error' => $e->getMessage() ]); return []; } } /** * 获取用户指定任务的变更数据 * * @param int $userId 用户ID * @param int $taskId 任务ID * @return TaskChangeTempDto|null 任务变更数据 */ public static function getUserTaskChange(int $userId, int $taskId): ?TaskChangeTempDto { try { return TaskTemp::getUserTaskChange($userId, $taskId); } catch (\Exception $e) { Log::error('获取用户指定任务变更数据失败', [ 'user_id' => $userId, 'task_id' => $taskId, 'error' => $e->getMessage() ]); return null; } } /** * 记录任务进度更新 * * @param int $userId 用户ID * @param int $taskId 任务ID * @param string $taskName 任务名称 * @param int $progress 进度百分比 * @param array $progressDetails 进度详情 * @return bool 是否成功 */ public static function recordTaskProgressUpdate(int $userId, int $taskId, string $taskName, int $progress, array $progressDetails = []): bool { try { TaskTemp::handleTaskProgressUpdated($userId, $taskId, $taskName, $progress, $progressDetails); return true; } catch (\Exception $e) { Log::error('记录任务进度更新失败', [ 'user_id' => $userId, 'task_id' => $taskId, 'progress' => $progress, 'error' => $e->getMessage() ]); return false; } } /** * 清理用户的任务变更数据 * * @param int $userId 用户ID * @return bool 是否成功 */ public static function clearUserTaskChanges(int $userId): bool { try { TaskTemp::clearUserTaskChanges($userId); return true; } catch (\Exception $e) { Log::error('清理用户任务变更数据失败', [ 'user_id' => $userId, 'error' => $e->getMessage() ]); return false; } } /** * 清理用户指定任务的变更数据 * * @param int $userId 用户ID * @param int $taskId 任务ID * @return bool 是否成功 */ public static function clearUserTaskChange(int $userId, int $taskId): bool { try { TaskTemp::clearUserTaskChange($userId, $taskId); return true; } catch (\Exception $e) { Log::error('清理用户指定任务变更数据失败', [ 'user_id' => $userId, 'task_id' => $taskId, 'error' => $e->getMessage() ]); return false; } } /** * 获取用户任务变更统计信息 * * @param int $userId 用户ID * @return array 统计信息 */ public static function getUserTaskChangeStats(int $userId): array { try { $changes = TaskTemp::getUserTaskChanges($userId); $stats = [ 'total_changes' => count($changes), 'progress_updates' => 0, 'completed_tasks' => 0, 'reward_claims' => 0, 'latest_update' => null, ]; foreach ($changes as $change) { switch ($change->changeType) { case 'progress_updated': $stats['progress_updates']++; break; case 'completed': $stats['completed_tasks']++; break; case 'reward_claimed': $stats['reward_claims']++; break; } if ($stats['latest_update'] === null || $change->updatedAt > $stats['latest_update']) { $stats['latest_update'] = $change->updatedAt; } } return $stats; } catch (\Exception $e) { Log::error('获取用户任务变更统计信息失败', [ 'user_id' => $userId, 'error' => $e->getMessage() ]); return [ 'total_changes' => 0, 'progress_updates' => 0, 'completed_tasks' => 0, 'reward_claims' => 0, 'latest_update' => null, ]; } } /** * 检查用户是否有任务变更数据 * * @param int $userId 用户ID * @return bool 是否有变更数据 */ public static function hasUserTaskChanges(int $userId): bool { try { $changes = TaskTemp::getUserTaskChanges($userId); return !empty($changes); } catch (\Exception $e) { Log::error('检查用户任务变更数据失败', [ 'user_id' => $userId, 'error' => $e->getMessage() ]); return false; } } /** * 获取用户最近的任务变更 * * @param int $userId 用户ID * @param int $limit 限制数量 * @return array 最近的任务变更 */ public static function getUserRecentTaskChanges(int $userId, int $limit = 10): array { try { $changes = TaskTemp::getUserTaskChanges($userId); // 按更新时间倒序排序 usort($changes, function ($a, $b) { return $b->updatedAt - $a->updatedAt; }); // 限制数量 return array_slice($changes, 0, $limit); } catch (\Exception $e) { Log::error('获取用户最近任务变更失败', [ 'user_id' => $userId, 'limit' => $limit, 'error' => $e->getMessage() ]); return []; } } }