Merge branch 'preview'
# Conflicts: # app/api/controller/IndexController.php
This commit is contained in:
commit
ddc10275a5
|
@ -1,172 +1,175 @@
|
||||||
<?php
|
<?php
|
||||||
namespace app\api\controller;
|
namespace app\api\controller;
|
||||||
|
|
||||||
use app\common\enum\notice\NoticeEnum;
|
use app\common\enum\notice\NoticeEnum;
|
||||||
use app\common\model\action\Action;
|
use app\common\model\action\Action;
|
||||||
use app\common\model\device\Device;
|
use app\common\model\device\Device;
|
||||||
use app\common\model\device\MonitorThreshold;
|
use app\common\model\device\MonitorThreshold;
|
||||||
use app\common\model\land\Land;
|
use app\common\model\land\Land;
|
||||||
use app\common\model\land\LandProduct;
|
use app\common\model\land\LandProduct;
|
||||||
use app\common\model\LandCollection;
|
use app\common\model\LandCollection;
|
||||||
use app\common\model\monitor\MonitorData;
|
use app\common\model\monitor\MonitorData;
|
||||||
use app\common\model\plant\Plant;
|
use app\common\model\plant\Plant;
|
||||||
use app\common\model\product\ProductDevice;
|
use app\common\model\product\ProductDevice;
|
||||||
use think\facade\Log;
|
use think\facade\Log;
|
||||||
use think\response\Json;
|
use think\response\Json;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* index
|
* index
|
||||||
* Class IndexController
|
* Class IndexController
|
||||||
* @package app\api\controller
|
* @package app\api\controller
|
||||||
*/
|
*/
|
||||||
class IndexController extends BaseApiController
|
class IndexController extends BaseApiController
|
||||||
{
|
{
|
||||||
|
|
||||||
public array $notNeedLogin = ['code','suYuan'];
|
public array $notNeedLogin = ['code','suYuan'];
|
||||||
|
|
||||||
//溯源首页
|
//溯源首页
|
||||||
public function index(): Json
|
public function index(): Json
|
||||||
{
|
{
|
||||||
$params = $this->request->get(['land_id']);
|
$params = $this->request->get(['land_id']);
|
||||||
//获取土地信息
|
//获取土地信息
|
||||||
if(isset($params['land_id']) && $params['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();
|
$data = Land::where('user_id',$this->userId)->where('id',$params['land_id'])->order('id desc')->findOrEmpty()->toArray();
|
||||||
}else{
|
}else{
|
||||||
$data = Land::where('user_id',$this->userId)->order('id desc')->findOrEmpty()->toArray();
|
$data = Land::where('user_id',$this->userId)->order('id desc')->findOrEmpty()->toArray();
|
||||||
}
|
}
|
||||||
if(empty($data)){
|
if(empty($data)){
|
||||||
return $this->success('请求成功',[]);
|
return $this->success('请求成功',[]);
|
||||||
}
|
}
|
||||||
$data['pic'] = json_decode($data['pic'],true);
|
$data['pic'] = json_decode($data['pic'],true);
|
||||||
//获取绑定产品
|
//获取绑定产品
|
||||||
$landProduct = LandProduct::where('land_id',$data['id'])->findOrEmpty();
|
$landProduct = LandProduct::where('land_id',$data['id'])->findOrEmpty();
|
||||||
if($landProduct->isEmpty()){
|
if($landProduct->isEmpty()){
|
||||||
$data['monitor'] = [];
|
$data['monitor'] = [];
|
||||||
}else{
|
}else{
|
||||||
$landCollection = LandCollection::where('land_id',$params['land_id'])->order('id desc')->findOrEmpty();
|
$productDevice = ProductDevice::where('product_id',$landProduct['product_id'])->findOrEmpty();
|
||||||
if($landCollection->isEmpty()){
|
$device = Device::where('id', $productDevice['device_id'])->findOrEmpty();
|
||||||
$data['monitor'] = [];
|
$data['video_url'] = $device['video_url'];
|
||||||
}else{
|
$landCollection = LandCollection::where('land_id',$params['land_id'])->order('id desc')->findOrEmpty();
|
||||||
$data['monitor']['soil_monitor_data'] = [
|
if($landCollection->isEmpty()){
|
||||||
'soil_temperature'=>$landCollection['soil_temperature'],
|
$data['monitor'] = [];
|
||||||
'soil_moisture'=>$landCollection['soil_moisture'],
|
}else{
|
||||||
'conductivity'=>$landCollection['soil_conductivity'],
|
$data['monitor']['soil_monitor_data'] = [
|
||||||
'ph'=>$landCollection['soil_PH'],
|
'soil_temperature'=>$landCollection['soil_temperature'],
|
||||||
'n_content'=>$landCollection['soil_potassium_phosphate_nitrogen'],
|
'soil_moisture'=>$landCollection['soil_moisture'],
|
||||||
'p_content'=>$landCollection['soil_potassium_phosphate_phosphorus'],
|
'conductivity'=>$landCollection['soil_conductivity'],
|
||||||
'k_content'=>$landCollection['soil_potassium_phosphate_potassium'],
|
'ph'=>$landCollection['soil_PH'],
|
||||||
'create_time' => $landCollection['create_time']
|
'n_content'=>$landCollection['soil_potassium_phosphate_nitrogen'],
|
||||||
];
|
'p_content'=>$landCollection['soil_potassium_phosphate_phosphorus'],
|
||||||
$data['monitor']['air_monitor_data'] = [
|
'k_content'=>$landCollection['soil_potassium_phosphate_potassium'],
|
||||||
'wind_direction'=>$landCollection['wind_direction'],
|
'create_time' => $landCollection['create_time']
|
||||||
'wind_speed'=>$landCollection['wind_speed'],
|
];
|
||||||
'air_temperature'=>$landCollection['ambient_temperature'],
|
$data['monitor']['air_monitor_data'] = [
|
||||||
'air_moisture'=>$landCollection['ambient_humidity'],
|
'wind_direction'=>$landCollection['wind_direction'],
|
||||||
'co2_content'=>$landCollection['carbon_dioxide'],
|
'wind_speed'=>$landCollection['wind_speed'],
|
||||||
'pressure'=>$landCollection['ambient_air_pressure'],
|
'air_temperature'=>$landCollection['ambient_temperature'],
|
||||||
'rainfall'=>$landCollection['rainfall'],
|
'air_moisture'=>$landCollection['ambient_humidity'],
|
||||||
'light_intensity'=>$landCollection['ambient_lighting'],
|
'co2_content'=>$landCollection['carbon_dioxide'],
|
||||||
'create_time' => $landCollection['create_time']
|
'pressure'=>$landCollection['ambient_air_pressure'],
|
||||||
];
|
'rainfall'=>$landCollection['rainfall'],
|
||||||
$monitorThreshold = MonitorThreshold::select();
|
'light_intensity'=>$landCollection['ambient_lighting'],
|
||||||
if($monitorThreshold->toArray()!=null){
|
'create_time' => $landCollection['create_time']
|
||||||
$monitorThreshold=$monitorThreshold[0];
|
];
|
||||||
}else{
|
$monitorThreshold = MonitorThreshold::select();
|
||||||
$monitorThreshold=[];
|
if($monitorThreshold->toArray()!=null){
|
||||||
}
|
$monitorThreshold=$monitorThreshold[0];
|
||||||
$monitorThreshold['ambient_air_pressure_max'] = 120;
|
}else{
|
||||||
$monitorThreshold['ambient_air_pressure_min'] = 10;
|
$monitorThreshold=[];
|
||||||
$data['monitor']['threshold'] = $monitorThreshold;
|
}
|
||||||
}
|
$monitorThreshold['ambient_air_pressure_max'] = 120;
|
||||||
}
|
$monitorThreshold['ambient_air_pressure_min'] = 10;
|
||||||
return $this->success('请求成功',$data);
|
$data['monitor']['threshold'] = $monitorThreshold;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//视频监控
|
return $this->success('请求成功',$data);
|
||||||
public function video(): Json
|
}
|
||||||
{
|
|
||||||
$params = $this->request->get(['land_id']);
|
//视频监控
|
||||||
if(empty($params['land_id'])){
|
public function video(): Json
|
||||||
return $this->fail('参数错误');
|
{
|
||||||
}
|
$params = $this->request->get(['land_id']);
|
||||||
//获取土地绑定的产品
|
if(empty($params['land_id'])){
|
||||||
$landProduct = LandProduct::where('land_id',$params['land_id'])->findOrEmpty();
|
return $this->fail('参数错误');
|
||||||
if($landProduct->isEmpty()){
|
}
|
||||||
return $this->fail('当前土地未绑定设备产品');
|
//获取土地绑定的产品
|
||||||
}
|
$landProduct = LandProduct::where('land_id',$params['land_id'])->findOrEmpty();
|
||||||
//获取监控设备
|
if($landProduct->isEmpty()){
|
||||||
$productDevice = ProductDevice::where('product_id',$landProduct['product_id'])->where('device_type',3)->column('device_id');
|
return $this->fail('当前土地未绑定设备产品');
|
||||||
if(empty($productDevice)){
|
}
|
||||||
return $this->fail('当前土地未绑定监控设备');
|
//获取监控设备
|
||||||
}
|
$productDevice = ProductDevice::where('product_id',$landProduct['product_id'])->where('device_type',3)->column('device_id');
|
||||||
//获取设备编号
|
if(empty($productDevice)){
|
||||||
$device = Device::where('id','in',$productDevice)->select();
|
return $this->fail('当前土地未绑定监控设备');
|
||||||
return $this->success('请求成功',$device->toArray());
|
}
|
||||||
}
|
//获取设备编号
|
||||||
|
$device = Device::where('id','in',$productDevice)->select();
|
||||||
// 获取短信验证码
|
return $this->success('请求成功',$device->toArray());
|
||||||
public function code(): Json
|
}
|
||||||
{
|
|
||||||
//验证请求方式
|
// 获取短信验证码
|
||||||
if(!$this->request->isPost()){
|
public function code(): Json
|
||||||
return $this->fail('请求方式错误');
|
{
|
||||||
}
|
//验证请求方式
|
||||||
//获取参数
|
if(!$this->request->isPost()){
|
||||||
$params = $this->request->post(['phone','scene']);
|
return $this->fail('请求方式错误');
|
||||||
if(empty($params['phone']) || empty($params['scene'])){
|
}
|
||||||
return $this->fail('缺少必要参数');
|
//获取参数
|
||||||
}
|
$params = $this->request->post(['phone','scene']);
|
||||||
if(!in_array($params['scene'],[NoticeEnum::LOGIN_CAPTCHA,NoticeEnum::BIND_MOBILE_CAPTCHA,NoticeEnum::CHANGE_MOBILE_CAPTCHA,NoticeEnum::FIND_LOGIN_PASSWORD_CAPTCHA])){
|
if(empty($params['phone']) || empty($params['scene'])){
|
||||||
return $this->fail('短信场景错误');
|
return $this->fail('缺少必要参数');
|
||||||
}
|
}
|
||||||
//发送短信
|
if(!in_array($params['scene'],[NoticeEnum::LOGIN_CAPTCHA,NoticeEnum::BIND_MOBILE_CAPTCHA,NoticeEnum::CHANGE_MOBILE_CAPTCHA,NoticeEnum::FIND_LOGIN_PASSWORD_CAPTCHA])){
|
||||||
try {
|
return $this->fail('短信场景错误');
|
||||||
$result = event('Notice', [
|
}
|
||||||
'scene_id' => $params['scene'],
|
//发送短信
|
||||||
'params' => [
|
try {
|
||||||
'mobile' => $params['phone'],
|
$result = event('Notice', [
|
||||||
'code' => mt_rand(100000, 999999),
|
'scene_id' => $params['scene'],
|
||||||
]
|
'params' => [
|
||||||
]);
|
'mobile' => $params['phone'],
|
||||||
return $this->success($result[0]);
|
'code' => mt_rand(100000, 999999),
|
||||||
}catch(\Exception $e){
|
]
|
||||||
//记录日志
|
]);
|
||||||
Log::error($e->getMessage());
|
return $this->success($result[0]);
|
||||||
return $this->fail($e->getMessage());
|
}catch(\Exception $e){
|
||||||
}
|
//记录日志
|
||||||
}
|
Log::error($e->getMessage());
|
||||||
|
return $this->fail($e->getMessage());
|
||||||
public function suYuan(): Json
|
}
|
||||||
{
|
}
|
||||||
$params = $this->request->get(['plant_id']);
|
|
||||||
if(empty($params['plant_id'])){
|
public function suYuan(): Json
|
||||||
return $this->fail('参数错误');
|
{
|
||||||
}
|
$params = $this->request->get(['plant_id']);
|
||||||
$plantInfo = Plant::where('id',$params['plant_id'])->findOrEmpty();
|
if(empty($params['plant_id'])){
|
||||||
if($plantInfo->isEmpty()){
|
return $this->fail('参数错误');
|
||||||
return $this->fail('种植信息错误');
|
}
|
||||||
}
|
$plantInfo = Plant::where('id',$params['plant_id'])->findOrEmpty();
|
||||||
if($plantInfo['status'] != 2){
|
if($plantInfo->isEmpty()){
|
||||||
return $this->fail('种植信息状态错误');
|
return $this->fail('种植信息错误');
|
||||||
}
|
}
|
||||||
$landInfo = Land::where('id',$plantInfo['land_id'])->findOrEmpty();
|
if($plantInfo['status'] != 2){
|
||||||
if($landInfo->isEmpty()){
|
return $this->fail('种植信息状态错误');
|
||||||
return $this->fail('土地信息错误');
|
}
|
||||||
}
|
$landInfo = Land::where('id',$plantInfo['land_id'])->findOrEmpty();
|
||||||
$plantInfo['pic'] = json_decode($plantInfo['pic'],true);
|
if($landInfo->isEmpty()){
|
||||||
$plantInfo['group_day'] = floor(($plantInfo['harvest_date'] - $plantInfo['plant_date']) / 86400);
|
return $this->fail('土地信息错误');
|
||||||
$plantInfo['plant_date'] = date('Y-m-d',$plantInfo['plant_date']);
|
}
|
||||||
$plantInfo['harvest_date'] = date('Y-m-d',$plantInfo['harvest_date']);
|
$plantInfo['pic'] = json_decode($plantInfo['pic'],true);
|
||||||
$plantInfo['land_name'] = $landInfo['title'];
|
$plantInfo['group_day'] = floor(($plantInfo['harvest_date'] - $plantInfo['plant_date']) / 86400);
|
||||||
$plantInfo['land_area'] = $landInfo['total_area'];
|
$plantInfo['plant_date'] = date('Y-m-d',$plantInfo['plant_date']);
|
||||||
$plantInfo['land_address'] = $landInfo['province_name'].$landInfo['city_name'].$landInfo['county_name'].$landInfo['town_name'].$landInfo['village_name'].$landInfo['group_name'];
|
$plantInfo['harvest_date'] = date('Y-m-d',$plantInfo['harvest_date']);
|
||||||
//获取操作
|
$plantInfo['land_name'] = $landInfo['title'];
|
||||||
$action = Action::field('type,type_text,detail,create_time')->where('plant_id',$params['plant_id'])->select()->each(function($item){
|
$plantInfo['land_area'] = $landInfo['total_area'];
|
||||||
$item['detail'] = json_decode($item['detail'],true);
|
$plantInfo['land_address'] = $landInfo['province_name'].$landInfo['city_name'].$landInfo['county_name'].$landInfo['town_name'].$landInfo['village_name'].$landInfo['group_name'];
|
||||||
return $item;
|
//获取操作
|
||||||
})->toArray();
|
$action = Action::field('type,type_text,detail,create_time')->where('plant_id',$params['plant_id'])->select()->each(function($item){
|
||||||
$plantInfo['actions'] = $action;
|
$item['detail'] = json_decode($item['detail'],true);
|
||||||
return $this->success('请求成功',$plantInfo->toArray());
|
return $item;
|
||||||
}
|
})->toArray();
|
||||||
|
$plantInfo['actions'] = $action;
|
||||||
|
return $this->success('请求成功',$plantInfo->toArray());
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue