Compare commits

..

No commits in common. "823654a768209fe9bf3b643b8e1e7df454803008" and "1a7119f42a16f98352131139c4c39183ab26a9dc" have entirely different histories.

4 changed files with 67 additions and 41 deletions

View File

@ -1,12 +1,26 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
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\LandProduct;
use app\common\model\land\LandDevice;
use app\common\model\monitor\AirMonitor;
use app\common\model\monitor\SoilMonitor;
use app\common\model\product\ProductDevice;
use think\facade\Log;
use think\response\Json;
@ -23,33 +37,40 @@ class IndexController extends BaseApiController
public function index(): Json
{
$params = $this->request->get(['land_id']);
$params = $this->request->get('land_id');
//获取土地信息
if(isset($params['land_id']) && $params['land_id'] !=''){
$data = Land::where('user_id',$this->userId)->where('id',$params['land_id'])->order('id desc')->findOrEmpty()->toArray();
$land = Land::where('user_id',$this->userId)->where('id',$params['land_id'])->order('id desc')->findOrEmpty();
}else{
$data = Land::where('user_id',$this->userId)->order('id desc')->findOrEmpty()->toArray();
$land = Land::where('user_id',$this->userId)->order('id desc')->findOrEmpty();
}
if(empty($data)){
if($land->isEmpty()){
return $this->success('请求成功',[]);
}
$data['pic'] = json_decode($data['pic'],true);
//获取绑定产品
$landProduct = LandProduct::where('land_id',$data['id'])->findOrEmpty();
if($landProduct->isEmpty()){
$data['monitor'] = [];
$land['pic'] = json_decode($land['pic'],true);
//获取监测数据
$landDeviceForSoil = LandDevice::where('land_id',$land['id'])->where('device_type',1)->findOrEmpty();
if($landDeviceForSoil->isEmpty()){
$land['soil_device'] = 0;
}else{
$device = ProductDevice::where('product_id',$landProduct['product_id'])->select();
foreach($device as $v) {
if($v['device_type'] == 1){
$data['monitor']['soil_monitor_data'] = SoilMonitor::where('device_id',$v['device_id'])->order('id desc')->findOrEmpty()->toArray();
$land['soil_device'] = 1;
$land['soil_monitor_data'] = SoilMonitor::where('device_id',$landDeviceForSoil['device_id'])->order('id desc')->findOrEmpty();
}
if($v['device_type'] == 2){
$data['monitor']['air_monitor_data'] = AirMonitor::where('device_id',$v['device_id'])->order('id desc')->findOrEmpty()->toArray();
$landDeviceForAir = LandDevice::where('land_id',$land['id'])->where('device_type',2)->findOrEmpty();
if($landDeviceForAir->isEmpty()){
$land['air_device'] = 0;
}else{
$land['air_device'] = 1;
$land['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()){
$land['video_device'] = 0;
}else{
$land['video_device'] = 1;
$land['video_monitor_data'] = '';
}
}
return $this->success('请求成功',$data);
return $this->success('请求成功',$land->toArray());
}
// 获取短信验证码

View File

@ -9,6 +9,9 @@
use app\common\model\geo\Town;
use app\common\model\geo\Village;
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\response\Json;
class LandController extends BaseApiController
@ -44,6 +47,28 @@
return $this->fail('土地信息不存在');
}
$data['pic'] = json_decode($data['pic'],true);
//获取监测数据
$landDeviceForSoil = LandDevice::where('land_id',$params['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',$params['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',$params['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('请求成功',$data->toArray());
}

View File

@ -1,10 +0,0 @@
<?php
namespace app\common\model\land;
use app\common\model\BaseModel;
class LandProduct extends BaseModel
{
protected $name = 'land_product';
}

View File

@ -1,10 +0,0 @@
<?php
namespace app\common\model\product;
use app\common\model\BaseModel;
class ProductDevice extends BaseModel
{
protected $name = 'product_device';
}