协程版仓库后端项目
Some checks failed
Build Docker / build (push) Has been cancelled

This commit is contained in:
2025-07-08 14:59:47 +08:00
commit 0b2299c427
134 changed files with 19277 additions and 0 deletions

View File

@ -0,0 +1,38 @@
<?php
/**
* Author: ykxiao
* Date: 2025/6/3
* Time: 下午7:23
* Description:
*
* (c) ykxiao <yk_9001@hotmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
declare(strict_types=1);
use function Hyperf\Support\env;
return [
/*
|--------------------------------------------------------------------------
| Aliases
|--------------------------------------------------------------------------
|
|
*/
'accessKeyId' => env('ALI_ACCESS_KEY_ID', ''),
'accessKeySecret' => env('ALI_ACCESS_KEY_SECRET', ''),
'oss' => [
'oss_endpoint' => env('OSS_ENDPOINT', ''),
],
'logs' => [
'log_endpoint' => env('LOG_ENDPOINT', ''),
'log_project' => env('LOG_PROJECT', ''),
'log_store' => env('LOG_STORE', ''),
],
];

42
config/autoload/amqp.php Normal file
View File

@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
use function Hyperf\Support\env;
return [
'default' => [
'host' => env('AMQP_HOST', 'localhost'),
'port' => (int) env('AMQP_PORT', 5672),
'user' => env('AMQP_USER', 'guest'),
'password' => env('AMQP_PASSWORD', 'guest'),
'vhost' => env('AMQP_VHOST', '/'),
'concurrent' => [
'limit' => 1,
],
'pool' => [
'connections' => 2,
],
'params' => [
'insist' => false,
'login_method' => 'AMQPLAIN',
'login_response' => null,
'locale' => 'en_US',
'connection_timeout' => 3,
'read_write_timeout' => 6,
'context' => null,
'keepalive' => true,
'heartbeat' => 3,
'channel_rpc_timeout' => 0.0,
'close_on_destruct' => false,
'max_idle_channels' => 10,
],
],
];

View File

@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
return [
'scan' => [
'paths' => [
BASE_PATH . '/app',
],
'ignore_annotations' => [
'mixin',
],
],
];

View File

@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
return [
];

View File

@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
use Hyperf\AsyncQueue\Driver\RedisDriver;
return [
'default' => [
'driver' => RedisDriver::class,
'redis' => [
'pool' => 'default',
],
'channel' => '{queue}',
'timeout' => 2,
'retry_seconds' => 5,
'handle_timeout' => 10,
'processes' => 1,
'concurrent' => [
'limit' => 10,
],
'max_messages' => 0,
],
'whf' => [
'driver' => RedisDriver::class,
'redis' => [
'pool' => 'default',
],
'channel' => '{drp.custom}',
'timeout' => 2,
'retry_seconds' => 5,
'handle_timeout' => 10,
'processes' => 1,
'concurrent' => [
'limit' => 10,
],
'max_messages' => 0,
],
];

19
config/autoload/cache.php Normal file
View File

@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
return [
'default' => [
'driver' => Hyperf\Cache\Driver\RedisDriver::class,
'packer' => Hyperf\Codec\Packer\PhpSerializerPacker::class,
'prefix' => 'c:',
'skip_cache_results' => [],
],
];

View File

@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
return [
];

View File

