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