tongshanglei преди 3 години
родител
ревизия
8e604de1b5
променени са 3 файла, в които са добавени 32 реда и са изтрити 31 реда
  1. 20 20
      catch/wind/controller/Wind.php
  2. 11 11
      catch/wind/model/Wind.php
  3. 1 0
      catch/wind/route.php

+ 20 - 20
catch/wind/controller/Wind.php

@@ -27,6 +27,15 @@ class Wind extends CatchController
     }
     
     /**
+     * 列表
+     * @time 2022年04月27日 10:49
+     * @param Request $request 
+     */
+    public function getWindList(Request $request) : \think\Response
+    {
+        return CatchResponse::success($this->windModel->getWindList());
+    }
+    /**
      * 保存信息
      * @time 2022年04月27日 10:49
      * @param Request $request 
@@ -77,28 +86,19 @@ class Wind extends CatchController
     {
         $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'])){
+        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']);
         }
-        return CatchResponse::success($this->windModel->updateBy($id, $post));
+       $post['wind_info'] = json_encode($post['wind_info']);
+
+       return CatchResponse::success($this->windModel->updateBy($id, $post));
     }
     
     /**

+ 11 - 11
catch/wind/model/Wind.php

@@ -46,17 +46,7 @@ class Wind extends Model
     );
     public function getList()
     {
-        // 不分页
-        if (property_exists($this, 'paginate') && $this->paginate === false) {
-            return $this->dataRange()
-                ->catchSearch()
-                ->field('*')
-                ->catchOrder()
-                ->append(['type_name','depart_name'])
-                ->creator()
-                ->select();
-        }
-
+        
         // 分页列表
         return $this->dataRange()
             ->catchSearch()
@@ -66,6 +56,16 @@ class Wind extends Model
             ->creator()
             ->paginate();
     }
+    public function getWindList(){
+        // 不分页
+        return $this->dataRange()
+        ->catchSearch()
+        ->field('*')
+        ->catchOrder()
+        ->append(['type_name','depart_name'])
+        ->creator()
+        ->select();
+    }
        /**
      * 获取风场类型(文本)
      */

+ 1 - 0
catch/wind/route.php

@@ -12,5 +12,6 @@
 // you should use `$router`
 $router->group(function () use ($router){
 	// wind路由
+	$router->get('wind/getWindList', '\catchAdmin\wind\controller\Wind@getWindList');
 	$router->resource('wind', '\catchAdmin\wind\controller\Wind');
 })->middleware('auth');