This commit is contained in:
chenbo 2024-01-31 15:21:56 +08:00
parent 8333a2cd0d
commit a3704c69e3
1 changed files with 10 additions and 1 deletions

View File

@ -18,6 +18,8 @@ namespace app\api\lists;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\animal_info\AnimalInfo;
use app\common\lists\ListsSearchInterface;
use app\common\model\farm\Farm;
use app\common\model\fence_house\FenceHouse;
/**
@ -55,7 +57,14 @@ class AnimalInfoLists extends BaseApiDataLists implements ListsSearchInterface
*/
public function lists(): array
{
return AnimalInfo::where($this->searchWhere)
$fenceHouseId = $this->request->get('fence_house_id', '');
$where = [];
if (empty($fenceHouseId)) {
$farmIds = Farm::where('user_id', $this->userId)->column('id');
$fenceHouseIds = FenceHouse::whereIn('farm_id', $farmIds)->column('id');
$where[] = ['fence_house_id', 'in', $fenceHouseIds];
}
return AnimalInfo::where($this->searchWhere)->where($where)
->with(['fenceHouseAttr'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])