新增首页接口

This commit is contained in:
weiz 2023-11-25 10:32:45 +08:00
parent c132164e06
commit 6be8667105
1 changed files with 37 additions and 61 deletions

View File

@ -17,6 +17,10 @@ namespace app\api\controller;
use app\api\logic\IndexLogic; use app\api\logic\IndexLogic;
use app\common\enum\notice\NoticeEnum; use app\common\enum\notice\NoticeEnum;
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; use think\facade\Log;
use think\response\Json; use think\response\Json;
@ -28,68 +32,40 @@ use think\response\Json;
*/ */
class IndexController extends BaseApiController class IndexController extends BaseApiController
{ {
public array $notNeedLogin = ['code','suYuan'];
public array $notNeedLogin = ['index', 'config', 'policy', 'decorate','code','suYuan'];
public function index(): Json
/**
* @notes 首页数据
* @return Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2022/9/21 19:15
*/
public function index()
{ {
$result = IndexLogic::getIndexData(); //获取土地信息
return $this->data($result); $land = Land::where('user_id',$this->userId)->order('id desc')->findOrEmpty();
} if($land->isEmpty()){
return $this->success('请求成功',[]);
}
/** $land['pic'] = json_decode($land['pic'],true);
* @notes 全局配置 //获取监测数据
* @return Json $landDeviceForSoil = LandDevice::where('land_id',$land['id'])->where('device_type',1)->findOrEmpty();
* @throws \think\db\exception\DataNotFoundException if($landDeviceForSoil->isEmpty()){
* @throws \think\db\exception\DbException $data['soil_device'] = 0;
* @throws \think\db\exception\ModelNotFoundException }else{
* @author 段誉 $data['soil_device'] = 1;
* @date 2022/9/21 19:41 $data['soil_monitor_data'] = SoilMonitor::where('device_id',$landDeviceForSoil['device_id'])->order('id desc')->findOrEmpty();
*/ }
public function config() $landDeviceForAir = LandDevice::where('land_id',$land['id'])->where('device_type',2)->findOrEmpty();
{ if($landDeviceForAir->isEmpty()){
$result = IndexLogic::getConfigData(); $data['air_device'] = 0;
return $this->data($result); }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',$land['id'])->where('device_type',3)->findOrEmpty();
* @notes 政策协议 if($landDeviceForVideo->isEmpty()){
* @return Json $data['video_device'] = 0;
* @author 段誉 }else{
* @date 2022/9/20 20:00 $data['video_device'] = 1;
*/ $data['video_monitor_data'] = '';
public function policy() }
{ return $this->success('请求成功',$land->toArray());
$type = $this->request->get('type/s', '');
$result = IndexLogic::getPolicyByType($type);
return $this->data($result);
}
/**
* @notes 装修信息
* @return Json
* @author 段誉
* @date 2022/9/21 18:37
*/
public function decorate()
{
$id = $this->request->get('id/d');
$result = IndexLogic::getDecorate($id);
return $this->data($result);
} }
// 获取短信验证码 // 获取短信验证码