From 6be8667105886f92e31b5f6beae04ae4ecea499a Mon Sep 17 00:00:00 2001 From: weiz Date: Sat, 25 Nov 2023 10:32:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A6=96=E9=A1=B5=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/IndexController.php | 98 ++++++++++---------------- 1 file changed, 37 insertions(+), 61 deletions(-) diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index e341fe68..4d533bdd 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -17,6 +17,10 @@ namespace app\api\controller; use app\api\logic\IndexLogic; use app\common\enum\notice\NoticeEnum; +use app\common\model\land\Land; +use app\common\model\land\LandDevice; +use app\common\model\monitor\AirMonitor; +use app\common\model\monitor\SoilMonitor; use think\facade\Log; use think\response\Json; @@ -28,68 +32,40 @@ use think\response\Json; */ class IndexController extends BaseApiController { - - - public array $notNeedLogin = ['index', 'config', 'policy', 'decorate','code','suYuan']; - - - /** - * @notes 首页数据 - * @return Json - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - * @author 段誉 - * @date 2022/9/21 19:15 - */ - public function index() + + public array $notNeedLogin = ['code','suYuan']; + + public function index(): Json { - $result = IndexLogic::getIndexData(); - return $this->data($result); - } - - - /** - * @notes 全局配置 - * @return Json - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - * @author 段誉 - * @date 2022/9/21 19:41 - */ - public function config() - { - $result = IndexLogic::getConfigData(); - return $this->data($result); - } - - - /** - * @notes 政策协议 - * @return Json - * @author 段誉 - * @date 2022/9/20 20:00 - */ - public function policy() - { - $type = $this->request->get('type/s', ''); - $result = IndexLogic::getPolicyByType($type); - return $this->data($result); - } - - - /** - * @notes 装修信息 - * @return Json - * @author 段誉 - * @date 2022/9/21 18:37 - */ - public function decorate() - { - $id = $this->request->get('id/d'); - $result = IndexLogic::getDecorate($id); - return $this->data($result); + //获取土地信息 + $land = Land::where('user_id',$this->userId)->order('id desc')->findOrEmpty(); + if($land->isEmpty()){ + return $this->success('请求成功',[]); + } + $land['pic'] = json_decode($land['pic'],true); + //获取监测数据 + $landDeviceForSoil = LandDevice::where('land_id',$land['id'])->where('device_type',1)->findOrEmpty(); + if($landDeviceForSoil->isEmpty()){ + $data['soil_device'] = 0; + }else{ + $data['soil_device'] = 1; + $data['soil_monitor_data'] = SoilMonitor::where('device_id',$landDeviceForSoil['device_id'])->order('id desc')->findOrEmpty(); + } + $landDeviceForAir = LandDevice::where('land_id',$land['id'])->where('device_type',2)->findOrEmpty(); + if($landDeviceForAir->isEmpty()){ + $data['air_device'] = 0; + }else{ + $data['air_device'] = 1; + $data['air_monitor_data'] = AirMonitor::where('device_id',$landDeviceForAir['device_id'])->order('id desc')->findOrEmpty(); + } + $landDeviceForVideo = LandDevice::where('land_id',$land['id'])->where('device_type',3)->findOrEmpty(); + if($landDeviceForVideo->isEmpty()){ + $data['video_device'] = 0; + }else{ + $data['video_device'] = 1; + $data['video_monitor_data'] = ''; + } + return $this->success('请求成功',$land->toArray()); } // 获取短信验证码