新增后台基础公共库

This commit is contained in:
wuyanwen
2019-12-12 18:54:07 +08:00
parent 4a5993160f
commit d53b0bae73
6 changed files with 54 additions and 16 deletions

View File

@@ -1,7 +1,9 @@
<?php
namespace catcher;
use think\facade\View;
use think\Paginator;
use think\Response;
class CatchResponse
{
@@ -16,11 +18,13 @@ class CatchResponse
*/
public static function success($data = [], $msg = 'success', $code = 10000): \think\response\Json
{
return json([
'code' => $code,
'msg' => $msg,
'data' => $data,
]);
if (request()->isAjax()) {
return json([
'code' => $code,
'msg' => $msg,
'data' => $data,
]);
}
}
/**
@@ -47,13 +51,18 @@ class CatchResponse
* @time 2019年12月02日
* @param string $msg
* @param int $code
* @return \think\response\Json
* @return mixed
* @throws \Exception
*/
public static function fail($msg = '', $code = 10001): \think\response\Json
public static function fail($msg = '', $code = 10001)
{
return json([
'code' => $code,
'msg' => $msg,
]);
if (request()->isAjax()) {
return json([
'code' => $code,
'msg' => $msg,
]);
}
return Response::create(config('catch.error'), 'view', $code)->assign(['msg' => $msg]);
}
}