suyuan/app/api/controller/IndexController.php

113 lines
3.7 KiB
PHP
Raw Normal View History

2023-11-21 11:51:27 +08:00
<?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;
2023-11-25 10:32:45 +08:00
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\facade\Log;
2023-11-21 11:51:27 +08:00
use think\response\Json;
/**
* index
* Class IndexController
* @package app\api\controller
*/
class IndexController extends BaseApiController
{
2023-11-25 10:32:45 +08:00
public array $notNeedLogin = ['code','suYuan'];
public function index(): Json
2023-11-21 11:51:27 +08:00
{
2023-11-25 13:42:20 +08:00
$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();
}else{
$land = Land::where('user_id',$this->userId)->order('id desc')->findOrEmpty();
}
2023-11-25 10:32:45 +08:00
if($land->isEmpty()){
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()){
2023-11-25 10:39:21 +08:00
$land['soil_device'] = 0;
2023-11-25 10:32:45 +08:00
}else{
2023-11-25 10:39:21 +08:00
$land['soil_device'] = 1;
$land['soil_monitor_data'] = SoilMonitor::where('device_id',$landDeviceForSoil['device_id'])->order('id desc')->findOrEmpty();
2023-11-25 10:32:45 +08:00
}
$landDeviceForAir = LandDevice::where('land_id',$land['id'])->where('device_type',2)->findOrEmpty();
if($landDeviceForAir->isEmpty()){
2023-11-25 10:39:21 +08:00
$land['air_device'] = 0;
2023-11-25 10:32:45 +08:00
}else{
2023-11-25 10:39:21 +08:00
$land['air_device'] = 1;
$land['air_monitor_data'] = AirMonitor::where('device_id',$landDeviceForAir['device_id'])->order('id desc')->findOrEmpty();
2023-11-25 10:32:45 +08:00
}
$landDeviceForVideo = LandDevice::where('land_id',$land['id'])->where('device_type',3)->findOrEmpty();
if($landDeviceForVideo->isEmpty()){
2023-11-25 10:39:21 +08:00
$land['video_device'] = 0;
2023-11-25 10:32:45 +08:00
}else{
2023-11-25 10:39:21 +08:00
$land['video_device'] = 1;
$land['video_monitor_data'] = '';
2023-11-25 10:32:45 +08:00
}
return $this->success('请求成功',$land->toArray());
2023-11-21 11:51:27 +08:00
}
// 获取短信验证码
public function code(): Json
{
//验证请求方式
if(!$this->request->isPost()){
return $this->fail('请求方式错误');
}
//获取参数
$params = $this->request->post(['phone','scene']);
if(empty($params['phone']) || empty($params['scene'])){
return $this->fail('缺少必要参数');
}
if(!in_array($params['scene'],[NoticeEnum::LOGIN_CAPTCHA,NoticeEnum::BIND_MOBILE_CAPTCHA,NoticeEnum::CHANGE_MOBILE_CAPTCHA,NoticeEnum::FIND_LOGIN_PASSWORD_CAPTCHA])){
return $this->fail('短信场景错误');
}
//发送短信
try {
$result = event('Notice', [
'scene_id' => $params['scene'],
'params' => [
'mobile' => $params['phone'],
'code' => mt_rand(100000, 999999),
]
]);
return $this->success($result[0]);
}catch(\Exception $e){
//记录日志
Log::error($e->getMessage());
return $this->fail($e->getMessage());
}
}
public function suYuan() {
}
2023-11-21 11:51:27 +08:00
}