eloquentClass::where('user_id', $userId); if ($taskId) { $query->where('task_id', $taskId); } return $query->orderBy('cost_at', 'desc') ->limit($limit) ->get() ->toArray(); } /** * 获取特定时间段内的任务消耗日志 * * @param string $startDate 开始日期 * @param string $endDate 结束日期 * @return array 任务消耗日志列表 */ public function getCostLogsByDateRange(string $startDate, string $endDate): array { return $this->eloquentClass::whereBetween('cost_at', [$startDate, $endDate]) ->orderBy('cost_at', 'desc') ->get() ->toArray(); } /** * 获取特定消耗类型的任务消耗日志 * * @param string $costType 消耗类型 * @param int $limit 限制数量 * @return array 任务消耗日志列表 */ public function getCostLogsByType(string $costType, int $limit = 100): array { return $this->eloquentClass::where('cost_type', $costType) ->orderBy('cost_at', 'desc') ->limit($limit) ->get() ->toArray(); } }