From 474affde25f80d17160d2ca5851f7bc7e057c89a Mon Sep 17 00:00:00 2001 From: weiz Date: Thu, 2 Nov 2023 16:07:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=BA=AF=E6=BA=90=E7=A0=81?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E6=A8=A1=E5=9D=97=E7=9B=B8=E5=85=B3=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/action/ActionController.php | 6 +- .../action/ActionTypeController.php | 4 +- .../controller/code/CodeController.php | 182 +++++++++++++++++- .../controller/device/DeviceController.php | 10 + 4 files changed, 196 insertions(+), 6 deletions(-) create mode 100644 app/adminapi/controller/device/DeviceController.php diff --git a/app/adminapi/controller/action/ActionController.php b/app/adminapi/controller/action/ActionController.php index 681562a0..dbb7753d 100644 --- a/app/adminapi/controller/action/ActionController.php +++ b/app/adminapi/controller/action/ActionController.php @@ -41,7 +41,7 @@ } Db::name($this->actionDetailTableName)->insertAll($detail); }); - return $this->success('添加成功'); + return $this->success('添加成功',[],1,1); } //删除用户操作 @@ -59,7 +59,7 @@ //在删除操作信息 Db::name($this->actionTableName)->where('id',$params['action_id'])->delete(); }); - return $this->success('删除成功'); + return $this->success('删除成功',[],1,1); } //删除相关信息 @@ -73,7 +73,7 @@ //删除数据 $delRes = Db::name($this->actionDetailTableName)->where('id',$params['action_detail_id'])->delete(); //返回数据 - return $delRes ? $this->success('删除成功') : $this->fail('删除失败'); + return $delRes ? $this->success('删除成功',[],1,1) : $this->fail('删除失败',[],1,1); } //操作列表 diff --git a/app/adminapi/controller/action/ActionTypeController.php b/app/adminapi/controller/action/ActionTypeController.php index d9456c84..b346874c 100644 --- a/app/adminapi/controller/action/ActionTypeController.php +++ b/app/adminapi/controller/action/ActionTypeController.php @@ -25,7 +25,7 @@ //添加数据 $addRes = Db::name($this->actionTypeTableName)->insert(['name'=>$params['name']]); //返回数据 - return $addRes ? $this->success('添加成功') : $this->fail('添加失败'); + return $addRes ? $this->success('添加成功',[],1,1) : $this->fail('添加失败',[],1,1); } //修改操作类型 @@ -45,7 +45,7 @@ //更新数据 $ediRes = Db::name($this->actionTypeTableName)->where('id',$params['id'])->update(['name'=>$params['name']]); //返回数据 - return $ediRes ? $this->success('修改成功') : $this->fail('修改失败'); + return $ediRes ? $this->success('修改成功',[],1,1) : $this->fail('修改失败',[],1,1); } //操作记录列表 diff --git a/app/adminapi/controller/code/CodeController.php b/app/adminapi/controller/code/CodeController.php index 1ba04b0e..d5f9c5ee 100644 --- a/app/adminapi/controller/code/CodeController.php +++ b/app/adminapi/controller/code/CodeController.php @@ -118,11 +118,191 @@ return $this->success('请求成功',$result); } - public function detail() { + public function detail(): Json + { //type=>1-种植户 2-家禽养殖户 3-家畜养殖户 4-水产养殖户 $params = $this->request->get(['id','type']); if(empty($params['id']) || empty($params['type']) || !in_array($params['type'],[1,2,3,4])){ return $this->fail('参数错误'); } + //获取数据 + switch ($params['type']) { + case 1: + $data = Db::name('farmer_land_crop')->field('id,user_id,land_id,source_code as code,crop_variety as kind,crop_brand as breed,ripe_time,seed_time as create_time')->where('id',$params['id'])->findOrEmpty(); + if(!empty($data)){ + $data['status'] = !empty($data['ripe_time']) ? '已成熟' : '生长中'; + $data['create_time'] = date('Y-m-d H:i:s',$data['create_time']); + unset($data['ripe_time']); + //获取生长记录 + $data['action_lists'] = Db::name('farmer_land_crop_record')->field('action_id,action_content,create_time') + ->where('crop_id',$data['id'])->order('create_time desc')->limit(10)->select()->each(function($item){ + $action = Db::name('farmer_action')->where('id',$item['action_id'])->findOrEmpty(); + if(!empty($action)){ + $item['action_name'] = $action['name']; + } + $item['create_time'] = date('Y-m-d H:i:s',$item['create_time']); + return $item; + })->toArray(); + //获取监管记录 + $data['check_list'] = Db::name('farmer_land_check')->field('check_status,pic,create_time') + ->where('land_id',$data['land_id'])->order('create_time desc')->limit(10)->select()->each(function($item){ + //1-正常 2-未及时更新生产状况 3-生产状况与实际不符 + $item['status'] = $item['check_status'] == 1 ? '正常' : ($item['check_status'] == 2 ? '未及时更新生产状况' : '生产状况与实际不符'); + $item['create_time'] = date('Y-m-d H:i:s',$item['create_time']); + unset($item['check_status']); + return $item; + })->toArray(); + unset($data['land_id']); + } + break; + case 2: + $data = Db::name('farmer_poultry_breed')->field('id,user_id,code,kind,breed,status,create_time')->where('id',$params['id'])->findOrEmpty(); + if(!empty($data)){ + switch ($data['status']) { + case 1: + $data['status'] = '健康'; + break; + case 2: + $data['status'] = '产蛋期'; + break; + case 3: + $data['status'] = '生病隔离'; + break; + case 4: + $data['status'] = '可出栏'; + break; + case 5: + $data['status'] = '已出栏'; + break; + } + $data['create_time'] = date('Y-m-d H:i:s',$data['create_time']); + //获取生长记录 + $data['action_lists'] = Db::name('farmer_poultry_record')->field('action_id,action_content,create_time') + ->where('user_id',$data['user_id'])->order('create_time desc')->limit(10)->select()->each(function($item){ + $action = Db::name('farmer_action')->where('id',$item['action_id'])->findOrEmpty(); + if(!empty($action)){ + $item['action_name'] = $action['name']; + } + $item['create_time'] = date('Y-m-d H:i:s',$item['create_time']); + return $item; + })->toArray(); + //获取监管记录 + $data['check_list'] = Db::name('farmer_poultry_check')->field('check_status,pic,create_time') + ->where('user_id',$data['user_id'])->order('create_time desc')->limit(10)->select()->each(function($item){ + //1-正常 2-未及时更新生产状况 3-生产状况与实际不符 + $item['status'] = $item['check_status'] == 1 ? '正常' : ($item['check_status'] == 2 ? '未及时更新生产状况' : '生产状况与实际不符'); + $item['create_time'] = date('Y-m-d H:i:s',$item['create_time']); + unset($item['check_status']); + return $item; + })->toArray(); + } + break; + case 3: + $data = Db::name('farmer_animal_breed')->field('id,user_id,animal_code as code,animal_kind as kind,animal_breed as breed,animal_status as status,create_time')->where('id',$params['id'])->findOrEmpty(); + if(!empty($data)){ + switch ($data['status']) { + case 1: + $data['status'] = '健康'; + break; + case 2: + $data['status'] = '怀孕中'; + break; + case 3: + $data['status'] = '生病隔离'; + break; + case 4: + $data['status'] = '可出栏'; + break; + case 5: + $data['status'] = '已出栏'; + break; + } + $data['create_time'] = date('Y-m-d H:i:s',$data['create_time']); + //获取生长记录 + $data['action_lists'] = Db::name('farmer_animal_record')->field('action_id,action_content,create_time') + ->where('user_id',$data['user_id'])->order('create_time desc')->limit(10)->select()->each(function($item){ + $action = Db::name('farmer_action')->where('id',$item['action_id'])->findOrEmpty(); + if(!empty($action)){ + $item['action_name'] = $action['name']; + } + $item['create_time'] = date('Y-m-d H:i:s',$item['create_time']); + return $item; + })->toArray(); + //获取监管记录 + $data['check_list'] = Db::name('farmer_animal_check')->field('check_status,pic,create_time') + ->where('user_id',$data['user_id'])->order('create_time desc')->limit(10)->select()->each(function($item){ + //1-正常 2-未及时更新生产状况 3-生产状况与实际不符 + $item['status'] = $item['check_status'] == 1 ? '正常' : ($item['check_status'] == 2 ? '未及时更新生产状况' : '生产状况与实际不符'); + $item['create_time'] = date('Y-m-d H:i:s',$item['create_time']); + unset($item['check_status']); + return $item; + })->toArray(); + } + break; + case 4: + $data = Db::name('farmer_pond_breed')->field('id,user_id,pond_id,source_code as code,kind,breed,create_time')->where('id',$params['id'])->findOrEmpty(); + if(!empty($data)){ + $data['status'] = '生长中'; + $data['create_time'] = date('Y-m-d H:i:s',$data['create_time']); + //获取生长记录 + $data['action_lists'] = Db::name('farmer_pond_record')->field('action_id,action_content,create_time') + ->where('pond_id',$data['pond_id'])->order('create_time desc')->limit(10)->select()->each(function($item){ + $action = Db::name('farmer_action')->where('id',$item['action_id'])->findOrEmpty(); + if(!empty($action)){ + $item['action_name'] = $action['name']; + } + $item['create_time'] = date('Y-m-d H:i:s',$item['create_time']); + return $item; + })->toArray(); + //获取监管记录 + $data['check_list'] = Db::name('farmer_pond_check')->field('check_status,pic,create_time') + ->where('pond_id',$data['pond_id'])->order('create_time desc')->limit(10)->select()->each(function($item){ + //1-正常 2-未及时更新生产状况 3-生产状况与实际不符 + $item['status'] = $item['check_status'] == 1 ? '正常' : ($item['check_status'] == 2 ? '未及时更新生产状况' : '生产状况与实际不符'); + $item['create_time'] = date('Y-m-d H:i:s',$item['create_time']); + unset($item['check_status']); + return $item; + })->toArray(); + unset($data['pond_id']); + } + break; + default: + $data = []; + } + if(!empty($data)){ + $url = env('project.worker_domain').'/api/information/farmerInfo'; + $farmer = curl_post($url,[],['user_id'=>$data['user_id']]); + if(!empty($farmer) && $farmer['code'] == 1){ + $data['address'] = $farmer['data']['area_name'].$farmer['data']['street_name'].$farmer['data']['village_name'].$farmer['data']['brigade_name'].$farmer['data']['address']; + $data['captain_name'] = $farmer['data']['captain_name']; + $data['group_name'] = $farmer['data']['group_name']; + $data['farmer_name'] = $farmer['data']['name']; + } + } + return $this->success('请求成功',$data); + } + + public function landEnv(): Json + { + $params = $this->request->get(['user_id','start_time','end_time']); + if(empty($params['user_id']) || empty($params['start_time']) || empty($params['end_time'])){ + return $this->fail('参数错误'); + } + //获取数据 + $data = Db::name('farmer_land_env_data')->where('user_id',$params['user_id'])->whereBetweenTime('create_time', $params['start_time'], $params['end_time'])->order('id asc')->select()->each(function($item){ + $item['create_time'] = date('m-d',$item['create_time']); + return $item; + })->toArray(); + if(empty($data)){ + return $this->fail('暂无数据'); + } + $result = [ + ['soil_temp' => '土地温度','categories' => array_column($data,'create_time'),'series'=>['name'=>'目标值','data'=>array_column($data,'soil_temp')],'max'=>max(array_column($data,'soil_temp'))], + ['soil_mois' => '土地湿度','categories' => array_column($data,'create_time'),'series'=>['name'=>'目标值','data'=>array_column($data,'soil_mois')],'max'=>max(array_column($data,'soil_mois'))], + ['p_content' => '土壤磷含量','categories' => array_column($data,'create_time'),'series'=>['name'=>'目标值','data'=>array_column($data,'p_content')],'max'=>max(array_column($data,'p_content'))], + ['n_content' => '土壤氮含量','categories' => array_column($data,'create_time'),'series'=>['name'=>'目标值','data'=>array_column($data,'n_content')],'max'=>max(array_column($data,'n_content'))], + ['k_content' => '土壤钾含量','categories' => array_column($data,'create_time'),'series'=>['name'=>'目标值','data'=>array_column($data,'k_content')],'max'=>max(array_column($data,'k_content'))], + ]; + return $this->success('请求成功',$result); } } \ No newline at end of file diff --git a/app/adminapi/controller/device/DeviceController.php b/app/adminapi/controller/device/DeviceController.php new file mode 100644 index 00000000..58b45c59 --- /dev/null +++ b/app/adminapi/controller/device/DeviceController.php @@ -0,0 +1,10 @@ +