|
@@ -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);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|