HelpHander.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace app\hander;
  3. class HelpHander
  4. {
  5. public static function Response($code, $msg, $data = [])
  6. {
  7. $json = [
  8. 'code' => $code,
  9. 'message' => $msg,
  10. 'data' => $data
  11. ];
  12. throw new \think\exception\HttpResponseException(json($json));
  13. return;
  14. }
  15. public static function success($data = [], $msg = '')
  16. {
  17. if(is_array($data)){
  18. $data = array_change_line_to_hump($data);
  19. }
  20. $json = [
  21. 'code' => 0,
  22. 'message' => $msg,
  23. 'data' => $data
  24. ];
  25. throw new \think\exception\HttpResponseException(json($json));
  26. return;
  27. }
  28. public static function error($msg, $code = 1, $data = [])
  29. {
  30. $code = $code == 0 ? 1 : $code; // code不能等于0
  31. if(is_array($data)){
  32. $data = array_change_line_to_hump($data);
  33. }
  34. $json = [
  35. 'code' => $code,
  36. 'message' => $msg,
  37. 'data' => $data
  38. ];
  39. throw new \think\exception\HttpResponseException(json($json));
  40. return;
  41. }
  42. }