新增首页接口

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;
@ -29,67 +33,39 @@ 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);
//获取监测数据
/** $landDeviceForSoil = LandDevice::where('land_id',$land['id'])->where('device_type',1)->findOrEmpty();
* @notes 全局配置 if($landDeviceForSoil->isEmpty()){
* @return Json $data['soil_device'] = 0;
* @throws \think\db\exception\DataNotFoundException }else{
* @throws \think\db\exception\DbException $data['soil_device'] = 1;
* @throws \think\db\exception\ModelNotFoundException $data['soil_monitor_data'] = SoilMonitor::where('device_id',$landDeviceForSoil['device_id'])->order('id desc')->findOrEmpty();
* @author 段誉
* @date 2022/9/21 19:41
*/
public function config()
{
$result = IndexLogic::getConfigData();
return $this->data($result);
} }
$landDeviceForAir = LandDevice::where('land_id',$land['id'])->where('device_type',2)->findOrEmpty();
if($landDeviceForAir->isEmpty()){
/** $data['air_device'] = 0;
* @notes 政策协议 }else{
* @return Json $data['air_device'] = 1;
* @author 段誉 $data['air_monitor_data'] = AirMonitor::where('device_id',$landDeviceForAir['device_id'])->order('id desc')->findOrEmpty();
* @date 2022/9/20 20:00
*/
public function policy()
{
$type = $this->request->get('type/s', '');
$result = IndexLogic::getPolicyByType($type);
return $this->data($result);
} }
$landDeviceForVideo = LandDevice::where('land_id',$land['id'])->where('device_type',3)->findOrEmpty();
if($landDeviceForVideo->isEmpty()){
/** $data['video_device'] = 0;
* @notes 装修信息 }else{
* @return Json $data['video_device'] = 1;
* @author 段誉 $data['video_monitor_data'] = '';
* @date 2022/9/21 18:37 }
*/ return $this->success('请求成功',$land->toArray());
public function decorate()
{
$id = $this->request->get('id/d');
$result = IndexLogic::getDecorate($id);
return $this->data($result);
} }
// 获取短信验证码 // 获取短信验证码