windModel = $windModel; } /** * 列表 * @time 2022年04月27日 10:49 * @param Request $request */ public function index(Request $request) : \think\Response { return CatchResponse::paginate($this->windModel->getList()); } /** * 列表 * @time 2022年04月27日 10:49 * @param Request $request */ public function getWindList(Request $request) : \think\Response { $list=$this->windModel->getWindList(); foreach($list as $val){ if($val['wind_shape']=='circle'){ $val['center_lng']=$val['wind_info']['center']['lng']; $val['center_lat']=$val['wind_info']['center']['lat']; } if($val['wind_shape']=='polygon'){ $val['center_lng']=$val['wind_info'][0]['lng']; $val['center_lat']=$val['wind_info'][0]['lat']; } } return CatchResponse::success($list); } /** * 保存信息 * @time 2022年04月27日 10:49 * @param Request $request */ public function save(Request $request) : \think\Response { $post = $request->post(); if (!isset($post['name']) || !$post['name']) { return CatchResponse::fail('风场名称不能为空'); } if (!isset($post['wind_shape']) || !$post['wind_shape']) { return CatchResponse::fail('获取风场类型失败'); } if (!isset($post['wind_info']) || !is_array($post['wind_info'])) { return CatchResponse::fail('获取风场坐标数据失败'); } if (!isset($post['department_id']) || !is_array($post['department_id'])) { return CatchResponse::fail('获取风场所属部门失败'); } // 检测名称重复 if($this->windModel->where('name',$post['name'])->count()){ return CatchResponse::fail('风场名称已存在'); } $post['wind_info'] = json_encode($post['wind_info']); $post['department_id'] = array_pop($post['department_id']); return CatchResponse::success($this->windModel->storeBy($post)); } /** * 读取 * @time 2022年04月27日 10:49 * @param $id */ public function read($id) : \think\Response { return CatchResponse::success($this->windModel->findBy($id)); } /** * 更新 * @time 2022年04月27日 10:49 * @param Request $request * @param $id */ public function update(Request $request, $id) : \think\Response { $post = $request->post(); if(isset($post['name'])){ // 检测名称重复 $n_id = $this->windModel->where('name',$post['name'])->value('id'); if($n_id && ($n_id != $id)){ return CatchResponse::fail('风场名称已存在'); } } if(isset($post['department_id']) && is_array($post['department_id'])){ $post['department_id'] = array_pop($post['department_id']); } $post['wind_info'] = json_encode($post['wind_info']); return CatchResponse::success($this->windModel->updateBy($id, $post)); } /** * 删除 * @time 2022年04月27日 10:49 * @param $id */ public function delete($id) : \think\Response { return CatchResponse::success($this->windModel->deleteBy($id,true)); } /** * 获取风场下拉菜单 * @time 2022年04月28日 19:53 */ public function getWindOptions(Request $request){ $list=$this->windModel->field('id as value,name as text')->select(); return CatchResponse::success($list); } }