diff --git a/app/adminapi/logic/animal_info/AnimalInfoLogic.php b/app/adminapi/logic/animal_info/AnimalInfoLogic.php index ffb3506..7b19016 100644 --- a/app/adminapi/logic/animal_info/AnimalInfoLogic.php +++ b/app/adminapi/logic/animal_info/AnimalInfoLogic.php @@ -134,6 +134,10 @@ class AnimalInfoLogic extends BaseLogic */ public static function detail($params): array { + if (isset($params['sn'])) { + return AnimalInfo::with(['fenceHouseAttr'])->where('sn', $params['sn'])->toArray(); + } return AnimalInfo::with(['fenceHouseAttr'])->findOrEmpty($params['id'])->toArray(); + } } \ No newline at end of file diff --git a/app/adminapi/logic/fence_house/FenceHouseLogic.php b/app/adminapi/logic/fence_house/FenceHouseLogic.php index 55ef4b0..40060b7 100644 --- a/app/adminapi/logic/fence_house/FenceHouseLogic.php +++ b/app/adminapi/logic/fence_house/FenceHouseLogic.php @@ -15,9 +15,12 @@ namespace app\adminapi\logic\fence_house; +use app\common\model\device\Device; use app\common\model\farm\Farm; use app\common\model\fence_house\FenceHouse; use app\common\logic\BaseLogic; +use app\common\model\land\Product; +use app\common\model\product\ProductDevice; use think\facade\Db; @@ -120,7 +123,14 @@ class FenceHouseLogic extends BaseLogic */ public static function detail($params): array { - return FenceHouse::findOrEmpty($params['id'])->toArray(); + $data = FenceHouse::findOrEmpty($params['id'])->toArray(); + $product = Product::where('fence_house_id', $params['id'])->findOrEmpty()->toArray(); + $deviceIds = ProductDevice::where('product_id', $product['id'])->column('device_id'); + $device = Device::whereIn('id', $deviceIds)->where('type', 2)->findOrEmpty(); + $data['video_url'] = $device['video_url']; + $data['device_id'] = $device['id']; + + return $data; } diff --git a/app/api/controller/AnimalInfoController.php b/app/api/controller/AnimalInfoController.php index 373107d..8b55915 100644 --- a/app/api/controller/AnimalInfoController.php +++ b/app/api/controller/AnimalInfoController.php @@ -99,10 +99,8 @@ class AnimalInfoController extends BaseApiController */ public function detail() { - $params = (new AnimalInfoValidate())->goCheck('detail'); + $params = $this->request->param(); $result = AnimalInfoLogic::detail($params); return $this->data($result); } - - } \ No newline at end of file