@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
use function Hyperf\Support\env;
return [
'default' => [
'driver' => env('DB_DRIVER', 'mysql'),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', 3306),
'database' => env('DB_DATABASE', 'hyperf'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => env('DB_CHARSET', 'utf8mb4'),
'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'),
'prefix' => env('DB_PREFIX', ''),
'pool' => [
'min_connections' => 1,
'max_connections' => 10,
'connect_timeout' => 10.0,
'wait_timeout' => 3.0,
'heartbeat' => -1,
'max_idle_time' => (float) env('DB_MAX_IDLE_TIME', 60),
],
'cache' => [
'handler' => Hyperf\ModelCache\Handler\RedisHandler::class,
'cache_key' => '{mc:%s:m:%s}:%s:%s',
'prefix' => 'default',
'ttl' => 3600 * 24,
'empty_model_ttl' => 600,
'load_script' => true,
],
'commands' => [
'gen:model' => [
'path' => 'app/Model',
'force_casts' => true,
'inheritance' => 'Model',
'uses' => '',
'table_mapping' => [],
],
],
],
];

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
use App\JsonRpc\EasyAppServiceConsumer;
use App\JsonRpc\EasyAppServiceInterface;
use App\JsonRpc\InventoryServiceConsumer;
use App\JsonRpc\InventoryServiceInterface;
use App\JsonRpc\UserAuthServiceConsumer;
use App\JsonRpc\UserAuthServiceInterface;
use App\Log\StdoutLoggerFactory;
use Hyperf\Contract\StdoutLoggerInterface;
return [
StdoutLoggerInterface::class => StdoutLoggerFactory::class,
UserAuthServiceInterface::class => UserAuthServiceConsumer::class,
EasyAppServiceInterface::class => EasyAppServiceConsumer::class,
InventoryServiceInterface::class => InventoryServiceConsumer::class,
];

View File

@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
return [
'generator' => [
'amqp' => [
'consumer' => [
'namespace' => 'App\\Amqp\\Consumer',
],
'producer' => [
'namespace' => 'App\\Amqp\\Producer',
],
],
'aspect' => [
'namespace' => 'App\\Aspect',
],
'command' => [
'namespace' => 'App\\Command',
],
'controller' => [
'namespace' => 'App\\Controller',
],
'job' => [
'namespace' => 'App\\Job',
],
'listener' => [
'namespace' => 'App\\Listener',
],
'middleware' => [
'namespace' => 'App\\Middleware',
],
'Process' => [
'namespace' => 'App\\Processes',
],
],
];

View File

@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
use App\Exception\Handler\ApiExceptionHandler;
use App\Exception\Handler\AppExceptionHandler;
use Hyperf\HttpServer\Exception\Handler\HttpExceptionHandler;
return [
'handler' => [
'http' => [
HttpExceptionHandler::class,
AppExceptionHandler::class,
ApiExceptionHandler::class,
],
],
];

View File

@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
return [
Hyperf\ExceptionHandler\Listener\ErrorExceptionHandler::class,
Hyperf\Command\Listener\FailToHandleListener::class,
];

View File

@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
use App\Log\AliSlsHandler;
use App\Log\AppendRequestIdProcessor;
use Monolog\Formatter\JsonFormatter;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\RotatingFileHandler;
use Psr\Log\LogLevel;
use function Hyperf\Support\env;
$env = env('APP_ENV', 'production');
$isProduction = $env === 'production';
$productionLogLevel = env('LOG_LEVEL', 'error');
$formatter = $isProduction
? [
'class' => JsonFormatter::class,
'constructor' => [
'format' => null,
'dateFormat' => 'Y-m-d H:i:s',
'allowInlineLineBreaks' => true,
],
]
: [
'class' => LineFormatter::class,
'constructor' => [
'format' => "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n",
'dateFormat' => 'Y-m-d H:i:s',
'allowInlineLineBreaks' => true,
],
];
$loggers = [
'default', 'sql', 'request', 'crontab', 'queue', 'timer', 'job', 'some', 'amqp'
];
$logLevel = $isProduction ? $productionLogLevel : LogLevel::INFO;
$config = [];
foreach ($loggers as $loggerName) {
$handler = $isProduction
? [
'class' => AliSlsHandler::class,
'constructor' => [
'filename' => BASE_PATH . sprintf('/runtime/logs/%s/%s.log', $loggerName, $loggerName),
'level' => $logLevel,
'maxFiles' => 30,
],
]
: [
'class' => RotatingFileHandler::class,
'constructor' => [
'filename' => BASE_PATH . sprintf('/runtime/logs/%s/%s.log', $loggerName, $loggerName),
'level' => $logLevel,
'maxFiles' => 30,
],
];
$config[$loggerName] = [
'handler' => $handler,
'formatter' => $formatter,
'processors' => [
[
'class' => AppendRequestIdProcessor::class,
],
],
];
}
return $config;

