This commit is contained in:
chenbo 2024-01-31 15:58:18 +08:00
parent a3704c69e3
commit edce7b2ce3
3 changed files with 16 additions and 4 deletions

View File

@ -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();
}
}

View File

@ -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;
}

View File

@ -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);
}
}