likang vor 2 Jahren
Ursprung
Commit
ec4a7270ce
1 geänderte Dateien mit 32 neuen und 34 gelöschten Zeilen
  1. 32 34
      catch/hydraulic/model/HydEquipment.php

+ 32 - 34
catch/hydraulic/model/HydEquipment.php

@@ -5,7 +5,9 @@ namespace catchAdmin\hydraulic\model;
 use catchAdmin\equipment\model\EquipmentType;
 use catcher\base\CatchModel as Model;
 use catchAdmin\permissions\model\DataRangScopeTrait;
+use catchAdmin\permissions\model\Department as ModelDepartment;
 use catchAdmin\system\model\SysDictData;
+use Department;
 
 class HydEquipment extends Model
 {
@@ -57,46 +59,40 @@ class HydEquipment extends Model
     public function searchMaterialNumberAttr($query, $value, $data)
     {
 
-        return $query->where('material_number', 'like', '%'.$value.'%');
-        
+        return $query->where('material_number', 'like', '%' . $value . '%');
     }
     //设备类别搜索
     public function searchEquipmentTypeAttr($query, $value, $data)
     {
         return $query->where('equipment_type', '=', $value);
-        
     }
     //名称
     public function searchNameAttr($query, $value, $data)
     {
-        return $query->where('name', 'like', '%'.$value.'%');
-        
+        return $query->where('name', 'like', '%' . $value . '%');
     }
     //设备序列号以及设备资产编号
     public function searchNumberAttr($query, $value, $data)
     {
-       
-        return $query->where('serial_number|fixed_asset_number|fixed_asset_number2', 'like', '%'.$value.'%');
-        
+
+        return $query->where('serial_number|fixed_asset_number|fixed_asset_number2', 'like', '%' . $value . '%');
     }
     //根据pid 查询当前子类的设备
     public function searchPidAttr($query, $value, $data)
     {
-        $eqtype =new  EquipmentType();
-        $list =$eqtype->getIdbyPid($value);
-        $ids=[];
-        foreach($list as $key =>$value)
-        {
+        $eqtype = new  EquipmentType();
+        $list = $eqtype->getIdbyPid($value);
+        $ids = [];
+        foreach ($list as $key => $value) {
             $ids[] = $value['id'];
         }
         return $query->where('equipment_type', 'in', $ids);
-        
     }
     public function getList()
     {
         $res =  $this->dataRange()
             ->catchSearch()
-            ->append(['classification','equ_type_name', 'list','status1','check_status1'])
+            ->append(['classification', 'equ_type_name', 'list', 'status1', 'check_status1'])
             ->order($this->aliasField('id'), 'desc')
             ->paginate();
         return $res;
@@ -127,52 +123,54 @@ class HydEquipment extends Model
     public function getEquTypeNameAttr()
     {
         $id = $this->getData('equipment_type');
-        $name =  EquipmentType::where('id',$id)->value('name');
+        $name =  EquipmentType::where('id', $id)->value('name');
         return $name;
     }
     public function getCheckStatus1Attr()
     {
         $id = $this->getData('check_status');
         $Dict =  new SysDictData();
-        $value = $Dict->getValueByCode('Check',$id);
+        $value = $Dict->getValueByCode('Check', $id);
         return $value;
     }
     public function getStatus1Attr()
     {
         $id = $this->getData('status');
         $Dict =  new SysDictData();
-        $value = $Dict->getValueByCode('ToolStatus',$id);
+        $value = $Dict->getValueByCode('ToolStatus', $id);
         return $value;
     }
     public function getCheckLastTimeAttr()
     {
         $time = $this->getData('check_last_time');
-        
-        return $time?date('Y-m-d',$time):'';
+
+        return $time ? date('Y-m-d', $time) : '';
     }
     public function getCheckNextTimeAttr()
     {
         $time = $this->getData('check_next_time');
-        return $time?date('Y-m-d',$time):'';
+        return $time ? date('Y-m-d', $time) : '';
     }
     public function getListAttr()
     {
         $id = $this->getData('id');
         $type_id = $this->getData('equipment_type');
-        if($type_id==2)
-        {
-          return  Hydraulic::where('eq_id',$id)->find();
-
-        }
-        if($type_id==3||$type_id==4)
-        {
-            return Wrench::where('eq_id',$id)->find();
+        $data = null;
+        if ($type_id == 2) {
+            $data = Hydraulic::where('eq_id', $id)->find()->toArray();
+            $data["department_name"] = ModelDepartment::where('id', $data['department_id'])->value('department_name');
+            $sysdict = new SysDictData();
+            $data['alarm_state_name'] = $sysdict->getValueByCode('AlarmType', $data['alarm_state']);
+            return  $data;
         }
-        else
-        {
+        if ($type_id == 3 || $type_id == 4) {
+            $data = Wrench::where('eq_id', $id)->find()->toArray();
+            $data["department_name"] = ModelDepartment::where('id', $data['department_id'])->value('department_name');
+            $sysdict = new SysDictData();
+            $data['alarm_state_name'] = $sysdict->getValueByCode('AlarmType', $data['alarm_state']);
+            return $data;
+        } else {
             return null;
         }
     }
-    
-    
-}
+}