userId = $userTask->user_id; $dto->taskId = $userTask->task_id; $dto->userTaskId = $userTask->id; $dto->status = $userTask->status; $dto->progress = $userTask->progress; $dto->acceptedAt = $userTask->accepted_at ? $userTask->accepted_at->format('Y-m-d H:i:s') : null; $dto->completedAt = $userTask->completed_at ? $userTask->completed_at->format('Y-m-d H:i:s') : null; $dto->rewardedAt = $userTask->rewarded_at ? $userTask->rewarded_at->format('Y-m-d H:i:s') : null; $dto->lastResetTime = $userTask->last_reset_time ? $userTask->last_reset_time->format('Y-m-d H:i:s') : null; $dto->nextResetTime = $userTask->next_reset_time ? $userTask->next_reset_time->format('Y-m-d H:i:s') : null; $dto->resetCount = $userTask->reset_count ?? 0; // 加载任务信息 if ($userTask->relationLoaded('task')) { $dto->task = TaskDto::fromModel($userTask->task); } return $dto; } /** * 添加条件进度 * * @param TaskConditionDto $conditionDto 条件DTO * @param int $currentValue 当前值 * @return self */ public function addConditionProgress(TaskConditionDto $conditionDto, int $currentValue): self { $conditionDto->setProgress($currentValue); $this->conditionProgress[] = $conditionDto; return $this; } /** * 从用户任务进度列表添加条件进度 * * @param array $userProgressList 用户任务进度列表 * @param array $conditionList 条件列表 * @return self */ public function addConditionProgressFromList(array $userProgressList, array $conditionList): self { foreach ($conditionList as $condition) { $conditionDto = TaskConditionDto::fromModel($condition); // 查找对应的进度记录 $progress = null; foreach ($userProgressList as $userProgress) { if ($userProgress->achievement_condition_id === $condition->id) { $progress = $userProgress; break; } } // 添加条件进度 $currentValue = $progress ? $progress->current_value : 0; $this->addConditionProgress($conditionDto, $currentValue); } return $this; } }