mirror of
https://gitee.com/ctexthuang/hyperf-micro-svc.git
synced 2026-02-08 10:20:16 +08:00
first commit
This commit is contained in:
16
app/Lib/Return/AdminReturn.php
Normal file
16
app/Lib/Return/AdminReturn.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Lib\Return;
|
||||
|
||||
class AdminReturn extends CommonReturn
|
||||
{
|
||||
/**
|
||||
* 通用返回
|
||||
* @param array $res
|
||||
* @return array
|
||||
*/
|
||||
final protected function afterSuccess(array $res): array
|
||||
{
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
16
app/Lib/Return/ApiReturn.php
Normal file
16
app/Lib/Return/ApiReturn.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Lib\Return;
|
||||
|
||||
class ApiReturn extends CommonReturn
|
||||
{
|
||||
/**
|
||||
* 通用返回
|
||||
* @param array $res
|
||||
* @return array
|
||||
*/
|
||||
final 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\ResultCode;
|
||||
|
||||
abstract class CommonReturn
|
||||
{
|
||||
/**
|
||||
* 通用 success 返回
|
||||
* @param string $msg
|
||||
* @param array $data
|
||||
* @param int|ResultCode $code
|
||||
* @param array $debug
|
||||
* @return array
|
||||
*/
|
||||
final public function success(string $msg = 'success', array $data = [], ResultCode|int $code = ResultCode::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 int|ResultCode $code
|
||||
* @param array $debug
|
||||
* @return array
|
||||
*/
|
||||
final public function error(string $msg = 'failed', ResultCode|int $code = ResultCode::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;
|
||||
}
|
||||
Reference in New Issue
Block a user