Wrench.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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\Wrench as wrenchModel;
  7. class Wrench extends CatchController
  8. {
  9. protected $wrenchModel;
  10. public function __construct(WrenchModel $wrenchModel)
  11. {
  12. $this->wrenchModel = $wrenchModel;
  13. }
  14. /**
  15. * 列表
  16. * @time 2022年05月06日 14:11
  17. * @param Request $request
  18. */
  19. public function index(Request $request) : \think\Response
  20. {
  21. return CatchResponse::paginate($this->wrenchModel->getList());
  22. }
  23. /**
  24. * 保存信息
  25. * @time 2022年05月06日 14:11
  26. * @param Request $request
  27. */
  28. public function save(Request $request) : \think\Response
  29. {
  30. $data = $request->post();
  31. if(isset($data['out_date']) && is_int($data['out_date'])){
  32. $data['out_date'] = date('Y-m-d',$data['out_date']);
  33. }
  34. if(!$data['out_date']){
  35. $data['out_date'] = null;
  36. }
  37. return CatchResponse::success($this->wrenchModel->storeBy($data));
  38. }
  39. /**
  40. * 读取
  41. * @time 2022年05月06日 14:11
  42. * @param $id
  43. */
  44. public function read($id) : \think\Response
  45. {
  46. return CatchResponse::success($this->wrenchModel->findBy($id));
  47. }
  48. /**
  49. * 更新
  50. * @time 2022年05月06日 14:11
  51. * @param Request $request
  52. * @param $id
  53. */
  54. public function update(Request $request, $id) : \think\Response
  55. {
  56. $data = $request->post();
  57. if(isset($data['out_date']) && is_int($data['out_date'])){
  58. $data['out_date'] = date('Y-m-d',$data['out_date']);
  59. }
  60. if(!$data['out_date']){
  61. $data['out_date'] = null;
  62. }
  63. return CatchResponse::success($this->wrenchModel->updateBy($id, $data));
  64. }
  65. /**
  66. * 删除
  67. * @time 2022年05月06日 14:11
  68. * @param $id
  69. */
  70. public function delete($id) : \think\Response
  71. {
  72. return CatchResponse::success($this->wrenchModel->deleteBy($id));
  73. }
  74. }