|
@@ -33,7 +33,28 @@ class Wind extends CatchController
|
|
|
*/
|
|
|
public function save(Request $request) : \think\Response
|
|
|
{
|
|
|
- return CatchResponse::success($this->windModel->storeBy($request->post()));
|
|
|
+ $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));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -54,7 +75,30 @@ class Wind extends CatchController
|
|
|
*/
|
|
|
public function update(Request $request, $id) : \think\Response
|
|
|
{
|
|
|
- return CatchResponse::success($this->windModel->updateBy($id, $request->post()));
|
|
|
+ $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']) || !$post['department_id']) {
|
|
|
+ return CatchResponse::fail('获取风场所属部门失败');
|
|
|
+ }
|
|
|
+ // 检测名称重复
|
|
|
+ $n_id = $this->windModel->where('name',$post['name'])->value('id');
|
|
|
+ if($n_id && $n_id != $id){
|
|
|
+ return CatchResponse::fail('风场名称已存在');
|
|
|
+ }
|
|
|
+ $post['wind_info'] = json_encode($post['wind_info']);
|
|
|
+ if(isset($post['department_id']) && is_array($post['department_id'])){
|
|
|
+ $post['department_id'] = array_pop($post['department_id']);
|
|
|
+ }
|
|
|
+ return CatchResponse::success($this->windModel->updateBy($id, $post));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -64,6 +108,6 @@ class Wind extends CatchController
|
|
|
*/
|
|
|
public function delete($id) : \think\Response
|
|
|
{
|
|
|
- return CatchResponse::success($this->windModel->deleteBy($id));
|
|
|
+ return CatchResponse::success($this->windModel->deleteBy($id,true));
|
|
|
}
|
|
|
}
|