likang 2 年之前
父节点
当前提交
7c570272c8
共有 2 个文件被更改,包括 36 次插入31 次删除
  1. 28 30
      catch/hydraulic/controller/Maintenance.php
  2. 8 1
      catch/worklocation/model/Workplan.php

+ 28 - 30
catch/hydraulic/controller/Maintenance.php

@@ -12,81 +12,79 @@ use think\facade\Db;
 class Maintenance extends CatchController
 {
     protected $maintenanceModel;
-    
+
     public function __construct(MaintenanceModel $maintenanceModel)
     {
         $this->maintenanceModel = $maintenanceModel;
     }
-    
+
     /**
      * 列表
      * @time 2022年05月23日 09:40
      * @param Request $request 
      */
-    public function index(Request $request) : \think\Response
+    public function index(Request $request): \think\Response
     {
-        $data =$request->post();
+        $data = $request->post();
         return CatchResponse::paginate($this->maintenanceModel->getList());
     }
-    
+
     /**
      * 保存信息
      * @time 2022年05月23日 09:40
      * @param Request $request 
      */
-    public function save(Request $request) : \think\Response
+    public function save(Request $request): \think\Response
     {
         //校验是否重复 value 是否重复
         $data =  $request->post();
-        $where[] = ["device_type",'=',$data['device_type']];
-        $where[] = ['value','=',$data["value"]];
+        $where[] = ["device_type", '=', $data['device_type']];
+        $where[] = ['value', '=', $data["value"]];
         $bool =  Db::name("maintenance_mapper")->where($where)->find();
-        if(!empty($bool))
-        {
+        if (!empty($bool)) {
             return CatchResponse::fail('唯一标识重复');
         };
         return CatchResponse::success($this->maintenanceModel->storeBy($request->post()));
     }
-    
+
     /**
      * 读取
      * @time 2022年05月23日 09:40
      * @param $id 
      */
-    public function read($id) : \think\Response
+    public function read($id): \think\Response
     {
         return CatchResponse::success($this->maintenanceModel->findBy($id));
     }
-    
+
     /**
      * 更新
      * @time 2022年05月23日 09:40
      * @param Request $request 
      * @param $id
      */
-    public function update(Request $request, $id) : \think\Response
-    {   
+    public function update(Request $request, $id): \think\Response
+    {
         $data =  $request->post();
-        $where[] = ["device_type",'=',$data['device_type']];
-        $where[] = ['value','=',$data["value"]];
-        $where[] =['id','<>',$id];
+        $where[] = ["device_type", '=', $data['device_type']];
+        $where[] = ['value', '=', $data["value"]];
+        $where[] = ['id', '<>', $id];
         $bool =  Db::name("maintenance_mapper")->where($where)->find();
-        if(!empty($bool))
-        {
+        if (!empty($bool)) {
             return CatchResponse::fail('唯一标识重复');
         };
 
         return CatchResponse::success($this->maintenanceModel->updateBy($id, $request->post()));
     }
-    
+
     /**
      * 删除
      * @time 2022年05月23日 09:40
      * @param $id
      */
-    public function delete($id) : \think\Response
+    public function delete($id): \think\Response
     {
-        return CatchResponse::success($this->maintenanceModel->deleteBy($id,true));
+        return CatchResponse::success($this->maintenanceModel->deleteBy($id, true));
     }
     /**
      * function
@@ -95,15 +93,15 @@ class Maintenance extends CatchController
      */
     public function getMaintenOption(Request $request)
     {
-        $data= $request->get();
+        $data = $request->get();
         $where = [];
-        if($data['type'])
-        {
-             $where[]  = ['device_type','=',$data['type']];
+        if ($data['type']) {
+            $where[]  = ['device_type', '=', $data['type']];
+        }
+        if ($data['type'] == 2 && isset($data['fan_model'])) {
+            $where[] = ['fan_model', '=', $data['fan_model']];
         }
         $list = $this->maintenanceModel->where($where)->field('value,name')->select();
         return CatchResponse::success($list);
-
     }
-
-}
+}

+ 8 - 1
catch/worklocation/model/Workplan.php

@@ -47,7 +47,7 @@ class Workplan extends Model
     {
         return $this->dataRange()
             ->catchSearch()
-            ->append(['wind_name', 'fan_number', 'work_sign_name', 'parts_sign_name', 'boit_type_sign_name', 'status_name', 'creat_name'])
+            ->append(['wind_name', 'fan_number', 'work_sign_name', 'parts_sign_name', 'boit_type_sign_name', 'status_name', 'creat_name', 'fan_model'])
             ->field('*')
             ->catchOrder()
             ->creator()
@@ -92,4 +92,11 @@ class Workplan extends Model
         $name =  Users::where('id', $this->creator_id)->value('realname');
         return $name;
     }
+    //获取风机的型号id
+    public function getFanModelAttr()
+    {
+        $fan_id = $this->fan_id;
+        $fanModel =  Fan::where('id', $fan_id)->value('fan_model');
+        return $fanModel;
+    }
 }