..
This commit is contained in:
@@ -6,6 +6,10 @@ namespace Aether;
|
||||
|
||||
class AetherResponse
|
||||
{
|
||||
public const SUCCESS = 0;
|
||||
|
||||
public const ERROR = 1;
|
||||
|
||||
/**
|
||||
* 成功响应.
|
||||
* @param null|mixed $data 数据
|
||||
@@ -14,7 +18,7 @@ class AetherResponse
|
||||
public static function success(mixed $data = null, string $message = '操作成功'): array
|
||||
{
|
||||
return [
|
||||
'code' => 0,
|
||||
'code' => self::SUCCESS,
|
||||
'message' => $message,
|
||||
'data' => $data,
|
||||
'timestamp' => time(),
|
||||
@@ -27,7 +31,7 @@ class AetherResponse
|
||||
* @param string $message 错误消息
|
||||
* @param null|mixed $data 附加数据
|
||||
*/
|
||||
public static function error(int $code, string $message = '', mixed $data = null): array
|
||||
public static function error(string $message = '', int $code = self::ERROR, mixed $data = null): array
|
||||
{
|
||||
return [
|
||||
'code' => $code,
|
||||
@@ -37,6 +41,22 @@ class AetherResponse
|
||||
];
|
||||
}
|
||||
|
||||
public static function page($list, int $total, int $page, int $size): array
|
||||
{
|
||||
return [
|
||||
'code' => self::SUCCESS,
|
||||
'message' => 'success',
|
||||
'data' => [
|
||||
'list' => $list,
|
||||
'page' => $page,
|
||||
'size' => $size,
|
||||
'total' => $total,
|
||||
'pages' => (int) ceil($total / $size),
|
||||
],
|
||||
'timestamp' => time(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取默认错误消息.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user