mirror of
https://gitee.com/ctexthuang/hyperf-micro-svc.git
synced 2026-02-08 10:20:16 +08:00
53 lines
1.3 KiB
PHP
53 lines
1.3 KiB
PHP
<?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;
|
|
} |