request->get(['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(); }else{ $data = Land::where('user_id',$this->userId)->order('id desc')->findOrEmpty()->toArray(); } if(empty($data)){ return $this->success('请求成功',[]); } $data['pic'] = json_decode($data['pic'],true); //获取绑定产品 $landProduct = LandProduct::where('land_id',$data['id'])->findOrEmpty(); if($landProduct->isEmpty()){ $data['monitor'] = []; }else{ $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(); } } } return $this->success('请求成功',$data); } // 获取短信验证码 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() { } }