request->isPost()) { return $this->fail('请求方式错误'); } $params = $this->request->post(['name','pic','area','crop','growth_cycle','cultivation_method','content','crop_info']); if(!isset($params['name']) || $params['name'] == ''){ return $this->fail('请填写名称'); } $result = Db::name('production_base')->insert($params); if($result){ return $this->success('添加成功'); }else{ return $this->fail('添加失败'); } } //修改种植基地 public function ediArea(): Json { if(!$this->request->isPost()) { return $this->fail('请求方式错误'); } $params = $this->request->post(['id','name','pic','area','crop','growth_cycle','cultivation_method','content','crop_info']); if(!isset($params['id']) || $params['id'] == '' || !isset($params['name']) || $params['name'] == ''){ return $this->fail('请填写名称'); } $result = Db::name('production_base')->update($params); if($result){ return $this->success('修改成功'); }else{ return $this->fail('修改失败'); } } //种植基地详情 public function areaDetail(): Json { if(!$this->request->isPost()) { return $this->fail('请求方式错误'); } $params = $this->request->post(['id']); if(!isset($params['id']) || $params['id'] == ''){ return $this->fail('请填写名称'); } $data = Db::name('production_base')->field('id,name,pic,area,crop,growth_cycle,cultivation_method,content,crop_info')->where('id',$params['id'])->findOrEmpty(); return $this->success('请求成功',$data); } //种植基地列表 public function areaLists(): Json { $data = Db::name('production_base')->field('id,name,pic,area,crop,growth_cycle,cultivation_method,content,crop_info')->select(); return $this->success('请求成功',$data->toArray()); } //添加环境监测数据 public function addMonitor(): Json { if(!$this->request->isPost()) { return $this->fail('请求方式错误'); } $params = $this->request->post(['production_base_id','soil_temperature','soil_moisture','room_temperature','air_humidity','air_quality_index','pond_temperature','pond_ph_value','wind_direction','wind_speed','illumination','rainfall','carbon_dioxide_content','nitrogen_content','methane_content','ammonia_nitrogen_content','nitrite_content','dissolved_oxygen','temperature_threshold','humidity_threshold','flag']); if(!isset($params['production_base_id']) || $params['production_base_id'] == ''){ return $this->fail('请选择区域'); } $result = Db::name('environmental_data')->insert($params); if($result){ return $this->success('添加成功'); }else{ return $this->fail('添加失败'); } } //修改环境检查数据 public function ediMonitor(): Json { if(!$this->request->isPost()) { return $this->fail('请求方式错误'); } $params = $this->request->post(['id','production_base_id','soil_temperature','soil_moisture','room_temperature','air_humidity','air_quality_index','pond_temperature','pond_ph_value','wind_direction','wind_speed','illumination','rainfall','carbon_dioxide_content','nitrogen_content','methane_content','ammonia_nitrogen_content','nitrite_content','dissolved_oxygen','temperature_threshold','humidity_threshold']); if(!isset($params['id']) || $params['id'] == '' || !isset($params['production_base_id']) || $params['production_base_id'] == ''){ return $this->fail('请选择区域'); } $result = Db::name('environmental_data')->update($params); if($result){ return $this->success('修改成功'); }else{ return $this->fail('修改失败'); } } //环境检查数据详情 public function monitorDetail(): Json { if(!$this->request->isPost()) { return $this->fail('请求方式错误'); } $params = $this->request->post(['id','flag']); if(empty($params['id']) || empty($params['flag'])){ return $this->fail('参数错误'); } $data = Db::name('environmental_data')->where('production_base_id',$params['id'])->where('flag',$params['flag'])->order('id desc')->findOrEmpty(); return $this->success('请求成功',$data); } public function monitorList() { $params = $this->request->get(['id','flag']); if(empty($params['id']) || empty($params['flag'])){ return $this->fail('参数错误'); } $data = Db::name('environmental_data')->where('production_base_id',$params['id'])->where('flag',$params['flag'])->limit(6)->select(); $content = Db::name('production_base')->where('id',$params['id'])->field('content')->findOrEmpty(); $result = []; foreach ($data as $v) { } dump($data);die; } //上传图片 public function imageUpload(): Json { if(!$this->request->isPost()) { return $this->fail('请求方式错误'); } $file = request()->file('file'); if(empty($file)){ return $this->fail('上传文件不存在'); } $save_name = Filesystem::disk('public')->putFile( '', $file); return $this->success('上传成功',['image'=>$this->request->domain().$save_name]); } }