Compare commits
2 Commits
1a7119f42a
...
823654a768
Author | SHA1 | Date |
---|---|---|
weiz | 823654a768 | |
weiz | 7bbc063d5f |
|
@ -1,26 +1,12 @@
|
|||
<?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\LandDevice;
|
||||
use app\common\model\land\LandProduct;
|
||||
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;
|
||||
|
||||
|
@ -37,40 +23,33 @@ 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'] !=''){
|
||||
$land = Land::where('user_id',$this->userId)->where('id',$params['land_id'])->order('id desc')->findOrEmpty();
|
||||
$data = Land::where('user_id',$this->userId)->where('id',$params['land_id'])->order('id desc')->findOrEmpty()->toArray();
|
||||
}else{
|
||||
$land = Land::where('user_id',$this->userId)->order('id desc')->findOrEmpty();
|
||||
$data = Land::where('user_id',$this->userId)->order('id desc')->findOrEmpty()->toArray();
|
||||
}
|
||||
if($land->isEmpty()){
|
||||
if(empty($data)){
|
||||
return $this->success('请求成功',[]);
|
||||
}
|
||||
$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;
|
||||
$data['pic'] = json_decode($data['pic'],true);
|
||||
//获取绑定产品
|
||||
$landProduct = LandProduct::where('land_id',$data['id'])->findOrEmpty();
|
||||
if($landProduct->isEmpty()){
|
||||
$data['monitor'] = [];
|
||||
}else{
|
||||
$land['soil_device'] = 1;
|
||||
$land['soil_monitor_data'] = SoilMonitor::where('device_id',$landDeviceForSoil['device_id'])->order('id desc')->findOrEmpty();
|
||||
$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();
|
||||
}
|
||||
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('请求成功',$land->toArray());
|
||||
return $this->success('请求成功',$data);
|
||||
}
|
||||
|
||||
// 获取短信验证码
|
||||
|
|
|
@ -9,9 +9,6 @@
|
|||
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
|
||||
|
@ -47,28 +44,6 @@
|
|||
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());
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\model\land;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class LandProduct extends BaseModel
|
||||
{
|
||||
protected $name = 'land_product';
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\model\product;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class ProductDevice extends BaseModel
|
||||
{
|
||||
protected $name = 'product_device';
|
||||
}
|
Loading…
Reference in New Issue