This commit is contained in:
yaooo 2023-11-28 17:22:17 +08:00
commit 465662229c
3 changed files with 92 additions and 10 deletions

View File

@ -2,11 +2,12 @@
namespace app\api\controller;
use app\common\enum\notice\NoticeEnum;
use app\common\model\action\Action;
use app\common\model\device\Device;
use app\common\model\land\Land;
use app\common\model\land\LandProduct;
use app\common\model\monitor\AirMonitor;
use app\common\model\monitor\MonitorData;
use app\common\model\monitor\SoilMonitor;
use app\common\model\plant\Plant;
use app\common\model\product\ProductDevice;
use think\facade\Log;
use think\response\Json;
@ -22,6 +23,7 @@ class IndexController extends BaseApiController
public array $notNeedLogin = ['code','suYuan'];
//溯源首页
public function index(): Json
{
$params = $this->request->get(['land_id']);
@ -70,6 +72,31 @@ class IndexController extends BaseApiController
return $this->success('请求成功',$data);
}
//视频监控
public function video() {
$params = $this->request->get(['land_id']);
if(empty($params['land_id'])){
return $this->fail('参数错误');
}
//获取土地绑定的产品
$landProduct = LandProduct::where('land_id',$params['land_id'])->findOrEmpty();
if($landProduct->isEmpty()){
return $this->fail('当前土地未绑定设备产品');
}
//获取监控设备
$productDevice = ProductDevice::where('product_id',$landProduct['product_id'])->where('device_type',3)->findOrEmpty();
if($productDevice->isEmpty()){
return $this->fail('当前土地未绑定监控设备');
}
//获取设备编号
$device = Device::where('id',$productDevice['device_id'])->findOrEmpty();
if($device->isEmpty()){
return $this->fail('监控设备信息错误');
}
//获取监控数据
//todo
}
// 获取短信验证码
public function code(): Json
{
@ -102,9 +129,34 @@ class IndexController extends BaseApiController
}
}
public function suYuan() {
public function suYuan(): Json
{
$params = $this->request->get(['plant_id']);
if(empty($params['plant_id'])){
return $this->fail('参数错误');
}
$plantInfo = Plant::where('id',$params['plant_id'])->findOrEmpty();
if($plantInfo->isEmpty()){
return $this->fail('种植信息错误');
}
if($plantInfo['status'] != 2){
return $this->fail('种植信息状态错误');
}
$landInfo = Land::where('id',$plantInfo['land_id'])->findOrEmpty();
if($landInfo->isEmpty()){
return $this->fail('土地信息错误');
}
$plantInfo['pic'] = json_decode($plantInfo['pic'],true);
$plantInfo['plant_date'] = date('Y-m-d',$plantInfo['plant_date']);
$plantInfo['land_name'] = $landInfo['title'];
$plantInfo['land_area'] = $landInfo['total_area'];
$plantInfo['land_address'] = $landInfo['province_name'].$landInfo['city_name'].$landInfo['county_name'].$landInfo['town_name'].$landInfo['village_name'].$landInfo['group_name'];
//获取操作
$action = Action::field('type,type_text,detail,create_time')->where('plant_id',$params['plant_id'])->select()->each(function($item){
$item['detail'] = json_decode($item['detail'],true);
return $item;
})->toArray();
$plantInfo['actions'] = $action;
return $this->success('请求成功',$plantInfo->toArray());
}
}

View File

@ -129,13 +129,14 @@
public function product(): Json
{
$data = Product::field('id as product_id,code,name')->where('status',1)->select()->toArray();
$result = [];
foreach ($data as $k=>$v) {
$productDevice = ProductDevice::where('product_id',$v['product_id'])->select()->toArray();
if(empty($productDevice)){
unset($data[$k]);
if(!empty($productDevice)){
$result[] = $v;
}
}
return $this->success('请求成功',$data);
return $this->success('请求成功',$result);
}
//绑定产品

View File

@ -2,7 +2,36 @@
namespace app\api\controller;
use app\common\model\device\Device;
use app\common\model\device\MonitorAlarm;
use think\response\Json;
class monitorController extends BaseApiController
{
public array $notNeedLogin = ['alarm'];
//获取报警数据
public function alarm(): Json
{
$params = $this->request->post(['device_code','content','value']);
if(empty($params['device_code']) || empty($params['content']) || empty($params['value'])){
return $this->fail('缺少必要参数');
}
//获取设备信息
$device = Device::where('code',$params['device_code'])->findOrEmpty();
if($device->isEmpty()){
return $this->fail('设备不匹配');
}
//写入数据
$res = MonitorAlarm::create([
'user_id' => $device['user_id'],
'device_id' => $device['id'],
'type' => $device['type'],
'content' => $params['content'],
'value' => $params['value'],
'solution' => '',
'create_time' => time(),
'update_time' => time()
]);
return $res->id ? $this->success('数据添加成功') : $this->fail('数据添加失败');
}
}