From 4e0884678de01e627a3c098db5d6561edb5baf82 Mon Sep 17 00:00:00 2001 From: chenbo <709206448@qq.com> Date: Sat, 3 Feb 2024 16:01:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E5=9C=B0=E7=BB=8F=E7=BA=AC=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/adminapi/logic/farm/FarmLogic.php | 4 +- .../controller/dataview/FarmController.php | 88 +++++++++++++++++++ 2 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 app/api/controller/dataview/FarmController.php diff --git a/app/adminapi/logic/farm/FarmLogic.php b/app/adminapi/logic/farm/FarmLogic.php index 99795c5..3aab35e 100644 --- a/app/adminapi/logic/farm/FarmLogic.php +++ b/app/adminapi/logic/farm/FarmLogic.php @@ -55,7 +55,7 @@ class FarmLogic extends BaseLogic 'village' => $params['village'], 'bridge' => $params['bridge'], 'address' => $params['address'], - 'image' => $params['image'], + 'pic' => $params['pic'], 'longitude' => $params['longitude'], 'latitude' => $params['latitude'], ]); @@ -95,7 +95,7 @@ class FarmLogic extends BaseLogic 'village' => $params['village'], 'bridge' => $params['bridge'], 'address' => $params['address'], - 'image' => $params['image'], + 'pic' => $params['pic'], 'longitude' => $params['longitude'], 'latitude' => $params['latitude'], ]); diff --git a/app/api/controller/dataview/FarmController.php b/app/api/controller/dataview/FarmController.php new file mode 100644 index 0000000..20aab2e --- /dev/null +++ b/app/api/controller/dataview/FarmController.php @@ -0,0 +1,88 @@ +areaCode = $this->request->param('areaCode', ''); + $this->streetCode = $this->request->param('streetCode', ''); + if ($this->areaCode == '') { + throw new ValidateException('未获取到位置信息'); + } + } + + public function farmCount() + { + $query = Farm::alias('f')->where(function ($query) { + if ($this->streetCode != '') { + $query->where('f.street', $this->streetCode); + } else { + $query->where('f.area', $this->areaCode); + } + }); + // 地块数量 + $farmCount = $query->count(); + // 养殖规模 + $totalScale = $query->sum('form_scale'); + // 基地列表 + $farmList = $query->select()->each(function ($farm){ + $fenceHouse = FenceHouse::where('farm_id', $farm['id'])->order('id desc')->findOrEmpty()->toArray(); + if(empty($fenceHouse)){ + $farm['video_url'] = ''; + $farm['device_id'] = 0; + return $farm; + } + $product = Product::where('fence_house_id', $fenceHouse['id'])->findOrEmpty()->toArray(); + if(empty($product)){ + $farm['video_url'] = ''; + $farm['device_id'] = 0; + return $farm; + } + $deviceIds = ProductDevice::where('product_id', $product['id'])->column('device_id'); + $device = Device::whereIn('id', $deviceIds)->where('type', 2)->findOrEmpty(); + if(empty($device)){ + $farm['video_url'] = ''; + $farm['device_id'] = 0; + return $farm; + } + $farm['video_url'] = $device['video_url']; + $farm['device_id'] = $device['id']; + return $farm; + })->toArray(); + return $this->success('成功', compact('farmCount', 'totalScale', 'farmList')); + } + public function centralCount() + { + + $query = Farm::alias('f')->where(function ($query) { + if ($this->streetCode != '') { + $query->where('f.town_code', $this->streetCode); + } else { + $query->where('f.county_code', $this->areaCode); + } + }); + // 地块数量 + $farmCount = $query->count(); + // 养殖规模 + $totalScale = $query->sum('form_scale'); + // 养殖种类 + $breedCount = $query->group('breed_type')->count(); + + return $this->success('成功', compact('farmCount', 'totalScale', 'breedCount')); + } +} \ No newline at end of file