'integer', 'activity_id' => 'integer', 'progress' => 'integer', 'progress_data' => 'json', 'last_update' => 'datetime', ]; /** * 获取关联的活动 * * @return BelongsTo */ public function activity(): BelongsTo { return $this->belongsTo(ActivityConfig::class, 'activity_id', 'id'); } /** * 获取关联的参与记录 * * @return BelongsTo */ public function participation(): BelongsTo { return $this->belongsTo(ActivityParticipation::class, ['user_id', 'activity_id'], ['user_id', 'activity_id']); } /** * 更新进度 * * @param int $progress 新的进度值 * @param array|null $progressData 详细进度数据 * @return bool */ public function updateProgress(int $progress, ?array $progressData = null): bool { $this->progress = $progress; if ($progressData !== null) { $this->progress_data = $progressData; } $this->last_update = now(); return $this->save(); } /** * 增加进度 * * @param int $increment 增加的进度值 * @param array|null $progressData 详细进度数据 * @return bool */ public function incrementProgress(int $increment, ?array $progressData = null): bool { return $this->updateProgress($this->progress + $increment, $progressData); } }