diff --git a/.env b/.env index 5dffd8f..4e81493 100644 --- a/.env +++ b/.env @@ -1,15 +1,15 @@ -APP_NAME=hyperf- +APP_NAME=hyperf-data APP_ENV=dev DB_DRIVER=mysql DB_HOST=localhost DB_PORT=3306 -DB_DATABASE=hyperf_ -DB_USERNAME=hyperf_ +DB_DATABASE=hyperf_data +DB_USERNAME=hyperf_data DB_PASSWORD=4cfDRXZSksn7npiP DB_CHARSET=utf8mb4 DB_COLLATION=utf8mb4_unicode_ci -DB_PREFIX=_ +DB_PREFIX=da_ REDIS_HOST=localhost REDIS_AUTH=(null) @@ -22,4 +22,8 @@ SWOOLE_WORKER_NUM=1 NACOS_HOST=192.168.28.199 NACOS_PORT=8848 -NACOS_NAMESPACE=e42b853c-5195-478b-b5e3-6d49f6a45053 \ No newline at end of file +NACOS_USERNAME=nacos +NACOS_PASSWORD=nacos +NACOS_NAMESPACE=e42b853c-5195-478b-b5e3-6d49f6a45053 +NACOS_GROUP=DEFAULT_GROUP +NACOS_SERVICE_NAME=hyperf-data \ No newline at end of file diff --git a/app/Controller/AbstractController.php b/app/Controller/AbstractController.php deleted file mode 100644 index 4ef3da4..0000000 --- a/app/Controller/AbstractController.php +++ /dev/null @@ -1,30 +0,0 @@ -request->input('user', 'Hyperf'); - $method = $this->request->getMethod(); - - return [ - 'method' => $method, - 'message' => "Hello {$user}.", - ]; - } -} diff --git a/app/Exception/Handler/AppExceptionHandler.php b/app/Exception/Handler/AppExceptionHandler.php deleted file mode 100644 index 17b5fd6..0000000 --- a/app/Exception/Handler/AppExceptionHandler.php +++ /dev/null @@ -1,38 +0,0 @@ -logger->error(sprintf('%s[%s] in %s', $throwable->getMessage(), $throwable->getLine(), $throwable->getFile())); - $this->logger->error($throwable->getTraceAsString()); - return $response->withHeader('Server', 'Hyperf')->withStatus(500)->withBody(new SwooleStream('Internal Server Error.')); - } - - public function isValid(Throwable $throwable): bool - { - return true; - } -} diff --git a/app/JsonRpc/Contract/CampusServiceInterface.php b/app/JsonRpc/Contract/CampusServiceInterface.php new file mode 100644 index 0000000..08c2835 --- /dev/null +++ b/app/JsonRpc/Contract/CampusServiceInterface.php @@ -0,0 +1,40 @@ +toArray(); + } + + public function batchGetCampus(array $ids): array + { + if (empty($ids)) { + return []; + } + $campuses = Campus::whereIn('id', $ids)->get()->toArray(); + return array_column($campuses, null, 'id'); + } + + public function getCampusByProvince(string $province): array + { + return Campus::province($province) + ->level(3) + ->get() + ->toArray(); + } + + public function getCampusByCity(string $province, string $city): array + { + return Campus::province($province) + ->city($city) + ->level(3) + ->get() + ->toArray(); + } + + public function getCampusHierarchy(int $campusId): array + { + $hierarchy = []; + $current = Campus::find($campusId); + + if (! $current) { + return $hierarchy; + } + + // 从校区向上追溯层级 + while ($current) { + array_unshift($hierarchy, [ + 'id' => $current->id, + 'name' => $current->name, + 'level' => $current->level, + 'province' => $current->province, + 'city' => $current->city, + ]); + + if ($current->parent_id === 0) { + break; + } + + $current = Campus::find($current->parent_id); + } + + return $hierarchy; + } +} diff --git a/app/Listener/DbQueryExecutedListener.php b/app/Listener/DbQueryExecutedListener.php deleted file mode 100644 index 5804bb7..0000000 --- a/app/Listener/DbQueryExecutedListener.php +++ /dev/null @@ -1,66 +0,0 @@ -logger = $container->get(LoggerFactory::class)->get('sql'); - } - - public function listen(): array - { - return [ - QueryExecuted::class, - ]; - } - - /** - * @param QueryExecuted $event - */ - public function process(object $event): void - { - if ($event instanceof QueryExecuted) { - $sql = $event->sql; - if (! Arr::isAssoc($event->bindings)) { - $position = 0; - foreach ($event->bindings as $value) { - $position = strpos($sql, '?', $position); - if ($position === false) { - break; - } - $value = "'{$value}'"; - $sql = substr_replace($sql, $value, $position, 1); - $position += strlen($value); - } - } - - $this->logger->info(sprintf('[%s] %s', $event->time, $sql)); - } - } -} diff --git a/app/Listener/ResumeExitCoordinatorListener.php b/app/Listener/ResumeExitCoordinatorListener.php deleted file mode 100644 index eff2e0b..0000000 --- a/app/Listener/ResumeExitCoordinatorListener.php +++ /dev/null @@ -1,35 +0,0 @@ -resume(); - } -} diff --git a/app/Model/Campus.php b/app/Model/Campus.php new file mode 100644 index 0000000..34822b3 --- /dev/null +++ b/app/Model/Campus.php @@ -0,0 +1,80 @@ + 'integer', + 'level' => 'integer', + 'status' => 'integer', + ]; + + /** + * 获取子校区. + */ + public function children(): HasMany + { + return $this->hasMany(self::class, 'parent_id', 'id'); + } + + /** + * 按省份查询. + */ + public function scopeProvince(Builder $query, string $province): Builder + { + return $query->where('province', $province); + } + + /** + * 按城市查询. + */ + public function scopeCity(Builder $query, string $city): Builder + { + return $query->where('city', $city); + } + + /** + * 按层级查询. + */ + public function scopeLevel(Builder $query, int $level): Builder + { + return $query->where('level', $level); + } +} diff --git a/composer.json b/composer.json index e186e37..9e5cb8f 100755 --- a/composer.json +++ b/composer.json @@ -16,6 +16,7 @@ "hyperf/cache": "~3.1.0", "hyperf/command": "~3.1.0", "hyperf/config": "~3.1.0", + "hyperf/config-nacos": "^3.1", "hyperf/database": "~3.1.0", "hyperf/db-connection": "~3.1.0", "hyperf/engine": "^2.10", @@ -32,7 +33,9 @@ "hyperf/rpc": "~3.1.0", "hyperf/rpc-client": "~3.1.0", "hyperf/rpc-server": "~3.1.0", + "hyperf/service-governance": "^3.1", "hyperf/service-governance-nacos": "^3.1", + "hyperf/utils": "^3.1", "hyperf/validation": "^3.1" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 9269a7e..3c78c2e 100755 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d60c21c4bb08e5b1d7552c9d0bbe3b78", + "content-hash": "c30923a4e3d3314c7a9c295b398631d8", "packages": [ { "name": "carbonphp/carbon-doctrine-types", @@ -1345,6 +1345,150 @@ ], "time": "2025-06-06T02:41:30+00:00" }, + { + "name": "hyperf/config-center", + "version": "v3.1.60", + "source": { + "type": "git", + "url": "https://github.com/hyperf/config-center.git", + "reference": "89f42313140cb8957e43a23d089ab46208e87a9c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hyperf/config-center/zipball/89f42313140cb8957e43a23d089ab46208e87a9c", + "reference": "89f42313140cb8957e43a23d089ab46208e87a9c", + "shasum": "" + }, + "require": { + "hyperf/contract": "~3.1.0", + "hyperf/coordinator": "~3.1.0", + "hyperf/coroutine": "~3.1.0", + "hyperf/support": "~3.1.0", + "php": ">=8.1" + }, + "suggest": { + "hyperf/process": "^2.1" + }, + "type": "library", + "extra": { + "hyperf": { + "config": "Hyperf\\ConfigCenter\\ConfigProvider" + }, + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "psr-4": { + "Hyperf\\ConfigCenter\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "The abstraction component of config center", + "homepage": "https://hyperf.io", + "keywords": [ + "config-center", + "hyperf", + "php" + ], + "support": { + "docs": "https://hyperf.wiki", + "issues": "https://github.com/hyperf/hyperf/issues", + "pull-request": "https://github.com/hyperf/hyperf/pulls", + "source": "https://github.com/hyperf/hyperf" + }, + "funding": [ + { + "url": "https://hyperf.wiki/#/zh-cn/donate", + "type": "custom" + }, + { + "url": "https://opencollective.com/hyperf", + "type": "open_collective" + } + ], + "time": "2025-07-07T02:01:34+00:00" + }, + { + "name": "hyperf/config-nacos", + "version": "v3.1.61", + "source": { + "type": "git", + "url": "https://github.com/hyperf/config-nacos.git", + "reference": "ad46dffbc252153aebef0fc0918ec85d8335bfc9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hyperf/config-nacos/zipball/ad46dffbc252153aebef0fc0918ec85d8335bfc9", + "reference": "ad46dffbc252153aebef0fc0918ec85d8335bfc9", + "shasum": "" + }, + "require": { + "hyperf/codec": "~3.1.0", + "hyperf/collection": "~3.1.0", + "hyperf/config-center": "~3.1.0", + "hyperf/contract": "~3.1.0", + "hyperf/guzzle": "~3.1.0", + "hyperf/nacos": "~3.1.0", + "hyperf/support": "~3.1.0", + "jetbrains/phpstorm-attributes": "^1.0", + "php": ">=8.1" + }, + "suggest": { + "ext-json": "*", + "ext-simplexml": "*", + "ext-yaml": "*", + "hyperf/event": "Required to use listeners. (~2.2.0)", + "hyperf/framework": "Required to use listeners. (~2.2.0)", + "hyperf/process": "Required to use processes. (~2.2.0)" + }, + "type": "library", + "extra": { + "hyperf": { + "config": "Hyperf\\ConfigNacos\\ConfigProvider" + }, + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "psr-4": { + "Hyperf\\ConfigNacos\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A nacos adapter for config center component.", + "homepage": "https://hyperf.io", + "keywords": [ + "hyperf", + "nacos", + "php", + "swoole" + ], + "support": { + "docs": "https://hyperf.wiki", + "issues": "https://github.com/hyperf/hyperf/issues", + "pull-request": "https://github.com/hyperf/hyperf/pulls", + "source": "https://github.com/hyperf/hyperf" + }, + "funding": [ + { + "url": "https://hyperf.wiki/#/zh-cn/donate", + "type": "custom" + }, + { + "url": "https://opencollective.com/hyperf", + "type": "open_collective" + } + ], + "time": "2025-09-03T05:52:19+00:00" + }, { "name": "hyperf/context", "version": "v3.1.42", @@ -4181,6 +4325,72 @@ ], "time": "2025-06-06T02:41:30+00:00" }, + { + "name": "hyperf/utils", + "version": "v3.1.42", + "source": { + "type": "git", + "url": "https://github.com/hyperf/utils.git", + "reference": "4b13a567a61d08a3c4d058499e28a5b26fc18f1c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hyperf/utils/zipball/4b13a567a61d08a3c4d058499e28a5b26fc18f1c", + "reference": "4b13a567a61d08a3c4d058499e28a5b26fc18f1c", + "shasum": "" + }, + "require": { + "doctrine/inflector": "^2.0", + "hyperf/code-parser": "~3.1.0", + "hyperf/codec": "~3.1.0", + "hyperf/collection": "~3.1.0", + "hyperf/context": "~3.1.0", + "hyperf/contract": "~3.1.0", + "hyperf/coordinator": "~3.1.0", + "hyperf/coroutine": "~3.1.0", + "hyperf/engine": "^2.0", + "hyperf/macroable": "~3.1.0", + "hyperf/serializer": "~3.1.0", + "hyperf/stringable": "~3.1.0", + "hyperf/support": "~3.1.0", + "php": ">=8.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A tools package that could help developer solved the problem quickly.", + "homepage": "https://hyperf.io", + "keywords": [ + "hyperf", + "php", + "swoole", + "utils" + ], + "support": { + "docs": "https://hyperf.wiki", + "issues": "https://github.com/hyperf/hyperf/issues", + "pull-request": "https://github.com/hyperf/hyperf/pulls", + "source": "https://github.com/hyperf/hyperf" + }, + "funding": [ + { + "url": "https://hyperf.wiki/#/zh-cn/donate", + "type": "custom" + }, + { + "url": "https://opencollective.com/hyperf", + "type": "open_collective" + } + ], + "time": "2024-09-25T02:54:12+00:00" + }, { "name": "hyperf/validation", "version": "v3.1.60", diff --git a/config/autoload/nacos.php b/config/autoload/nacos.php new file mode 100644 index 0000000..1f9a838 --- /dev/null +++ b/config/autoload/nacos.php @@ -0,0 +1,16 @@ + [ + 'host' => env('NACOS_HOST', '127.0.0.1'), + 'port' => env('NACOS_PORT', 8848), + 'username' => env('NACOS_USERNAME', 'nacos'), + 'password' => env('NACOS_PASSWORD', 'nacos'), + 'namespace' => env('NACOS_NAMESPACE', 'public'), + 'timeout' => 5.0, + ], +]; diff --git a/config/autoload/server.php b/config/autoload/server.php index 5cc8164..2b6e983 100644 --- a/config/autoload/server.php +++ b/config/autoload/server.php @@ -15,29 +15,29 @@ use function Hyperf\Support\env; return [ 'mode' => SWOOLE_PROCESS, 'servers' => [ - [ - 'name' => 'jsonrpc-http', - 'type' => Server::SERVER_HTTP, - 'host' => env('JSON_RPC_HOST', '0.0.0.0'), - 'port' => (int) env('JSON_RPC_PORT', 9620), - 'sock_type' => SWOOLE_SOCK_TCP, - 'callbacks' => [ - Event::ON_REQUEST => [HttpServer::class, 'onRequest'], - ], - 'settings' => [ - 'open_eof_split' => true, - 'package_eof' => "\r\n", - 'package_max_length' => 1024 * 1024 * 2, - ], - 'options' => [ - // Whether to enable request lifecycle event - 'enable_request_lifecycle' => false, - ], - ], + [ + 'name' => 'jsonrpc-http', + 'type' => Server::SERVER_HTTP, + 'host' => env('JSON_RPC_HOST', '0.0.0.0'), + 'port' => (int) env('JSON_RPC_PORT', 9620), + 'sock_type' => SWOOLE_SOCK_TCP, + 'callbacks' => [ + Event::ON_REQUEST => [HttpServer::class, 'onRequest'], + ], + 'settings' => [ + 'open_eof_split' => true, + 'package_eof' => "\r\n", + 'package_max_length' => 1024 * 1024 * 2, + ], + 'options' => [ + // Whether to enable request lifecycle event + 'enable_request_lifecycle' => false, + ], + ], ], 'settings' => [ Constant::OPTION_ENABLE_COROUTINE => true, - Constant::OPTION_WORKER_NUM => (int) env('SWOOLE_WORKER_NUM', swoole_cpu_num()), //swoole_cpu_num(), + Constant::OPTION_WORKER_NUM => (int) env('SWOOLE_WORKER_NUM', swoole_cpu_num()), // swoole_cpu_num(), Constant::OPTION_PID_FILE => BASE_PATH . '/runtime/hyperf.pid', Constant::OPTION_OPEN_TCP_NODELAY => true, Constant::OPTION_MAX_COROUTINE => 100000, @@ -51,4 +51,10 @@ return [ Event::ON_PIPE_MESSAGE => [PipeMessageCallback::class, 'onPipeMessage'], Event::ON_WORKER_EXIT => [WorkerExitCallback::class, 'onWorkerExit'], ], + // 健康检查配置(供Nacos检测服务状态) + 'health_check' => [ + 'enable' => true, + 'path' => '/health', + 'interval' => 3, + ], ]; diff --git a/config/autoload/services.php b/config/autoload/services.php index 8bc110e..0800ebd 100644 --- a/config/autoload/services.php +++ b/config/autoload/services.php @@ -1,30 +1,30 @@ [ - 'discovery' => true, - 'register' => true, - ], - 'consumers' => [], - 'providers' => [], - 'drivers' => [ + 'enable' => true, + 'driver' => 'nacos', + 'registries' => [ 'nacos' => [ - // nacos server url like https://nacos.hyperf.io, Priority is higher than host:port - // 'url' => '', - // The nacos host info 'host' => env('NACOS_HOST', '127.0.0.1'), 'port' => env('NACOS_PORT', 8848), - // The nacos account info - 'username' => null, - 'password' => null, - 'guzzle' => [ - 'config' => null, + 'username' => env('NACOS_USERNAME', 'nacos'), + 'password' => env('NACOS_PASSWORD', 'nacos'), + 'namespace' => env('NACOS_NAMESPACE', 'public'), + 'group_name' => env('NACOS_GROUP_NAME', 'DEFAULT_GROUP'), + 'service_name' => env('NACOS_SERVICE_NAME', 'hyperf-organization'), + 'protect_threshold' => 0.5, + 'metadata' => [ + 'protocol' => 'jsonrpc-http', + 'server' => 'jsonrpc-http', + 'version' => '1.0.0', + 'weight' => 100, ], - 'group_name' => 'api', - 'namespace_id' => env('NACOS_NAMESPACE', 'dev'), 'heartbeat' => 5, + 'heartbeat_timeout' => 15, ], ], ]; diff --git a/extend/Aether/PHP/Hyperf/Traits/AetherEnum.php b/extend/Aether/PHP/Hyperf/Traits/AetherEnum.php index db5baf9..ee05ee2 100644 --- a/extend/Aether/PHP/Hyperf/Traits/AetherEnum.php +++ b/extend/Aether/PHP/Hyperf/Traits/AetherEnum.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace Aether\Traits; use App\Notice\Enum\NoticeStatusEnum; -use App\Notice\Model\NoticeStatsModel; +use App\Data\Model\NoticeStatsModel; use InvalidArgumentException; use ReflectionClass;