This commit is contained in:
2026-08-05 11:06:20 +08:00
parent b4e5e98353
commit 8380b8797b
4 changed files with 24 additions and 24 deletions

View File

@@ -14,9 +14,9 @@ trait ApiResponse
* @param int $code 自定义业务状态码
* @return Json
*/
protected function success(int $code = 200, string $message = '操作成功', mixed $data = []): Json
protected function success(string $message = '操作成功', mixed $data = [], int $code = 200): Json
{
return $this->jsonResponse($code, $message, $data);
return $this->jsonResponse($message, $data, $code);
}
/**
@@ -26,15 +26,15 @@ trait ApiResponse
* @param mixed $data 额外的错误数据(如验证未通过的具体字段)
* @return Json
*/
protected function error(int $code = 400, string $message = '操作失败', mixed $data = []): Json
protected function error(string $message = '操作失败', mixed $data = [], int $code = 400): Json
{
return $this->jsonResponse($code, $message, $data);
return $this->jsonResponse($message, $data, $code);
}
/**
* 统一 JSON 返回格式
*/
private function jsonResponse(int $code, string $message, mixed $data): Json
private function jsonResponse(string $message, mixed $data, int $code): Json
{
$result = [
'code' => $code,