wip
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\Trait;
|
||||
|
||||
use think\Response;
|
||||
@@ -13,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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -25,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,
|
||||
|
||||
Reference in New Issue
Block a user