taskId = $data['task_id'] ?? 0; $dto->taskName = $data['task_name'] ?? ''; $dto->changeType = $data['change_type'] ?? ''; $dto->status = $data['status'] ?? ''; $dto->progress = $data['progress'] ?? null; $dto->progressDetails = $data['progress_details'] ?? null; $dto->completedAt = $data['completed_at'] ?? null; $dto->rewardedAt = $data['rewarded_at'] ?? null; $dto->rewards = $data['rewards'] ?? null; $dto->updatedAt = $data['updated_at'] ?? time(); return $dto; } /** * 转换为数组 * * @return array 数组数据 */ public function toArray(): array { return [ 'task_id' => $this->taskId, 'task_name' => $this->taskName, 'change_type' => $this->changeType, 'status' => $this->status, 'progress' => $this->progress, 'progress_details' => $this->progressDetails, 'completed_at' => $this->completedAt, 'rewarded_at' => $this->rewardedAt, 'rewards' => $this->rewards, 'updated_at' => $this->updatedAt, ]; } /** * 获取变更类型的中文描述 * * @return string 中文描述 */ public function getChangeTypeDescription(): string { return match ($this->changeType) { 'progress_updated' => '进度更新', 'completed' => '任务完成', 'reward_claimed' => '奖励领取', default => '未知变更', }; } /** * 获取任务状态的中文描述 * * @return string 中文描述 */ public function getStatusDescription(): string { return match ($this->status) { 'in_progress' => '进行中', 'completed' => '已完成', 'rewarded' => '已领取奖励', default => '未知状态', }; } /** * 检查是否为进度更新 * * @return bool 是否为进度更新 */ public function isProgressUpdate(): bool { return $this->changeType === 'progress_updated'; } /** * 检查是否为任务完成 * * @return bool 是否为任务完成 */ public function isTaskCompleted(): bool { return $this->changeType === 'completed'; } /** * 检查是否为奖励领取 * * @return bool 是否为奖励领取 */ public function isRewardClaimed(): bool { return $this->changeType === 'reward_claimed'; } /** * 获取格式化的进度文本 * * @return string 格式化的进度文本 */ public function getFormattedProgress(): string { if ($this->progress === null) { return '无进度信息'; } return $this->progress . '%'; } /** * 获取奖励数量 * * @return int 奖励数量 */ public function getRewardCount(): int { return $this->rewards ? count($this->rewards) : 0; } }