Initial commit: ThinkPHP refactor (tp)
Made-with: Cursor
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\api\common;
|
||||
|
||||
/**
|
||||
* 统一响应类
|
||||
*/
|
||||
class Response
|
||||
{
|
||||
/**
|
||||
* 成功响应
|
||||
* @param mixed $data 返回数据
|
||||
* @param string $message 提示信息
|
||||
* @param int $code 状态码
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public static function success($data = [], string $message = 'success', int $code = 200)
|
||||
{
|
||||
return json([
|
||||
'code' => $code,
|
||||
'msg' => $message,
|
||||
'data' => $data,
|
||||
'time' => time(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败响应
|
||||
* @param string $message 提示信息
|
||||
* @param int $code 状态码
|
||||
* @param mixed $data 返回数据
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public static function error(string $message = 'error', int $code = 400, $data = [])
|
||||
{
|
||||
return json([
|
||||
'code' => $code,
|
||||
'msg' => $message,
|
||||
'data' => $data,
|
||||
'time' => time(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页数据响应
|
||||
* @param mixed $list 数据列表
|
||||
* @param int $total 总数
|
||||
* @param int $page 当前页
|
||||
* @param int $pageSize 每页数量
|
||||
* @param string $message 提示信息
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public static function paginate($list, int $total, int $page, int $pageSize, string $message = 'success')
|
||||
{
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => $message,
|
||||
'data' => [
|
||||
'list' => $list,
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'page_size' => $pageSize,
|
||||
],
|
||||
'time' => time(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user