feat: 初始化进销存数据开放平台项目
初始化完整的前后端项目结构,包含ThinkPHP后端API服务和Next.js前端管理系统,添加基础配置、中间件、模型、路由等核心代码,以及项目文档和静态资源。
This commit is contained in:
73
thinkphp/route/app.php
Normal file
73
thinkphp/route/app.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
use think\facade\Route;
|
||||
|
||||
// ========== 系统路由 ==========
|
||||
/* Route::get('/', function () {
|
||||
return json([
|
||||
'app' => '进销存数据开放平台',
|
||||
'version' => '1.0.0',
|
||||
'docs' => '/docs',
|
||||
]);
|
||||
}); */
|
||||
|
||||
Route::get('/health', function () {
|
||||
try {
|
||||
\think\facade\Db::connect('mssql')->query('SELECT 1');
|
||||
$mssqlStatus = 'connected';
|
||||
} catch (\Exception $e) {
|
||||
$mssqlStatus = 'disconnected';
|
||||
}
|
||||
|
||||
return json([
|
||||
'status' => $mssqlStatus === 'connected' ? 'ok' : 'degraded',
|
||||
'sql_server' => $mssqlStatus,
|
||||
]);
|
||||
});
|
||||
|
||||
// ========== 对外API路由(需要签名验证和限流)==========
|
||||
Route::group('api/v1', function () {
|
||||
Route::get('chuku', 'api.v1.Chuku/index');
|
||||
Route::get('ruku', 'api.v1.Ruku/index');
|
||||
})->middleware([\app\middleware\Auth::class, \app\middleware\RateLimit::class]);
|
||||
|
||||
// ========== 后台管理路由(需要管理员认证)==========
|
||||
// 登录接口不需要认证
|
||||
Route::post('api/admin/auth/login', 'api.admin.Auth/login');
|
||||
|
||||
// 修改密码接口需要认证
|
||||
Route::put('api/admin/auth/password', 'api.admin.Auth/changePassword')->middleware([\app\middleware\AdminAuth::class]);
|
||||
|
||||
// 其他管理接口需要认证
|
||||
Route::group('api/admin', function () {
|
||||
// 仪表盘
|
||||
Route::get('dashboard/stats', 'api.admin.Dashboard/stats');
|
||||
Route::get('dashboard/trend', 'api.admin.Dashboard/trend');
|
||||
|
||||
// 客户管理 - 按从具体到通用的顺序排列
|
||||
Route::post('clients/api-keys/create/:id', 'api.admin.ClientController/generateApiKey');
|
||||
Route::get('clients/api-keys/:id', 'api.admin.ClientController/apiKeys');
|
||||
Route::put('clients/update/:id', 'api.admin.ClientController/update');
|
||||
Route::patch('clients/toggle/:id', 'api.admin.ClientController/toggle');
|
||||
Route::delete('api-keys/delete/:keyId', 'api.admin.ClientController/deleteApiKey');
|
||||
Route::get('clients', 'api.admin.ClientController/index');
|
||||
Route::post('clients', 'api.admin.ClientController/create');
|
||||
|
||||
// 权限管理
|
||||
Route::get('permissions/:id', 'api.admin.PermissionController/read');
|
||||
Route::put('permissions/:id', 'api.admin.PermissionController/update');
|
||||
|
||||
// 日志管理
|
||||
Route::get('logs', 'api.admin.Log/index');
|
||||
Route::get('logs/:id', 'api.admin.Log/read');
|
||||
Route::get('logs/stats', 'api.admin.Log/stats');
|
||||
Route::get('logs/export', 'api.admin.Log/export');
|
||||
})->middleware([\app\middleware\AdminAuth::class]);
|
||||
64
thinkphp/route/route.php
Normal file
64
thinkphp/route/route.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
use think\facade\Route;
|
||||
|
||||
defined('DS') || define('DS', DIRECTORY_SEPARATOR);
|
||||
|
||||
Route::miss(function () {
|
||||
$appRequest = request()->pathinfo();
|
||||
if ($appRequest === null) {
|
||||
$appName = '';
|
||||
} else {
|
||||
$appRequest = str_replace('//', '/', $appRequest);
|
||||
$appName = explode('/', $appRequest)[0] ?? '';
|
||||
}
|
||||
|
||||
$publicPath = app()->getRootPath() . 'public' . DS;
|
||||
|
||||
$staticExtensions = ['js', 'css', 'png', 'jpg', 'jpeg', 'gif', 'svg', 'ico', 'woff', 'woff2', 'ttf', 'eot'];
|
||||
$pathParts = explode('.', $appRequest);
|
||||
$extension = strtolower(end($pathParts));
|
||||
|
||||
if (in_array($extension, $staticExtensions)) {
|
||||
$filePath = $publicPath . $appRequest;
|
||||
if (file_exists($filePath)) {
|
||||
$mimeTypes = [
|
||||
'js' => 'application/javascript',
|
||||
'css' => 'text/css',
|
||||
'png' => 'image/png',
|
||||
'jpg' => 'image/jpeg',
|
||||
'jpeg' => 'image/jpeg',
|
||||
'gif' => 'image/gif',
|
||||
'svg' => 'image/svg+xml',
|
||||
'ico' => 'image/x-icon',
|
||||
'woff' => 'font/woff',
|
||||
'woff2' => 'font/woff2',
|
||||
'ttf' => 'font/ttf',
|
||||
'eot' => 'application/vnd.ms-fontobject',
|
||||
];
|
||||
header('Content-Type: ' . ($mimeTypes[$extension] ?? 'application/octet-stream'));
|
||||
return file_get_contents($filePath);
|
||||
}
|
||||
}
|
||||
|
||||
switch (strtolower($appName)) {
|
||||
case 'admin':
|
||||
$filePath = $publicPath . 'admin' . DS . 'index.html';
|
||||
break;
|
||||
case 'home':
|
||||
case 'pages':
|
||||
default:
|
||||
$filePath = $publicPath . 'admin' . DS . 'client.html';
|
||||
break;
|
||||
}
|
||||
|
||||
if (file_exists($filePath)) {
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
return file_get_contents($filePath);
|
||||
}
|
||||
|
||||
return json([
|
||||
'code' => 404,
|
||||
'msg' => '页面不存在'
|
||||
], 404);
|
||||
});
|
||||
Reference in New Issue
Block a user