RfidWithBw.php 2.1 KB

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