| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace App\Module\Task\Repositorys;
- use App\Module\Task\Models\TaskCompletionLog;
- use Dcat\Admin\Repositories\EloquentRepository;
- /**
- * 任务完成日志数据仓库类
- *
- * 提供任务完成日志数据的访问和操作功能。
- * 该类是任务完成日志模块与后台管理系统的桥梁,用于处理任务完成日志数据的CRUD操作。
- */
- class TaskCompletionLogRepository extends EloquentRepository
- {
- /**
- * 关联的Eloquent模型类
- *
- * @var string
- */
- protected $eloquentClass = TaskCompletionLog::class;
-
- /**
- * 获取用户的任务完成日志
- *
- * @param int $userId 用户ID
- * @param int|null $taskId 任务ID
- * @param int $limit 限制数量
- * @return array 任务完成日志列表
- */
- public function getUserCompletionLogs(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('completed_at', 'desc')
- ->limit($limit)
- ->get()
- ->toArray();
- }
-
- /**
- * 获取特定时间段内的任务完成日志
- *
- * @param string $startDate 开始日期
- * @param string $endDate 结束日期
- * @return array 任务完成日志列表
- */
- public function getCompletionLogsByDateRange(string $startDate, string $endDate): array
- {
- return $this->eloquentClass::whereBetween('completed_at', [$startDate, $endDate])
- ->orderBy('completed_at', 'desc')
- ->get()
- ->toArray();
- }
- }
|