1099
config/autoload/menu.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
use App\Middleware\RequestLogsMiddleware;
use Hyperf\Validation\Middleware\ValidationMiddleware;
return [
'http' => [
ValidationMiddleware::class,
RequestLogsMiddleware::class,
],
];

View File

@ -0,0 +1,22 @@
<?php
/**
* Author: ykxiao
* Date: 2025/6/5
* Time: 下午7:37
* Description:
*
* (c) ykxiao <yk_9001@hotmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
declare(strict_types=1);
return [
[
'id' => 1,
'action' => 'UserController@userLogin',
'name' => '用户登录',
]
];

View File

@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
return [
];

29
config/autoload/redis.php Normal file
View File

@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
use function Hyperf\Support\env;
return [
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'auth' => env('REDIS_AUTH', null),
'port' => (int) env('REDIS_PORT', 6379),
'db' => (int) env('REDIS_DB', 0),
'pool' => [
'min_connections' => 1,
'max_connections' => 10,
'connect_timeout' => 10.0,
'wait_timeout' => 3.0,
'heartbeat' => -1,
'max_idle_time' => (float) env('REDIS_MAX_IDLE_TIME', 60),
],
],
];

View File

@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
use Hyperf\HttpServer\Server;
use Hyperf\Server\Event;
use Hyperf\Server\ServerInterface;
use Swoole\Constant;
return [
'mode' => SWOOLE_PROCESS,
'servers' => [
[
'name' => 'http',
'type' => ServerInterface::SERVER_HTTP,
'host' => '0.0.0.0',
'port' => 9501,
'sock_type' => SWOOLE_SOCK_TCP,
'callbacks' => [
Event::ON_REQUEST => [Server::class, 'onRequest'],
],
'options' => [
// Whether to enable request lifecycle event
'enable_request_lifecycle' => false,
],
],
],
'settings' => [
Constant::OPTION_ENABLE_COROUTINE => true,
Constant::OPTION_WORKER_NUM => min(swoole_cpu_num() * 4, 32),
Constant::OPTION_PID_FILE => BASE_PATH . '/runtime/hyperf.pid',
Constant::OPTION_OPEN_TCP_NODELAY => true,
Constant::OPTION_MAX_COROUTINE => 100000,
Constant::OPTION_OPEN_HTTP2_PROTOCOL => true,
Constant::OPTION_MAX_REQUEST => 100000,
Constant::OPTION_SOCKET_BUFFER_SIZE => 2 * 1024 * 1024,
Constant::OPTION_BUFFER_OUTPUT_SIZE => 2 * 1024 * 1024,
Constant::OPTION_ENABLE_DEADLOCK_CHECK => true,
// 连接池配置
Constant::OPTION_REACTOR_NUM => swoole_cpu_num(),
],
'callbacks' => [
Event::ON_WORKER_START => [Hyperf\Framework\Bootstrap\WorkerStartCallback::class, 'onWorkerStart'],
Event::ON_PIPE_MESSAGE => [Hyperf\Framework\Bootstrap\PipeMessageCallback::class, 'onPipeMessage'],
Event::ON_WORKER_EXIT => [Hyperf\Framework\Bootstrap\WorkerExitCallback::class, 'onWorkerExit'],
],
];

View File

@ -0,0 +1,63 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
use App\JsonRpc\EasyAppServiceInterface;
use App\JsonRpc\InventoryServiceInterface;
use App\JsonRpc\UserAuthServiceInterface;
use function Hyperf\Support\value;
return [
'consumers' => value(function () {
$consumers = [];
$services = [
'UserAuthService' => UserAuthServiceInterface::class,
'EasyAppService' => EasyAppServiceInterface::class,
'InventoryService' => InventoryServiceInterface::class,
];
foreach ($services as $name => $interface) {
$consumers[] = [
'name' => $name,
'service' => $interface,
'protocol' => 'jsonrpc-http',
'load_balancer' => 'random',
'registry' => [
'protocol' => 'nacos',
'address' => 'http://127.0.0.1:8848',
],
'options' => [
'connect_timeout' => 5.0,
'recv_timeout' => 5.0,
'settings' => [
// 开启连接池
'open_connection_pool' => true,
],
// 重试次数,默认值为 2收包超时不进行重试。暂只支持 JsonRpcPoolTransporter
'retry_count' => 2,
// 重试间隔,毫秒
'retry_interval' => 100,
// 使用多路复用 RPC 时的心跳间隔null 为不触发心跳
'heartbeat' => 30,
'pool' => [
'min_connections' => 1,
'max_connections' => 100,
'connect_timeout' => 10.0,
'wait_timeout' => 3.0,
'heartbeat' => 30,
'max_idle_time' => 60.0,
],
]
];
}
return $consumers;
}),
];

View File

@ -0,0 +1,21 @@
<?php
/**
* Author: ykxiao
* Date: 2025/6/3
* Time: 下午8:40
* Description:
*
* (c) ykxiao <yk_9001@hotmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
declare(strict_types=1);
// 配置RPC公司信息
return [
'companyInfo' => [
'full_name' => '苏州德木智造科技有限公司',
],
];

View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
return [
'locale' => 'zh_CN',
'fallback_locale' => 'en',
'path' => BASE_PATH . '/storage/languages',
];

33
config/config.php Normal file
View File

@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
use Hyperf\Contract\StdoutLoggerInterface;
use Psr\Log\LogLevel;
use function Hyperf\Support\env;
return [
'app_name' => env('APP_NAME', 'skeleton'),
'app_env' => env('APP_ENV', 'dev'),
'scan_cacheable' => env('SCAN_CACHEABLE', false),
StdoutLoggerInterface::class => [
'log_level' => [
LogLevel::ALERT,
LogLevel::CRITICAL,
LogLevel::DEBUG,
LogLevel::EMERGENCY,
LogLevel::ERROR,
LogLevel::INFO,
LogLevel::NOTICE,
LogLevel::WARNING,
],
],
];

21
config/container.php Normal file
View File

@ -0,0 +1,21 @@
<?php
/**
* Initialize a dependency injection container that implemented PSR-11 and return the container.
*/
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
use Hyperf\Context\ApplicationContext;
use Hyperf\Di\Container;
use Hyperf\Di\Definition\DefinitionSourceFactory;
$container = new Container((new DefinitionSourceFactory())());
return ApplicationContext::setContainer($container);

