123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?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
- {
- $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
- {
- //校验是否重复 value 是否重复
- $data = $request->post();
- $where[] = ["device_type", '=', $data['device_type']];
- $where[] = ['value', '=', $data["value"]];
- $bool = Db::name("maintenance_mapper")->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("maintenance_mapper")->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));
- }
- /**
- * function
- * 获取参数类型
- * @return void
- */
- public function getMaintenOption(Request $request)
- {
- $data = $request->get();
- $where = [];
- 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);
- }
- }
|