Maintenance.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. $data = $request->post();
  24. return CatchResponse::paginate($this->maintenanceModel->getList());
  25. }
  26. /**
  27. * 保存信息
  28. * @time 2022年05月23日 09:40
  29. * @param Request $request
  30. */
  31. public function save(Request $request): \think\Response
  32. {
  33. //校验是否重复 value 是否重复
  34. $data = $request->post();
  35. $where[] = ["device_type", '=', $data['device_type']];
  36. $where[] = ['value', '=', $data["value"]];
  37. $bool = Db::name("maintenance_mapper")->where($where)->find();
  38. if (!empty($bool)) {
  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. $data['id'] = $id;
  62. $where[] = ["device_type", '=', $data['device_type']];
  63. $where[] = ['value', '=', $data["value"]];
  64. $where[] = ['id', '<>', $id];
  65. $bool = Db::name("maintenance_mapper")->where($where)->find();
  66. if (!empty($bool)) {
  67. return CatchResponse::fail('唯一标识重复');
  68. };
  69. return CatchResponse::success($this->maintenanceModel->updateBy($id, $data));
  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. /**
  81. * function
  82. * 获取参数类型
  83. * @return void
  84. */
  85. public function getMaintenOption(Request $request)
  86. {
  87. $data = $request->get();
  88. $where = [];
  89. if ($data['type']) {
  90. $where[] = ['device_type', '=', $data['type']];
  91. }
  92. if ($data['type'] == 2 && isset($data['fan_model'])) {
  93. $where[] = ['fan_model', '=', $data['fan_model']];
  94. }
  95. $list = $this->maintenanceModel->where($where)->field('value,name')->select();
  96. return CatchResponse::success($list);
  97. }
  98. }