This commit is contained in:
15
app/Lib/Return/AdminReturn.php
Normal file
15
app/Lib/Return/AdminReturn.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Lib\Return;
|
||||
|
||||
class AdminReturn extends CommonReturn
|
||||
{
|
||||
/**
|
||||
* @param array $res
|
||||
* @return array
|
||||
*/
|
||||
protected function afterSuccess(array $res): array
|
||||
{
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
53
app/Lib/Return/CommonReturn.php
Normal file
53
app/Lib/Return/CommonReturn.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Lib\Return;
|
||||
|
||||
use App\Constants\ReturnCode;
|
||||
|
||||
abstract class CommonReturn
|
||||
{
|
||||
/**
|
||||
* 通用 success 返回
|
||||
* @param string $msg
|
||||
* @param array $data
|
||||
* @param ReturnCode $code
|
||||
* @param array $debug
|
||||
* @return array
|
||||
*/
|
||||
final public function success(string $msg = 'success', array $data = [], ReturnCode $code = ReturnCode::SUCCESS, array $debug = []): array
|
||||
{
|
||||
$res = [
|
||||
'code' => $code,
|
||||
'message' => $msg,
|
||||
'data' => $data
|
||||
];
|
||||
|
||||
return $this->afterSuccess(array_merge($res, $debug));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用 fail 返回
|
||||
* @param string $msg
|
||||
* @param array $data
|
||||
* @param ReturnCode $code
|
||||
* @param array $debug
|
||||
* @return array
|
||||
*/
|
||||
final public function error(string $msg = 'error', ReturnCode $code = ReturnCode::ERROR, array $data = [], array $debug = []): array
|
||||
{
|
||||
$res = [
|
||||
'code' => $code,
|
||||
'message' => $msg,
|
||||
'data' => $data
|
||||
];
|
||||
|
||||
return $this->afterSuccess(array_merge($res, $debug));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用类调子类返回方便切面类识别
|
||||
* @param array $res
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function afterSuccess(array $res): array;
|
||||
}
|
||||
15
app/Lib/Return/TestReturn.php
Normal file
15
app/Lib/Return/TestReturn.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Lib\Return;
|
||||
|
||||
class TestReturn extends CommonReturn
|
||||
{
|
||||
/**
|
||||
* @param array $res
|
||||
* @return array
|
||||
*/
|
||||
protected function afterSuccess(array $res): array
|
||||
{
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user