setRelations(['task']); } /** * 获取用户的任务奖励发放日志 * * @param int $userId 用户ID * @param int|null $taskId 任务ID * @param int $limit 限制数量 * @return array 任务奖励发放日志列表 */ public function getUserRewardLogs(int $userId, ?int $taskId = null, int $limit = 100): array { $query = $this->eloquentClass::where('user_id', $userId); if ($taskId) { $query->where('task_id', $taskId); } return $query->orderBy('rewarded_at', 'desc') ->limit($limit) ->get() ->toArray(); } /** * 获取特定时间段内的任务奖励发放日志 * * @param string $startDate 开始日期 * @param string $endDate 结束日期 * @return array 任务奖励发放日志列表 */ public function getRewardLogsByDateRange(string $startDate, string $endDate): array { return $this->eloquentClass::whereBetween('rewarded_at', [$startDate, $endDate]) ->orderBy('rewarded_at', 'desc') ->get() ->toArray(); } }