|
@@ -0,0 +1,285 @@
|
|
|
+<?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;
|
|
|
+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 StorageEquipment extends CatchController
|
|
|
+{
|
|
|
+ protected $hydEquipmentModel;
|
|
|
+
|
|
|
+ public function __construct(HydEquipmentModel $hydEquipmentModel)
|
|
|
+ {
|
|
|
+ $this->hydEquipmentModel = $hydEquipmentModel;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 列表
|
|
|
+ * @time 2022年06月21日 11:02
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function index(Request $request) : \think\Response
|
|
|
+ {
|
|
|
+ return CatchResponse::paginate($this->hydEquipmentModel->getList());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存信息
|
|
|
+ * @time 2022年06月21日 11:02
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function save(Request $request) : \think\Response
|
|
|
+ {
|
|
|
+ $data = $request->post();
|
|
|
+ $hydraulic = null;
|
|
|
+ $wrench = null;
|
|
|
+ $hydequ=[
|
|
|
+ // 物料号
|
|
|
+ 'material_number'=>$data['material_number'],
|
|
|
+ // 设备类别
|
|
|
+ 'equipment_type'=>$data['equipment_type'],
|
|
|
+ // 工具名称
|
|
|
+ 'name'=>$data['name'],
|
|
|
+ // 设备型号
|
|
|
+ 'equipment_model'=>$data['equipment_model'],
|
|
|
+ // 发放单位
|
|
|
+ 'issue_unit'=>$data['issue_unit'],
|
|
|
+ // 固定资产编号
|
|
|
+ 'fixed_asset_number'=>$data['fixed_asset_number'],
|
|
|
+ // 类固定资产编号
|
|
|
+ 'fixed_asset_number2'=>$data['fixed_asset_number2'],
|
|
|
+ // 序列号
|
|
|
+ 'serial_number'=>$data['serial_number'],
|
|
|
+ // 出厂编号
|
|
|
+ 'factory_number'=>$data['factory_number'],
|
|
|
+ // 上次校验时间
|
|
|
+ 'check_last_time'=>$data['check_last_time'],
|
|
|
+ // 下次校验时间
|
|
|
+ 'check_next_time'=>$data['check_next_time'],
|
|
|
+ // 校验状态
|
|
|
+ 'check_status'=>$data['check_status'],
|
|
|
+ // 状态
|
|
|
+ 'status'=>$data['status'],
|
|
|
+ ];
|
|
|
+ Db::startTrans();
|
|
|
+ try{
|
|
|
+ $id = $this->hydEquipmentModel->storeBy($hydequ);
|
|
|
+ if($data['equipment_type']==2)
|
|
|
+ {
|
|
|
+ $hydraulic=[
|
|
|
+ // 编号
|
|
|
+ 'number'=>$data['number'],
|
|
|
+ // 所属部门
|
|
|
+ 'department_id'=>$data['department_id'],
|
|
|
+ 'remark'=>$data['remark']?$data['remark']:'',
|
|
|
+ 'max_pressure'=>$data['max_pressure'],
|
|
|
+ 'min_pressure'=>$data['min_pressure'],
|
|
|
+ 'imei'=>$data['imei'],
|
|
|
+ 'effective_period'=>$data['effective_period'],
|
|
|
+ //设备的id
|
|
|
+ 'eq_id'=>$id
|
|
|
+ ];
|
|
|
+
|
|
|
+ Hydraulic::create($hydraulic);
|
|
|
+ }
|
|
|
+ //保存扳手
|
|
|
+ if($data['equipment_type']==3||$data['equipment_type']==4)
|
|
|
+ {
|
|
|
+
|
|
|
+ $wrench = [
|
|
|
+ // 编号
|
|
|
+ 'number'=>$data['number'],
|
|
|
+ //设备id
|
|
|
+ 'eq_id'=>$id,
|
|
|
+ // 所属部门
|
|
|
+ 'department_id'=>$data['department_id'],
|
|
|
+ 'remark'=>$data['remark']?$data['remark']:'',
|
|
|
+ 'pressure'=>$data['pressure'],
|
|
|
+ 'angle_sensor'=>$data['angle_sensor'],
|
|
|
+ // 扭矩
|
|
|
+ 'torque'=>$data['torque'],
|
|
|
+ ];
|
|
|
+ Wrench::create($wrench);
|
|
|
+ }
|
|
|
+ }catch(\Exception $e)
|
|
|
+ {
|
|
|
+ Db::rollback();
|
|
|
+ return CatchResponse::fail($e->getMessage());
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ return CatchResponse::success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 读取
|
|
|
+ * @time 2022年06月21日 11:02
|
|
|
+ * @param $id
|
|
|
+ */
|
|
|
+ public function read($id) : \think\Response
|
|
|
+ {
|
|
|
+ return CatchResponse::success($this->hydEquipmentModel->findBy($id));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新
|
|
|
+ * @time 2022年06月21日 11:02
|
|
|
+ * @param Request $request
|
|
|
+ * @param $id
|
|
|
+ */
|
|
|
+ public function update(Request $request, $id) : \think\Response
|
|
|
+ {
|
|
|
+ $data = $request->post();
|
|
|
+ $hydraulic = null;
|
|
|
+ $wrench = null;
|
|
|
+ $hydequ=[
|
|
|
+ // 物料号
|
|
|
+ 'material_number'=>$data['material_number'],
|
|
|
+ // 设备类别
|
|
|
+ 'equipment_type'=>$data['equipment_type'],
|
|
|
+ // 工具名称
|
|
|
+ 'name'=>$data['name'],
|
|
|
+ // 设备型号
|
|
|
+ 'equipment_model'=>$data['equipment_model'],
|
|
|
+ // 发放单位
|
|
|
+ 'issue_unit'=>$data['issue_unit'],
|
|
|
+ // 固定资产编号
|
|
|
+ 'fixed_asset_number'=>$data['fixed_asset_number'],
|
|
|
+ // 类固定资产编号
|
|
|
+ 'fixed_asset_number2'=>$data['fixed_asset_number2'],
|
|
|
+ // 序列号
|
|
|
+ 'serial_number'=>$data['serial_number'],
|
|
|
+ // 出厂编号
|
|
|
+ 'factory_number'=>$data['factory_number'],
|
|
|
+ // 上次校验时间
|
|
|
+ 'check_last_time'=>$data['check_last_time']?strstr($data['check_last_time'],'-')?strtotime($data['check_last_time']):$data['check_last_time']:'',
|
|
|
+ // 下次校验时间
|
|
|
+ 'check_next_time'=>$data['check_next_time']?strstr($data['check_next_time'],'-')?strtotime($data['check_next_time']):$data['check_next_time']:'',
|
|
|
+ // 校验状态
|
|
|
+ 'check_status'=>$data['check_status'],
|
|
|
+ // 状态
|
|
|
+ 'status'=>$data['status'],
|
|
|
+ ];
|
|
|
+ if($data['equipment_type']==2)
|
|
|
+ {
|
|
|
+ $hydraulic=[
|
|
|
+ // 编号
|
|
|
+ 'number'=>$data['number'],
|
|
|
+ // 所属部门
|
|
|
+ 'department_id'=>$data['department_id'],
|
|
|
+ //备注
|
|
|
+ 'remark'=>$data['remark'],
|
|
|
+ 'max_pressure'=>$data['max_pressure'],
|
|
|
+ 'min_pressure'=>$data['min_pressure'],
|
|
|
+ 'imei'=>$data['imei'],
|
|
|
+ 'effective_period'=>$data['effective_period'],
|
|
|
+ //设备的id
|
|
|
+ 'eq_id'=>$id
|
|
|
+ ];
|
|
|
+ Hydraulic::where('eq_id',$id)->update($hydraulic);
|
|
|
+ }
|
|
|
+ //保存扳手
|
|
|
+ if($data['equipment_type']==3||$data['equipment_type']==4)
|
|
|
+ {
|
|
|
+
|
|
|
+ $wrench = [
|
|
|
+ // 编号
|
|
|
+ 'number'=>$data['number'],
|
|
|
+ //设备id
|
|
|
+ 'eq_id'=>$id,
|
|
|
+ // 所属部门
|
|
|
+ 'department_id'=>$data['department_id'],
|
|
|
+ 'remark'=>$data['remark'],
|
|
|
+
|
|
|
+ 'pressure'=>$data['pressure'],
|
|
|
+ 'angle_sensor'=>$data['angle_sensor'],
|
|
|
+ // 扭矩
|
|
|
+ 'torque'=>$data['torque'],
|
|
|
+ ];
|
|
|
+ Wrench::where('id',$data['list']['id'])->update($wrench);
|
|
|
+ }
|
|
|
+ return CatchResponse::success($this->hydEquipmentModel->updateBy($id, $hydequ));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除
|
|
|
+ * @time 2022年06月21日 11:02
|
|
|
+ * @param $id
|
|
|
+ */
|
|
|
+ public function delete($id) : \think\Response
|
|
|
+ {
|
|
|
+ $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: 获取设备状态和校验状态
|
|
|
+ * @name: likang
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+ public function getHydEquipmentType(Request $request)
|
|
|
+ {
|
|
|
+ $data=$request->get();
|
|
|
+ $code = $data['code'];
|
|
|
+ $sysDict = new SysDictData();
|
|
|
+ $list = $sysDict->getTypesByCodeWithRemark($code,'');
|
|
|
+ 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);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|