56
config/routes.php Normal file
View File

@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
use App\Controller\CompanyController;
use App\Controller\FirstCompanyController;
use App\Controller\PurchaseController;
use App\Controller\RoleController;
use App\Controller\UserController;
use App\Middleware\CheckTokenMiddleware;
use Hyperf\HttpServer\Router\Router;
Router::get('/favicon.ico', function () {
return '';
});
Router::addGroup('/api/v1/', function () {
Router::post('user.login', [UserController::class, 'userLogin']); # 用户登录
});
Router::addGroup('/api/v1', function () {
Router::addGroup('/', function () {
/**
* 用户管理
*/
Router::post('user.add', [UserController::class, 'addUser']); # 新增用户
Router::post('user.list', [UserController::class, 'getUserList']); # 获取用户列表
Router::post('user.import', [UserController::class, 'importUser']); # 批量导入用户信息
/**
* 角色管理
*/
Router::post('role.add', [RoleController::class, 'addRole']); # 获取用户信息
/**
* 采购入库管理
*/
Router::post('purchase.add', [PurchaseController::class, 'addPurchase']); # 新增采购入库单
/**
* 公司管理
*/
Router::post('company.add', [CompanyController::class, 'addCompany']); # 新增公司
Router::post('company.add.first', [FirstCompanyController::class, 'addFirstCompany']); # 新增平台公司
});
}, ['middleware' => [CheckTokenMiddleware::class]]);