123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- namespace catchAdmin\hydraulic\controller;
- use catcher\base\CatchRequest as Request;
- use catcher\CatchResponse;
- use catcher\base\CatchController;
- use catchAdmin\hydraulic\model\maintenanceMapper as maintenanceModel;
- use catcher\base\CatchRequest;
- 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
- {
- return CatchResponse::paginate($this->maintenanceModel->getList());
- }
-
- /**
- * 保存信息
- * @time 2022年05月23日 09:40
- * @param Request $request
- */
- public function save(Request $request) : \think\Response
- {
- //校验是否重复 value 是否重复
- $data = $request->post();
- $where[] = ["device_type",'=',$data['device_type']];
- $where[] = ['value','=',$data["value"]];
- $bool = Db::name("maintenancemapper")->where($where)->find();
- 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
- {
- 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
- {
- $data = $request->post();
- $where[] = ["device_type",'=',$data['device_type']];
- $where[] = ['value','=',$data["value"]];
- $where[] =['id','<>',$id];
- $bool = Db::name("maintenancemapper")->where($where)->find();
- 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
- {
- return CatchResponse::success($this->maintenanceModel->deleteBy($id,true));
- }
- }
|