workerman/app/result/Result.php

58 lines
1.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/*
统一格式的返回json数据
*/
namespace app\result;
class Result
{
//success:code值为0,data数据
static public function Success($data)
{
$rs = [
'code' => 0,
'msg' => "",
'data' => $data,
];
return json($rs);
}
//ErrorCode需要code/msg参数
static public function ErrorCode($code, $msg)
{
$rs = [
'code' => $code,
'msg' => $msg,
'data' => "",
];
return json($rs);
}
//error,传入定义的数组常量
static public function Error($arr)
{
$rs = [
'code' => $arr['code'],
'msg' => $arr['msg'],
'data' => "",
];
return json($rs);
}
/**
* 通用化API数据格式输出
* @param $status
* @param string $message
* @param array $data
* @param int $httpStatus
* @return \think\response\Json
*/
static public function show($status, $message = 'error', $data = [], $httpStatus = 200)
{
$result = [
"status" => $status,
"message" => $message,
"result" => $data
];
return json($result, $httpStatus);
}
}