12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace app\hander;
- class HelpHander
- {
- public static function Response($code, $msg, $data = [])
- {
- $json = [
- 'code' => $code,
- 'message' => $msg,
- 'data' => $data
- ];
- throw new \think\exception\HttpResponseException(json($json));
- return;
- }
- public static function success($data = [], $msg = '')
- {
- if(is_array($data)){
- $data = array_change_line_to_hump($data);
- }
- $json = [
- 'code' => 0,
- 'message' => $msg,
- 'data' => $data
- ];
- throw new \think\exception\HttpResponseException(json($json));
- return;
- }
- public static function error($msg, $code = 1, $data = [])
- {
- $code = $code == 0 ? 1 : $code; // code不能等于0
- if(is_array($data)){
- $data = array_change_line_to_hump($data);
- }
- $json = [
- 'code' => $code,
- 'message' => $msg,
- 'data' => $data
- ];
- throw new \think\exception\HttpResponseException(json($json));
- return;
- }
- }
|