| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace App\Module\Farm\Repositories;
- use App\Module\Farm\Models\FarmLand;
- use Dcat\Admin\Repositories\EloquentRepository;
- use Illuminate\Database\Eloquent\Collection;
- /**
- * 土地信息仓库
- *
- * 提供土地信息数据的访问和操作功能。
- * 该类是土地信息模块与后台管理系统的桥梁,用于处理土地信息数据的CRUD操作。
- */
- class FarmLandRepository extends EloquentRepository
- {
- /**
- * 模型类名
- *
- * @var string
- */
- protected $eloquentClass = FarmLand::class;
- /**
- * 获取用户的所有土地
- *
- * @param int $userId
- * @return Collection
- */
- public function findByUserId(int $userId): Collection
- {
- return FarmLand::where('user_id', $userId)->get();
- }
- /**
- * 获取用户指定位置的土地
- *
- * @param int $userId
- * @param int $position
- * @return FarmLand|null
- */
- public function findByUserIdAndPosition(int $userId, int $position): ?FarmLand
- {
- return FarmLand::where('user_id', $userId)
- ->where('position', $position)
- ->first();
- }
- /**
- * 获取用户指定状态的土地
- *
- * @param int $userId
- * @param int $status
- * @return Collection
- */
- public function findByUserIdAndStatus(int $userId, int $status): Collection
- {
- return FarmLand::where('user_id', $userId)
- ->where('status', $status)
- ->get();
- }
- /**
- * 获取用户指定类型的土地
- *
- * @param int $userId
- * @param int $landType
- * @return Collection
- */
- public function findByUserIdAndType(int $userId, int $landType): Collection
- {
- return FarmLand::where('user_id', $userId)
- ->where('land_type', $landType)
- ->get();
- }
- /**
- * 获取用户的特殊土地数量
- *
- * @param int $userId
- * @return int
- */
- public function countSpecialLands(int $userId): int
- {
- return FarmLand::where('user_id', $userId)
- ->whereIn('land_type', [4, 5, 6]) // 金、蓝、紫特殊土地
- ->count();
- }
- }
|