[更新]修改接口返回参数

This commit is contained in:
Anyon 2018-06-06 15:40:11 +08:00
parent 1756305e42
commit c4606f5037
2 changed files with 16 additions and 12 deletions

View File

@ -42,22 +42,24 @@ class BasicApi
/**
* 返回成功的操作
* @param string $msg 消息内容
* @param mixed $msg 消息内容
* @param array $data 返回数据
* @param integer $code 返回代码
*/
protected function success($msg, $data = [])
protected function success($msg, $data = [], $code = 1)
{
ToolsService::success($msg, $data);
ToolsService::success($msg, $data, $code);
}
/**
* 返回失败的请求
* @param string $msg 消息内容
* @param mixed $msg 消息内容
* @param array $data 返回数据
* @param integer $code 返回代码
*/
protected function error($msg, $data = [])
protected function error($msg, $data = [], $code = 0)
{
ToolsService::error($msg, $data);
ToolsService::error($msg, $data, $code);
}
}

View File

@ -70,23 +70,25 @@ class ToolsService
/**
* 返回成功的操作
* @param string $msg 消息内容
* @param mixed $msg 消息内容
* @param array $data 返回数据
* @param integer $code 返回代码
*/
public static function success($msg, $data = [])
public static function success($msg, $data = [], $code = 1)
{
$result = ['code' => 1, 'msg' => $msg, 'data' => $data, 'token' => encode(session_name() . '=' . session_id())];
$result = ['code' => $code, 'msg' => $msg, 'data' => $data, 'token' => encode(session_name() . '=' . session_id())];
throw new HttpResponseException(Response::create($result, 'json', 200, self::corsRequestHander()));
}
/**
* 返回失败的请求
* @param string $msg 消息内容
* @param mixed $msg 消息内容
* @param array $data 返回数据
* @param integer $code 返回代码
*/
public static function error($msg, $data = [])
public static function error($msg, $data = [], $code = 0)
{
$result = ['code' => 0, 'msg' => $msg, 'data' => $data, 'token' => encode(session_name() . '=' . session_id())];
$result = ['code' => $code, 'msg' => $msg, 'data' => $data, 'token' => encode(session_name() . '=' . session_id())];
throw new HttpResponseException(Response::create($result, 'json', 200, self::corsRequestHander()));
}