Maintenance.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace catchAdmin\hydraulic\controller;
  3. use catcher\base\CatchRequest as Request;
  4. use catcher\CatchResponse;
  5. use catcher\base\CatchController;
  6. use catchAdmin\hydraulic\model\maintenanceMapper as maintenanceModel;
  7. use catcher\base\CatchRequest;
  8. use think\facade\Db;
  9. class Maintenance extends CatchController
  10. {
  11. protected $maintenanceModel;
  12. public function __construct(MaintenanceModel $maintenanceModel)
  13. {
  14. $this->maintenanceModel = $maintenanceModel;
  15. }
  16. /**
  17. * 列表
  18. * @time 2022年05月23日 09:40
  19. * @param Request $request
  20. */
  21. public function index(Request $request) : \think\Response
  22. {
  23. return CatchResponse::paginate($this->maintenanceModel->getList());
  24. }
  25. /**
  26. * 保存信息
  27. * @time 2022年05月23日 09:40
  28. * @param Request $request
  29. */
  30. public function save(Request $request) : \think\Response
  31. {
  32. //校验是否重复 value 是否重复
  33. $data = $request->post();
  34. $where[] = ["device_type",'=',$data['device_type']];
  35. $where[] = ['value','=',$data["value"]];
  36. $bool = Db::name("maintenancemapper")->where($where)->find();
  37. if(!empty($bool))
  38. {
  39. return CatchResponse::fail('唯一标识重复');
  40. };
  41. return CatchResponse::success($this->maintenanceModel->storeBy($request->post()));
  42. }
  43. /**
  44. * 读取
  45. * @time 2022年05月23日 09:40
  46. * @param $id
  47. */
  48. public function read($id) : \think\Response
  49. {
  50. return CatchResponse::success($this->maintenanceModel->findBy($id));
  51. }
  52. /**
  53. * 更新
  54. * @time 2022年05月23日 09:40
  55. * @param Request $request
  56. * @param $id
  57. */
  58. public function update(Request $request, $id) : \think\Response
  59. {
  60. $data = $request->post();
  61. $where[] = ["device_type",'=',$data['device_type']];
  62. $where[] = ['value','=',$data["value"]];
  63. $where[] =['id','<>',$id];
  64. $bool = Db::name("maintenancemapper")->where($where)->find();
  65. if(!empty($bool))
  66. {
  67. return CatchResponse::fail('唯一标识重复');
  68. };
  69. return CatchResponse::success($this->maintenanceModel->updateBy($id, $request->post()));
  70. }
  71. /**
  72. * 删除
  73. * @time 2022年05月23日 09:40
  74. * @param $id
  75. */
  76. public function delete($id) : \think\Response
  77. {
  78. return CatchResponse::success($this->maintenanceModel->deleteBy($id,true));
  79. }
  80. }