likang vor 2 Jahren
Ursprung
Commit
92891903e4

+ 65 - 10
catch/hydraulic/controller/HydEquipment.php

@@ -1,5 +1,7 @@
 <?php
 namespace catchAdmin\hydraulic\controller;
+error_reporting(1);
+use catchAdmin\equipment\model\EquipmentType;
 use catcher\base\CatchRequest as Request;
 use catcher\CatchResponse;
 use catcher\base\CatchController;
@@ -7,7 +9,9 @@ use catchAdmin\hydraulic\model\HydEquipment as hydEquipmentModel;
 use catchAdmin\hydraulic\model\Hydraulic;
 use catchAdmin\hydraulic\model\Wrench;
 use catchAdmin\system\model\SysDictData;
+use catcher\base\CatchRequest;
 use PhpParser\Node\Stmt\Catch_;
+use think\facade\Db;
 
 class HydEquipment extends CatchController
 {
@@ -66,13 +70,9 @@ class HydEquipment extends CatchController
         // 状态
         'status'=>$data['status'],
         ];
-
+        Db::startTrans();
+        try{
         $id = $this->hydEquipmentModel->storeBy($hydequ);
-        if(!$id)
-        {
-            return CatchResponse::fail('提交失败');
-        }
-
         if($data['equipment_type']==2)
         {
             $hydraulic=[
@@ -110,7 +110,12 @@ class HydEquipment extends CatchController
             ];
             Wrench::create($wrench);
         }
-        
+    }catch(\Exception $e)
+    {
+        Db::rollback();
+        return  CatchResponse::fail($e->getMessage());
+    }
+        Db::commit();
         return CatchResponse::success();
     }
     
@@ -179,7 +184,7 @@ class HydEquipment extends CatchController
                 //设备的id
                 'eq_id'=>$id
             ];
-            Hydraulic::where('id',$data['list']['id'])->update($hydraulic);
+            Hydraulic::where('eq_id',$id)->update($hydraulic);
         }
         //保存扳手
         if($data['equipment_type']==3||$data['equipment_type']==4)
@@ -210,8 +215,43 @@ class HydEquipment extends CatchController
      * @param $id
      */
     public function delete($id) : \think\Response
-    {
-        return CatchResponse::success($this->hydEquipmentModel->deleteBy($id));
+    { 
+        $data = array();
+        $where = [];
+        if(is_array($id))
+        {
+            $where[]=['id','in',$id];
+          $data = $this->hydEquipmentModel->where($where)->select()->toArray();
+        }
+        else
+        {
+            $list =  $this->hydEquipmentModel->where('id',$id)->find();
+            $data[] = $list;
+        }
+        Db::startTrans();
+        try{
+            foreach($data as $item)
+            {
+                if($item['equipment_type']==2)
+                {
+                    Hydraulic::where('eq_id','=',$item['id'])->delete();
+                }
+                if($item['equipment_type']==3||$item['equipment_type']==4)
+                {
+                    Wrench::where('eq_id','=',$item['id'])->delete();
+                }
+
+            }
+           
+            $this->hydEquipmentModel->deleteBy($id,true);
+
+        }catch (\Exception $e)
+        {
+            Db::rollback();
+            return  CatchResponse::fail($e->getMessage());
+        }
+        Db::commit();
+        return CatchResponse::success();
     }
     /**
      * @Descripttion: 获取设备状态和校验状态
@@ -227,4 +267,19 @@ class HydEquipment extends CatchController
         return CatchResponse::success($list);
         
     }
+    /**
+     * 根据设备类别统计每个设备的总数
+     */
+    public function getTotalByEquipmentType()
+    {
+        
+        $list = EquipmentType::where('pid',1)->order('order asc')->field('id,name')->limit(4)->select();
+        foreach($list as $key=>$value)
+        {
+            $list[$key]['total']=$this->hydEquipmentModel->where('equipment_type',$value['id'])->count();
+        }
+       return CatchResponse::success($list);
+
+    }
+    
 }

+ 27 - 0
catch/hydraulic/model/HydEquipment.php

@@ -50,6 +50,33 @@ class HydEquipment extends Model
         // 软删除
         'deleted_at',
     );
+    //物料号搜索
+    public function searchMaterialNumberAttr($query, $value, $data)
+    {
+
+        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.'%');
+        
+    }
+    //设备序列号以及设备资产编号
+    public function searchNumberAttr($query, $value, $data)
+    {
+       
+        return $query->where('serial_number|fixed_asset_number|fixed_asset_number2', 'like', '%'.$value.'%');
+        
+    }
+    
     public function getList()
     {
         $res =  $this->dataRange()

+ 1 - 0
catch/hydraulic/route.php

@@ -28,4 +28,5 @@ $router->group(function () use ($router){
 	$router->resource('hydEquipment', '\catchAdmin\hydraulic\controller\HydEquipment');
 	//获取所有设备状态字典
 	$router->get('getHydEquipmentType', '\catchAdmin\hydraulic\controller\HydEquipment@getHydEquipmentType');
+	$router->get('getTotalByEquipmentType', '\catchAdmin\hydraulic\controller\HydEquipment@getTotalByEquipmentType');
 })->middleware('auth');