基础数据-校区服务

This commit is contained in:
Aether
2025-09-19 15:14:20 +08:00
parent 824510d57c
commit b69f14ded2
16 changed files with 757 additions and 300 deletions

View File

@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
namespace App\Exception;
use Hyperf\Server\Exception\ServerException;
use Throwable;
class BusinessException extends ServerException
{
/**
* 业务异常.
* @param int $code 错误码
* @param string $message 错误消息
*/
public function __construct(int $code = 500, string $message = '', ?Throwable $previous = null)
{
if (empty($message)) {
$message = $this->getDefaultMessage($code);
}
parent::__construct($message, $code, $previous);
}
/**
* 获取默认错误消息.
*/
private function getDefaultMessage(int $code): string
{
$messages = [
400 => '请求参数错误',
401 => '未授权',
403 => '禁止访问',
404 => '资源不存在',
500 => '服务器内部错误',
10001 => '校区不存在',
10002 => '校区已存在',
10003 => '父级校区不存在',
10004 => '层级参数错误',
];
return $messages[$code] ?? '业务处理失败';
}
}