suyuan/app/adminapi/controller/SuYuanController.php

120 lines
5.0 KiB
PHP
Raw Normal View History

2023-10-14 13:36:39 +08:00
<?php
namespace app\adminapi\controller;
use think\facade\Db;
use think\response\Json;
class SuYuanController extends BaseAdminController
{
public array $notNeedLogin = ['areaLists','areaDetail','monitorDetail'];
//添加种植基地
public function addArea(): Json
{
if(!$this->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('id',$params['id'])->where('flag',$params['flag'])->findOrEmpty();
$content = Db::name('production_base')->where('id',$data['production_base_id'])->field('content')->findOrEmpty();
$data['content'] = $content['content'];
return $this->success('请求成功',$data);
}
}