作者 liyuhang

gx

... ... @@ -89,22 +89,22 @@ final class Code extends Enum implements LocalizedEnum
511 => 'Network Authentication Required', // RFC6585
];
//成功
const SUCCESS = 200;
const SUCCESS = 'A0000';
//用户行为大大类
const USER_ERROR = 202;
const USER_ERROR = 'A0010';
//用户错误大类
const USER_REGISTER_ERROE = 203;
const USER_REGISTER_ERROE = 'A0100';
//用户登陆错误大类
const USER_LOGIN_ERROE = 204;
const USER_LOGIN_ERROE = 'A1000';
//用户权限错误大类
const USER_PERMISSION_ERROE = 205;
const USER_PERMISSION_ERROE = 'A0200';
//用户请求参数错误大类
const USER_PARAMS_ERROE = 206;
const USER_PARAMS_ERROE = 'A0300';
//模型资源未找到
const USER_MODEL_NOTFOUND_ERROE = 207;
const USER_MODEL_NOTFOUND_ERROE = 'A0400';
//用户上传异常大类
const USER_UPLOAD_ERROE = 'A0500';
... ...
... ... @@ -2,11 +2,6 @@
namespace App\Http\Controllers\Aside;
<<<<<<< HEAD
class ProjectMenuController
{
=======
use App\Enums\Common\Code;
use App\Models\ProjectMenu as ProjectMenuModel;
use Illuminate\Support\Facades\Validator;
... ... @@ -117,5 +112,5 @@ class ProjectMenuController extends BaseController
}
$this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功',Code::SUCCESS);
}
>>>>>>> 5bb365e2828ceec83c8a52553d6f4c44a1e1785f
}
... ...
... ... @@ -46,29 +46,6 @@ class BaseController extends Controller
$this->uid = $info['id'];
}
/**
* 成功返回
* @param array $data
* @param int|string $code
* @param bool $objectData
* @return JsonResponse
* @author zbj
* @date 2023/4/12
*/
function success(array $data = [], $code = Code::SUCCESS, bool $objectData = false): JsonResponse
{
if ($objectData) {
$data = (object)$data;
}
$code = Code::fromValue($code);
$response = [
'code' => $code->value,
'data' => $data,
'msg' => $code->description,
];
return response()->json($response,200,$this->header);
}
/**
* @name 参数过滤
* @return void
* @author :liyuhang
... ... @@ -114,12 +91,12 @@ class BaseController extends Controller
* @author :liyuhang
* @method
*/
public function response($msg,$code = null,$data = [],$result_code = 200,$type = 'application/json'){
$code === null && $code = $result_code;
public function response($msg,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'){
$code = Code::fromValue($code);
$result = [
'msg' =>$msg,
'code'=>$code,
'data'=>$data
'msg' => $msg == null ? $msg : $code->description,
'code' => $code->value,
'data' => $data,
];
$this->header['Content-Type'] = $type;
$this->header['token'] = $this->token;
... ...