| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- namespace App\Module\Farm\Repositories;
- use App\Module\Farm\Models\FarmTeamProfit;
- use Dcat\Admin\Repositories\EloquentRepository;
- use Illuminate\Database\Eloquent\Collection;
- /**
- * 团队收益记录仓库
- *
- * 提供团队收益记录数据的访问和操作功能。
- * 该类是团队收益记录模块与后台管理系统的桥梁,用于处理团队收益记录数据的CRUD操作。
- */
- class FarmTeamProfitRepository extends EloquentRepository
- {
- /**
- * 模型类名
- *
- * @var string
- */
- protected $eloquentClass = FarmTeamProfit::class;
- /**
- * 获取用户的团队收益记录
- *
- * @param int $userId
- * @param int $limit
- * @return Collection
- */
- public function findByUserId(int $userId, int $limit = 100): Collection
- {
- return FarmTeamProfit::where('user_id', $userId)
- ->orderByDesc('created_at')
- ->limit($limit)
- ->get();
- }
- /**
- * 获取团队成员产生的收益记录
- *
- * @param int $teamMemberId
- * @param int $limit
- * @return Collection
- */
- public function findByTeamMemberId(int $teamMemberId, int $limit = 100): Collection
- {
- return FarmTeamProfit::where('team_member_id', $teamMemberId)
- ->orderByDesc('created_at')
- ->limit($limit)
- ->get();
- }
- /**
- * 获取指定收获记录产生的团队收益
- *
- * @param int $harvestId
- * @return Collection
- */
- public function findByHarvestId(int $harvestId): Collection
- {
- return FarmTeamProfit::where('harvest_id', $harvestId)
- ->orderByDesc('created_at')
- ->get();
- }
- /**
- * 获取指定时间段内的团队收益记录
- *
- * @param string $startTime
- * @param string $endTime
- * @return Collection
- */
- public function findByTimeRange(string $startTime, string $endTime): Collection
- {
- return FarmTeamProfit::whereBetween('created_at', [$startTime, $endTime])
- ->orderByDesc('created_at')
- ->get();
- }
- /**
- * 获取用户指定时间段内的团队收益记录
- *
- * @param int $userId
- * @param string $startTime
- * @param string $endTime
- * @return Collection
- */
- public function findByUserIdAndTimeRange(int $userId, string $startTime, string $endTime): Collection
- {
- return FarmTeamProfit::where('user_id', $userId)
- ->whereBetween('created_at', [$startTime, $endTime])
- ->orderByDesc('created_at')
- ->get();
- }
- /**
- * 清理过期的团队收益记录
- *
- * @param int $days 保留天数
- * @return int
- */
- public function cleanupOldLogs(int $days = 90): int
- {
- $date = now()->subDays($days);
- return FarmTeamProfit::where('created_at', '<', $date)->delete();
- }
- }
|