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