ControlManage.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace catchAdmin\alarm\controller;
  3. use catcher\base\CatchRequest as Request;
  4. use catcher\CatchResponse;
  5. use catcher\base\CatchController;
  6. use catchAdmin\alarm\model\ControlManage as controlManageModel;
  7. class ControlManage extends CatchController
  8. {
  9. protected $controlManageModel;
  10. public function __construct(ControlManageModel $controlManageModel)
  11. {
  12. $this->controlManageModel = $controlManageModel;
  13. }
  14. /**
  15. * 列表
  16. * @time 2022年10月26日 10:23
  17. * @param Request $request
  18. */
  19. public function index(Request $request) : \think\Response
  20. {
  21. return CatchResponse::paginate($this->controlManageModel->getList());
  22. }
  23. /**
  24. * 保存信息
  25. * @time 2022年10月26日 10:23
  26. * @param Request $request
  27. */
  28. public function save(Request $request) : \think\Response
  29. {
  30. $params=$request->post();
  31. $params['start_time']=strtotime($params['timeRange'][0]);
  32. $params['end_time']=strtotime($params['timeRange'][1]);
  33. $params['state']=1;
  34. if($params['type']=='2'){
  35. $params['control_obj']=$params['stations'];
  36. }
  37. // var_dump($params);
  38. return CatchResponse::success($this->controlManageModel->storeBy($params));
  39. }
  40. /**
  41. * 读取
  42. * @time 2022年10月26日 10:23
  43. * @param $id
  44. */
  45. public function read($id) : \think\Response
  46. {
  47. return CatchResponse::success($this->controlManageModel->findBy($id));
  48. }
  49. /**
  50. * 更新
  51. * @time 2022年10月26日 10:23
  52. * @param Request $request
  53. * @param $id
  54. */
  55. public function update(Request $request, $id) : \think\Response
  56. {
  57. $params=$request->post();
  58. $params['start_time']=strtotime($params['timeRange'][0]);
  59. $params['end_time']=strtotime($params['timeRange'][1]);
  60. $params['state']=1;
  61. if($params['type']=='2'){
  62. $params['control_obj']=$params['stations'];
  63. }
  64. return CatchResponse::success($this->controlManageModel->updateBy($id, $params));
  65. }
  66. /**
  67. * 删除
  68. * @time 2022年10月26日 10:23
  69. * @param $id
  70. */
  71. public function delete($id) : \think\Response
  72. {
  73. return CatchResponse::success($this->controlManageModel->deleteBy($id,true));
  74. }
  75. }