feat: 第一阶段基础框架搭建

后端 (Laravel 10 + Sanctum):
- RBAC 四层权限系统 (users→roles→permissions→menus)
- 门店隔离中间件 (BelongsToStore Trait + StoreIsolation Middleware)
- 操作日志中间件 (自动记录写操作)
- 权限检查中间件 (CheckPermission)
- 16张数据库表迁移 (系统基础+RBAC+字典+配置)
- 11个 Eloquent Model
- Auth API (登录/登出/用户信息)
- 系统设置模块 CRUD (门店/部门/职务/用户/角色/菜单/权限/字典/日志)
- 45条 RESTful API 路由
- InitSeeder 初始数据 (超管/角色/76权限/31菜单)

前端 (Vue 3 + Element Plus + Vite):
- Axios 请求封装 + Token 注入
- Pinia 状态管理 (user + permission store)
- 动态路由 (服务端菜单→前端路由自动生成)
- 后台布局 (侧边栏+顶栏+主内容区)
- 登录页 + 仪表盘首页
- 系统设置 7 个 CRUD 页面

技术方案文档 (7卷):
- 技术总览/数据库设计/API规范/RBAC设计/模块详设/小程序设计/部署方案
This commit is contained in:
li
2026-03-13 19:52:09 +08:00
commit 11c177a432
144 changed files with 25209 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
# OS
.DS_Store
Thumbs.db
# IDE
.idea/
.vscode/
*.swp
*.swo
# Environment
.env
.env.local
.env.*.local
# Frontend
frontend/node_modules/
frontend/dist/
# Backend (Laravel handles its own via backend/.gitignore)
# Docker
docker/mysql/data/
docker/redis/data/
# Logs
*.log
+18
View File
@@ -0,0 +1,18 @@
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
[*.{yml,yaml}]
indent_size = 2
[compose.yaml]
indent_size = 4
+65
View File
@@ -0,0 +1,65 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
APP_LOCALE=en
APP_FALLBACK_LOCALE=en
APP_FAKER_LOCALE=en_US
APP_MAINTENANCE_DRIVER=file
# APP_MAINTENANCE_STORE=database
# PHP_CLI_SERVER_WORKERS=4
BCRYPT_ROUNDS=12
LOG_CHANNEL=stack
LOG_STACK=single
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=sqlite
# DB_HOST=127.0.0.1
# DB_PORT=3306
# DB_DATABASE=laravel
# DB_USERNAME=root
# DB_PASSWORD=
SESSION_DRIVER=database
SESSION_LIFETIME=120
SESSION_ENCRYPT=false
SESSION_PATH=/
SESSION_DOMAIN=null
BROADCAST_CONNECTION=log
FILESYSTEM_DISK=local
QUEUE_CONNECTION=database
CACHE_STORE=database
# CACHE_PREFIX=
MEMCACHED_HOST=127.0.0.1
REDIS_CLIENT=phpredis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=log
MAIL_SCHEME=null
MAIL_HOST=127.0.0.1
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_FROM_ADDRESS="hello@example.com"
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
VITE_APP_NAME="${APP_NAME}"
+11
View File
@@ -0,0 +1,11 @@
* text=auto eol=lf
*.blade.php diff=html
*.css diff=css
*.html diff=html
*.md diff=markdown
*.php diff=php
/.github export-ignore
CHANGELOG.md export-ignore
.styleci.yml export-ignore
+24
View File
@@ -0,0 +1,24 @@
*.log
.DS_Store
.env
.env.backup
.env.production
.phpactor.json
.phpunit.result.cache
/.fleet
/.idea
/.nova
/.phpunit.cache
/.vscode
/.zed
/auth.json
/node_modules
/public/build
/public/hot
/public/storage
/storage/*.key
/storage/pail
/vendor
Homestead.json
Homestead.yaml
Thumbs.db
+59
View File
@@ -0,0 +1,59 @@
<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400" alt="Laravel Logo"></a></p>
<p align="center">
<a href="https://github.com/laravel/framework/actions"><img src="https://github.com/laravel/framework/workflows/tests/badge.svg" alt="Build Status"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a>
</p>
## About Laravel
Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:
- [Simple, fast routing engine](https://laravel.com/docs/routing).
- [Powerful dependency injection container](https://laravel.com/docs/container).
- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage.
- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent).
- Database agnostic [schema migrations](https://laravel.com/docs/migrations).
- [Robust background job processing](https://laravel.com/docs/queues).
- [Real-time event broadcasting](https://laravel.com/docs/broadcasting).
Laravel is accessible, powerful, and provides tools required for large, robust applications.
## Learning Laravel
Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework. You can also check out [Laravel Learn](https://laravel.com/learn), where you will be guided through building a modern Laravel application.
If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains thousands of video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library.
## Laravel Sponsors
We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the [Laravel Partners program](https://partners.laravel.com).
### Premium Partners
- **[Vehikl](https://vehikl.com)**
- **[Tighten Co.](https://tighten.co)**
- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)**
- **[64 Robots](https://64robots.com)**
- **[Curotec](https://www.curotec.com/services/technologies/laravel)**
- **[DevSquad](https://devsquad.com/hire-laravel-developers)**
- **[Redberry](https://redberry.international/laravel-development)**
- **[Active Logic](https://activelogic.com)**
## Contributing
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).
## Code of Conduct
In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).
## Security Vulnerabilities
If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed.
## License
The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
+19
View File
@@ -0,0 +1,19 @@
<?php
namespace App\Enums;
enum MenuType: int
{
case Directory = 1;
case Menu = 2;
case Button = 3;
public function label(): string
{
return match ($this) {
self::Directory => '目录',
self::Menu => '菜单',
self::Button => '按钮',
};
}
}
+19
View File
@@ -0,0 +1,19 @@
<?php
namespace App\Enums;
enum PermissionType: int
{
case Menu = 1;
case Button = 2;
case Api = 3;
public function label(): string
{
return match ($this) {
self::Menu => '菜单',
self::Button => '按钮',
self::Api => '接口',
};
}
}
+19
View File
@@ -0,0 +1,19 @@
<?php
namespace App\Enums;
enum UserStatus: int
{
case Pending = 0;
case Active = 1;
case Disabled = 2;
public function label(): string
{
return match ($this) {
self::Pending => '待审核',
self::Active => '正常',
self::Disabled => '禁用',
};
}
}
@@ -0,0 +1,88 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
class AuthController extends Controller
{
/**
* 登录
*/
public function login(Request $request): JsonResponse
{
$request->validate([
'username' => 'required|string',
'password' => 'required|string',
]);
$user = User::withoutGlobalScope('store')
->where('username', $request->username)
->first();
if (!$user || !Hash::check($request->password, $user->password)) {
return $this->error('用户名或密码错误', 40100, 401);
}
if ($user->status->value !== 1) {
return $this->error('账号已被禁用或待审核', 40101, 403);
}
// 清除旧 token
$user->tokens()->delete();
$token = $user->createToken('admin')->plainTextToken;
$user->update(['last_login_at' => now()]);
return $this->success([
'token' => $token,
'user' => [
'id' => $user->id,
'username' => $user->username,
'name' => $user->name,
'avatar' => $user->avatar,
'store_id' => $user->store_id,
'is_super' => $user->is_super,
],
]);
}
/**
* 退出登录
*/
public function logout(Request $request): JsonResponse
{
$request->user()->currentAccessToken()->delete();
return $this->success(null, '退出成功');
}
/**
* 获取当前用户信息
*/
public function me(Request $request): JsonResponse
{
$user = $request->user();
$user->load(['department', 'position', 'roles']);
return $this->success([
'id' => $user->id,
'username' => $user->username,
'name' => $user->name,
'phone' => $user->phone,
'email' => $user->email,
'avatar' => $user->avatar,
'store_id' => $user->store_id,
'is_super' => $user->is_super,
'department' => $user->department?->name,
'position' => $user->position?->name,
'roles' => $user->roles->pluck('name'),
'permissions' => $user->getAllPermissionCodes(),
'menus' => $user->getMenuTree(),
]);
}
}
@@ -0,0 +1,80 @@
<?php
namespace App\Http\Controllers\Admin\System;
use App\Http\Controllers\Controller;
use App\Models\Department;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class DepartmentController extends Controller
{
/**
* 部门树
*/
public function index(): JsonResponse
{
$departments = Department::orderBy('sort')->get()->toArray();
$tree = $this->buildTree($departments);
return $this->success($tree);
}
public function store(Request $request): JsonResponse
{
$data = $request->validate([
'parent_id' => 'integer',
'name' => 'required|string|max:50',
'sort' => 'integer',
'status' => 'in:0,1',
]);
$data['store_id'] = $data['store_id'] ?? auth()->user()->store_id;
$department = Department::create($data);
return $this->success($department, '创建成功');
}
public function update(Request $request, Department $department): JsonResponse
{
$data = $request->validate([
'parent_id' => 'integer',
'name' => 'string|max:50',
'sort' => 'integer',
'status' => 'in:0,1',
]);
// 不能设自己为上级
if (isset($data['parent_id']) && $data['parent_id'] == $department->id) {
return $this->error('不能设置自身为上级部门');
}
$department->update($data);
return $this->success($department, '更新成功');
}
public function destroy(Department $department): JsonResponse
{
if ($department->children()->exists()) {
return $this->error('该部门下还有子部门,无法删除');
}
if ($department->users()->exists()) {
return $this->error('该部门下还有员工,无法删除');
}
$department->delete();
return $this->success(null, '删除成功');
}
private function buildTree(array $items, int $parentId = 0): array
{
$tree = [];
foreach ($items as $item) {
if ($item['parent_id'] == $parentId) {
$children = $this->buildTree($items, $item['id']);
if ($children) {
$item['children'] = $children;
}
$tree[] = $item;
}
}
return $tree;
}
}
@@ -0,0 +1,91 @@
<?php
namespace App\Http\Controllers\Admin\System;
use App\Http\Controllers\Controller;
use App\Models\Dictionary;
use App\Models\DictionaryItem;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class DictionaryController extends Controller
{
public function index(): JsonResponse
{
$dictionaries = Dictionary::withCount('items')->orderByDesc('id')->get();
return $this->success($dictionaries);
}
public function store(Request $request): JsonResponse
{
$data = $request->validate([
'name' => 'required|string|max:50',
'code' => 'required|string|max:50|unique:dictionaries,code',
'description' => 'nullable|string|max:255',
]);
$dict = Dictionary::create($data);
return $this->success($dict, '创建成功');
}
/**
* 字典项列表
*/
public function items(Dictionary $dictionary): JsonResponse
{
return $this->success($dictionary->items);
}
/**
* 新建字典项
*/
public function storeItem(Request $request, Dictionary $dictionary): JsonResponse
{
$data = $request->validate([
'label' => 'required|string|max:100',
'value' => 'required|string|max:100',
'sort' => 'integer',
'status' => 'in:0,1',
]);
$data['dictionary_id'] = $dictionary->id;
$item = DictionaryItem::create($data);
return $this->success($item, '创建成功');
}
/**
* 更新字典项
*/
public function updateItem(Request $request, DictionaryItem $item): JsonResponse
{
$data = $request->validate([
'label' => 'string|max:100',
'value' => 'string|max:100',
'sort' => 'integer',
'status' => 'in:0,1',
]);
$item->update($data);
return $this->success($item, '更新成功');
}
/**
* 删除字典项
*/
public function destroyItem(DictionaryItem $item): JsonResponse
{
$item->delete();
return $this->success(null, '删除成功');
}
public function destroy(Dictionary $dictionary): JsonResponse
{
if ($dictionary->is_system) {
return $this->error('系统字典不可删除');
}
$dictionary->items()->delete();
$dictionary->delete();
return $this->success(null, '删除成功');
}
}
@@ -0,0 +1,71 @@
<?php
namespace App\Http\Controllers\Admin\System;
use App\Http\Controllers\Controller;
use App\Models\Menu;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class MenuController extends Controller
{
/**
* 菜单树
*/
public function index(): JsonResponse
{
return $this->success(Menu::tree());
}
public function store(Request $request): JsonResponse
{
$data = $request->validate([
'parent_id' => 'integer',
'name' => 'required|string|max:50',
'path' => 'nullable|string|max:255',
'component' => 'nullable|string|max:255',
'icon' => 'nullable|string|max:50',
'permission_code' => 'nullable|string|max:100',
'type' => 'required|in:1,2,3',
'visible' => 'in:0,1',
'sort' => 'integer',
'status' => 'in:0,1',
]);
$menu = Menu::create($data);
return $this->success($menu, '创建成功');
}
public function update(Request $request, Menu $menu): JsonResponse
{
$data = $request->validate([
'parent_id' => 'integer',
'name' => 'string|max:50',
'path' => 'nullable|string|max:255',
'component' => 'nullable|string|max:255',
'icon' => 'nullable|string|max:50',
'permission_code' => 'nullable|string|max:100',
'type' => 'in:1,2,3',
'visible' => 'in:0,1',
'sort' => 'integer',
'status' => 'in:0,1',
]);
if (isset($data['parent_id']) && $data['parent_id'] == $menu->id) {
return $this->error('不能设置自身为上级菜单');
}
$menu->update($data);
return $this->success($menu, '更新成功');
}
public function destroy(Menu $menu): JsonResponse
{
if ($menu->children()->exists()) {
return $this->error('该菜单下还有子菜单,无法删除');
}
$menu->delete();
return $this->success(null, '删除成功');
}
}
@@ -0,0 +1,39 @@
<?php
namespace App\Http\Controllers\Admin\System;
use App\Http\Controllers\Controller;
use App\Models\OperationLog;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class OperationLogController extends Controller
{
public function index(Request $request): JsonResponse
{
$query = OperationLog::query();
$user = auth()->user();
if (!$user->is_super) {
$query->where('store_id', $user->store_id);
}
if ($request->keyword) {
$query->where(function ($q) use ($request) {
$q->where('user_name', 'like', "%{$request->keyword}%")
->orWhere('target', 'like', "%{$request->keyword}%");
});
}
if ($request->module) {
$query->where('module', $request->module);
}
if ($request->start_date && $request->end_date) {
$query->whereBetween('created_at', [$request->start_date, $request->end_date . ' 23:59:59']);
}
$logs = $query->orderByDesc('created_at')
->paginate($request->input('page_size', 20));
return $this->paginate($logs);
}
}
@@ -0,0 +1,62 @@
<?php
namespace App\Http\Controllers\Admin\System;
use App\Http\Controllers\Controller;
use App\Models\Permission;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class PermissionController extends Controller
{
/**
* 权限树
*/
public function index(): JsonResponse
{
return $this->success(Permission::tree());
}
public function store(Request $request): JsonResponse
{
$data = $request->validate([
'parent_id' => 'integer',
'name' => 'required|string|max:50',
'code' => 'required|string|max:100|unique:permissions,code',
'module' => 'nullable|string|max:50',
'type' => 'required|in:1,2,3',
'description' => 'nullable|string|max:255',
'sort' => 'integer',
]);
$permission = Permission::create($data);
return $this->success($permission, '创建成功');
}
public function update(Request $request, Permission $permission): JsonResponse
{
$data = $request->validate([
'parent_id' => 'integer',
'name' => 'string|max:50',
'code' => 'string|max:100|unique:permissions,code,' . $permission->id,
'module' => 'nullable|string|max:50',
'type' => 'in:1,2,3',
'description' => 'nullable|string|max:255',
'sort' => 'integer',
]);
$permission->update($data);
return $this->success($permission, '更新成功');
}
public function destroy(Permission $permission): JsonResponse
{
if ($permission->children()->exists()) {
return $this->error('该权限下有子权限,无法删除');
}
$permission->roles()->detach();
$permission->delete();
return $this->success(null, '删除成功');
}
}
@@ -0,0 +1,48 @@
<?php
namespace App\Http\Controllers\Admin\System;
use App\Http\Controllers\Controller;
use App\Models\Position;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class PositionController extends Controller
{
public function index(Request $request): JsonResponse
{
$positions = Position::orderBy('sort')
->paginate($request->input('page_size', 50));
return $this->paginate($positions);
}
public function store(Request $request): JsonResponse
{
$data = $request->validate([
'name' => 'required|string|max:50',
'sort' => 'integer',
]);
$data['store_id'] = auth()->user()->store_id;
$position = Position::create($data);
return $this->success($position, '创建成功');
}
public function update(Request $request, Position $position): JsonResponse
{
$data = $request->validate([
'name' => 'string|max:50',
'sort' => 'integer',
]);
$position->update($data);
return $this->success($position, '更新成功');
}
public function destroy(Position $position): JsonResponse
{
$position->delete();
return $this->success(null, '删除成功');
}
}
@@ -0,0 +1,98 @@
<?php
namespace App\Http\Controllers\Admin\System;
use App\Http\Controllers\Controller;
use App\Models\Role;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class RoleController extends Controller
{
public function index(Request $request): JsonResponse
{
$query = Role::withCount('users');
if ($request->keyword) {
$query->where('name', 'like', "%{$request->keyword}%");
}
// 门店角色 + 全局角色
$user = auth()->user();
if (!$user->is_super) {
$query->where(function ($q) use ($user) {
$q->where('store_id', $user->store_id)
->orWhereNull('store_id');
});
}
$roles = $query->orderByDesc('id')
->paginate($request->input('page_size', 20));
return $this->paginate($roles);
}
public function store(Request $request): JsonResponse
{
$data = $request->validate([
'name' => 'required|string|max:50',
'code' => 'required|string|max:50|unique:roles,code',
'description' => 'nullable|string|max:255',
]);
$user = auth()->user();
$data['store_id'] = $user->is_super ? null : $user->store_id;
$role = Role::create($data);
return $this->success($role, '创建成功');
}
public function show(Role $role): JsonResponse
{
$role->load('permissions');
return $this->success($role);
}
public function update(Request $request, Role $role): JsonResponse
{
if ($role->is_system) {
return $this->error('系统内置角色不可编辑');
}
$data = $request->validate([
'name' => 'string|max:50',
'description' => 'nullable|string|max:255',
]);
$role->update($data);
return $this->success($role, '更新成功');
}
/**
* 分配权限
*/
public function assignPermissions(Request $request, Role $role): JsonResponse
{
$request->validate([
'permission_ids' => 'required|array',
'permission_ids.*' => 'exists:permissions,id',
]);
$role->permissions()->sync($request->permission_ids);
return $this->success(null, '权限分配成功');
}
public function destroy(Role $role): JsonResponse
{
if ($role->is_system) {
return $this->error('系统内置角色不可删除');
}
if ($role->users()->exists()) {
return $this->error('该角色下还有用户,无法删除');
}
$role->permissions()->detach();
$role->delete();
return $this->success(null, '删除成功');
}
}
@@ -0,0 +1,73 @@
<?php
namespace App\Http\Controllers\Admin\System;
use App\Http\Controllers\Controller;
use App\Models\Store;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class StoreController extends Controller
{
public function index(Request $request): JsonResponse
{
$query = Store::with('region');
if ($request->keyword) {
$query->where('name', 'like', "%{$request->keyword}%");
}
if ($request->has('status')) {
$query->where('status', $request->status);
}
$stores = $query->orderByDesc('id')
->paginate($request->input('page_size', 20));
return $this->paginate($stores);
}
public function store(Request $request): JsonResponse
{
$data = $request->validate([
'region_id' => 'required|exists:regions,id',
'name' => 'required|string|max:100',
'code' => 'nullable|string|max:20|unique:stores,code',
'address' => 'nullable|string|max:255',
'phone' => 'nullable|string|max:20',
'status' => 'in:0,1',
]);
$store = Store::create($data);
return $this->success($store, '创建成功');
}
public function show(Store $store): JsonResponse
{
$store->load('region');
return $this->success($store);
}
public function update(Request $request, Store $store): JsonResponse
{
$data = $request->validate([
'region_id' => 'exists:regions,id',
'name' => 'string|max:100',
'code' => 'nullable|string|max:20|unique:stores,code,' . $store->id,
'address' => 'nullable|string|max:255',
'phone' => 'nullable|string|max:20',
'status' => 'in:0,1',
]);
$store->update($data);
return $this->success($store, '更新成功');
}
public function destroy(Store $store): JsonResponse
{
if ($store->users()->exists()) {
return $this->error('该门店下还有员工,无法删除');
}
$store->delete();
return $this->success(null, '删除成功');
}
}
@@ -0,0 +1,123 @@
<?php
namespace App\Http\Controllers\Admin\System;
use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
class UserController extends Controller
{
public function index(Request $request): JsonResponse
{
$query = User::with(['department', 'position', 'roles']);
if ($request->keyword) {
$query->where(function ($q) use ($request) {
$q->where('name', 'like', "%{$request->keyword}%")
->orWhere('phone', 'like', "%{$request->keyword}%")
->orWhere('username', 'like', "%{$request->keyword}%");
});
}
if ($request->department_id) {
$query->where('department_id', $request->department_id);
}
if ($request->has('status')) {
$query->where('status', $request->status);
}
$users = $query->orderByDesc('id')
->paginate($request->input('page_size', 20));
return $this->paginate($users);
}
public function store(Request $request): JsonResponse
{
$data = $request->validate([
'username' => 'required|string|max:50|unique:users,username',
'password' => 'required|string|min:6',
'name' => 'required|string|max:50',
'phone' => 'nullable|string|max:20',
'email' => 'nullable|email|max:100',
'department_id' => 'nullable|exists:departments,id',
'position_id' => 'nullable|exists:positions,id',
'status' => 'in:0,1,2',
'role_ids' => 'array',
'role_ids.*' => 'exists:roles,id',
]);
$roleIds = $data['role_ids'] ?? [];
unset($data['role_ids']);
$data['store_id'] = auth()->user()->store_id;
$user = User::create($data);
if ($roleIds) {
$user->roles()->sync($roleIds);
}
return $this->success($user->load('roles'), '创建成功');
}
public function show(User $user): JsonResponse
{
$user->load(['department', 'position', 'roles']);
return $this->success($user);
}
public function update(Request $request, User $user): JsonResponse
{
$data = $request->validate([
'name' => 'string|max:50',
'phone' => 'nullable|string|max:20',
'email' => 'nullable|email|max:100',
'department_id' => 'nullable|exists:departments,id',
'position_id' => 'nullable|exists:positions,id',
'role_ids' => 'array',
'role_ids.*' => 'exists:roles,id',
]);
$roleIds = $data['role_ids'] ?? null;
unset($data['role_ids']);
$user->update($data);
if ($roleIds !== null) {
$user->roles()->sync($roleIds);
}
return $this->success($user->load('roles'), '更新成功');
}
/**
* 更新状态
*/
public function updateStatus(Request $request, User $user): JsonResponse
{
$request->validate(['status' => 'required|in:0,1,2']);
$user->update(['status' => $request->status]);
return $this->success(null, '状态更新成功');
}
/**
* 重置密码
*/
public function resetPassword(Request $request, User $user): JsonResponse
{
$request->validate(['password' => 'required|string|min:6']);
$user->update(['password' => $request->password]);
return $this->success(null, '密码重置成功');
}
public function destroy(User $user): JsonResponse
{
if ($user->is_super) {
return $this->error('超级管理员不可删除');
}
$user->delete();
return $this->success(null, '删除成功');
}
}
@@ -0,0 +1,47 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\JsonResponse;
abstract class Controller
{
/**
* 成功响应
*/
protected function success($data = null, string $message = 'success'): JsonResponse
{
return response()->json([
'code' => 0,
'message' => $message,
'data' => $data,
]);
}
/**
* 分页响应
*/
protected function paginate($paginator): JsonResponse
{
return response()->json([
'code' => 0,
'data' => [
'list' => $paginator->items(),
'total' => $paginator->total(),
'page' => $paginator->currentPage(),
'page_size' => $paginator->perPage(),
],
]);
}
/**
* 错误响应
*/
protected function error(string $message, int $code = 40001, int $httpCode = 400): JsonResponse
{
return response()->json([
'code' => $code,
'message' => $message,
], $httpCode);
}
}
@@ -0,0 +1,39 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
/**
* 权限检查中间件
* 用法:Route::middleware('permission:crm.lead.create')
*/
class CheckPermission
{
public function handle(Request $request, Closure $next, string ...$permissions)
{
$user = $request->user();
if (!$user) {
return response()->json(['code' => 40100, 'message' => '未认证'], 401);
}
// 超级管理员直接放行
if ($user->is_super) {
return $next($request);
}
// 检查权限
foreach ($permissions as $permission) {
if (!$user->hasPermission($permission)) {
return response()->json([
'code' => 40300,
'message' => '权限不足:' . $permission,
], 403);
}
}
return $next($request);
}
}
@@ -0,0 +1,86 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use App\Models\OperationLog as OperationLogModel;
/**
* 操作日志中间件
* 自动记录写操作(POST/PUT/PATCH/DELETE
*/
class OperationLog
{
/**
* 不记录的路由
*/
private array $except = [
'api/v1/auth/login',
'api/v1/auth/me',
];
public function handle(Request $request, Closure $next)
{
$response = $next($request);
// 仅记录写操作
if (!in_array($request->method(), ['POST', 'PUT', 'PATCH', 'DELETE'])) {
return $response;
}
// 排除白名单
foreach ($this->except as $pattern) {
if ($request->is($pattern)) {
return $response;
}
}
$user = $request->user();
if (!$user) {
return $response;
}
try {
// 从 URL 推断模块和操作
$path = $request->path();
$module = $this->parseModule($path);
$action = $this->parseAction($request->method());
OperationLogModel::create([
'store_id' => $user->store_id,
'user_id' => $user->id,
'user_name' => $user->name,
'module' => $module,
'action' => $action,
'target' => $path,
'ip' => $request->ip(),
'method' => $request->method(),
'url' => $request->fullUrl(),
'created_at' => now(),
]);
} catch (\Throwable $e) {
// 日志记录失败不影响业务
\Log::warning('操作日志记录失败: ' . $e->getMessage());
}
return $response;
}
private function parseModule(string $path): string
{
// api/v1/system/users → system
$segments = explode('/', $path);
return $segments[2] ?? 'unknown';
}
private function parseAction(string $method): string
{
return match ($method) {
'POST' => 'create',
'PUT', 'PATCH' => 'update',
'DELETE' => 'delete',
default => $method,
};
}
}
@@ -0,0 +1,33 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
/**
* 门店隔离中间件
* 验证并设置当前用户的门店上下文
*/
class StoreIsolation
{
public function handle(Request $request, Closure $next)
{
$user = $request->user();
if (!$user) {
return response()->json(['code' => 40100, 'message' => '未认证'], 401);
}
// 超级管理员可通过 Header 切换门店
if ($user->is_super && $request->header('X-Store-Id')) {
$storeId = (int) $request->header('X-Store-Id');
// 验证门店存在
if (!\App\Models\Store::where('id', $storeId)->exists()) {
return response()->json(['code' => 40400, 'message' => '门店不存在'], 404);
}
}
return $next($request);
}
}
+38
View File
@@ -0,0 +1,38 @@
<?php
namespace App\Models;
use App\Traits\BelongsToStore;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Department extends Model
{
use BelongsToStore;
protected $fillable = [
'store_id', 'parent_id', 'name', 'sort', 'status',
];
protected $casts = [
'status' => 'integer',
];
public function children(): HasMany
{
return $this->hasMany(self::class, 'parent_id');
}
public function users(): HasMany
{
return $this->hasMany(User::class);
}
/**
* 递归获取部门树
*/
public function childrenRecursive(): HasMany
{
return $this->children()->with('childrenRecursive');
}
}
+20
View File
@@ -0,0 +1,20 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Dictionary extends Model
{
protected $fillable = ['name', 'code', 'description', 'is_system'];
protected $casts = [
'is_system' => 'boolean',
];
public function items(): HasMany
{
return $this->hasMany(DictionaryItem::class)->orderBy('sort');
}
}
+20
View File
@@ -0,0 +1,20 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class DictionaryItem extends Model
{
protected $fillable = ['dictionary_id', 'label', 'value', 'sort', 'status'];
protected $casts = [
'status' => 'integer',
];
public function dictionary(): BelongsTo
{
return $this->belongsTo(Dictionary::class);
}
}
+55
View File
@@ -0,0 +1,55 @@
<?php
namespace App\Models;
use App\Enums\MenuType;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Menu extends Model
{
protected $fillable = [
'parent_id', 'name', 'path', 'component', 'icon',
'permission_code', 'type', 'visible', 'sort', 'status',
];
protected $casts = [
'type' => MenuType::class,
'visible' => 'integer',
'status' => 'integer',
];
public function children(): HasMany
{
return $this->hasMany(self::class, 'parent_id');
}
public function childrenRecursive(): HasMany
{
return $this->children()->with('childrenRecursive')->orderBy('sort');
}
/**
* 获取完整菜单树
*/
public static function tree(): array
{
$all = self::where('status', 1)->orderBy('sort')->get()->toArray();
return self::buildTree($all);
}
private static function buildTree(array $items, int $parentId = 0): array
{
$tree = [];
foreach ($items as $item) {
if ($item['parent_id'] == $parentId) {
$children = self::buildTree($items, $item['id']);
if ($children) {
$item['children'] = $children;
}
$tree[] = $item;
}
}
return $tree;
}
}
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class OperationLog extends Model
{
public $timestamps = false;
protected $fillable = [
'store_id', 'user_id', 'user_name', 'module', 'action',
'target', 'target_id', 'ip', 'method', 'url',
'before', 'after', 'created_at',
];
protected $casts = [
'before' => 'array',
'after' => 'array',
'created_at' => 'datetime',
];
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}
+53
View File
@@ -0,0 +1,53 @@
<?php
namespace App\Models;
use App\Enums\PermissionType;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Permission extends Model
{
protected $fillable = [
'parent_id', 'name', 'code', 'module', 'type', 'description', 'sort',
];
protected $casts = [
'type' => PermissionType::class,
];
public function children(): HasMany
{
return $this->hasMany(self::class, 'parent_id');
}
public function roles(): BelongsToMany
{
return $this->belongsToMany(Role::class, 'role_permission');
}
/**
* 获取权限树
*/
public static function tree(): array
{
$all = self::orderBy('sort')->get()->toArray();
return self::buildTree($all);
}
private static function buildTree(array $items, int $parentId = 0): array
{
$tree = [];
foreach ($items as $item) {
if ($item['parent_id'] == $parentId) {
$children = self::buildTree($items, $item['id']);
if ($children) {
$item['children'] = $children;
}
$tree[] = $item;
}
}
return $tree;
}
}
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace App\Models;
use App\Traits\BelongsToStore;
use Illuminate\Database\Eloquent\Model;
class Position extends Model
{
use BelongsToStore;
protected $fillable = ['store_id', 'name', 'sort'];
}
+20
View File
@@ -0,0 +1,20 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Region extends Model
{
protected $fillable = ['name', 'sort', 'status'];
protected $casts = [
'status' => 'integer',
];
public function stores(): HasMany
{
return $this->hasMany(Store::class);
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Role extends Model
{
protected $fillable = [
'store_id', 'name', 'code', 'description', 'is_system',
];
protected $casts = [
'is_system' => 'boolean',
];
public function users(): BelongsToMany
{
return $this->belongsToMany(User::class, 'role_user');
}
public function permissions(): BelongsToMany
{
return $this->belongsToMany(Permission::class, 'role_permission');
}
}
+38
View File
@@ -0,0 +1,38 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Store extends Model
{
protected $fillable = [
'region_id', 'name', 'code', 'address', 'phone', 'logo', 'status',
];
protected $casts = [
'status' => 'integer',
];
public function region(): BelongsTo
{
return $this->belongsTo(Region::class);
}
public function departments(): HasMany
{
return $this->hasMany(Department::class);
}
public function users(): HasMany
{
return $this->hasMany(User::class);
}
public function positions(): HasMany
{
return $this->hasMany(Position::class);
}
}
+33
View File
@@ -0,0 +1,33 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class SystemConfig extends Model
{
protected $fillable = ['store_id', 'group', 'key', 'value', 'description'];
/**
* 获取配置值
*/
public static function getValue(string $key, ?int $storeId = null, $default = null)
{
$config = self::where('key', $key)
->where('store_id', $storeId)
->first();
return $config ? $config->value : $default;
}
/**
* 设置配置值
*/
public static function setValue(string $key, $value, ?int $storeId = null, string $group = 'general'): void
{
self::updateOrCreate(
['key' => $key, 'store_id' => $storeId],
['value' => $value, 'group' => $group]
);
}
}
+118
View File
@@ -0,0 +1,118 @@
<?php
namespace App\Models;
use App\Enums\UserStatus;
use App\Traits\BelongsToStore;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable
{
use HasApiTokens, HasFactory, SoftDeletes, BelongsToStore;
protected $fillable = [
'store_id', 'department_id', 'position_id',
'username', 'password', 'name', 'phone', 'email',
'avatar', 'status', 'is_super', 'last_login_at',
];
protected $hidden = ['password'];
protected function casts(): array
{
return [
'status' => UserStatus::class,
'is_super' => 'boolean',
'last_login_at' => 'datetime',
'password' => 'hashed',
];
}
public function department(): BelongsTo
{
return $this->belongsTo(Department::class);
}
public function position(): BelongsTo
{
return $this->belongsTo(Position::class);
}
public function roles(): BelongsToMany
{
return $this->belongsToMany(Role::class, 'role_user');
}
/**
* 获取用户所有权限标识
*/
public function getAllPermissionCodes(): array
{
if ($this->is_super) {
return ['*'];
}
return $this->roles()
->with('permissions')
->get()
->pluck('permissions')
->flatten()
->pluck('code')
->unique()
->values()
->toArray();
}
/**
* 检查是否有指定权限
*/
public function hasPermission(string $code): bool
{
if ($this->is_super) {
return true;
}
return in_array($code, $this->getAllPermissionCodes());
}
/**
* 获取用户菜单树
*/
public function getMenuTree(): array
{
if ($this->is_super) {
$menus = Menu::where('status', 1)->orderBy('sort')->get();
} else {
$permissionCodes = $this->getAllPermissionCodes();
$menus = Menu::where('status', 1)
->where(function ($q) use ($permissionCodes) {
$q->whereIn('permission_code', $permissionCodes)
->orWhereNull('permission_code');
})
->orderBy('sort')
->get();
}
return self::buildTree($menus->toArray());
}
private static function buildTree(array $items, int $parentId = 0): array
{
$tree = [];
foreach ($items as $item) {
if ($item['parent_id'] == $parentId) {
$children = self::buildTree($items, $item['id']);
if ($children) {
$item['children'] = $children;
}
$tree[] = $item;
}
}
return $tree;
}
}
@@ -0,0 +1,24 @@
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
//
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
//
}
}
+46
View File
@@ -0,0 +1,46 @@
<?php
namespace App\Traits;
use App\Models\Store;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* 门店隔离 Trait
* 使用方法:在 Model use BelongsToStore;
* 自动 Scope 过滤当前门店数据
*/
trait BelongsToStore
{
public static function bootBelongsToStore(): void
{
// 查询自动过滤门店
static::addGlobalScope('store', function (Builder $builder) {
if ($storeId = self::getCurrentStoreId()) {
$builder->where($builder->getModel()->getTable() . '.store_id', $storeId);
}
});
// 创建时自动填入 store_id
static::creating(function ($model) {
if (empty($model->store_id)) {
$model->store_id = self::getCurrentStoreId();
}
});
}
public function store(): BelongsTo
{
return $this->belongsTo(Store::class);
}
private static function getCurrentStoreId(): ?int
{
$user = auth()->user();
if ($user && $user->is_super && request()->header('X-Store-Id')) {
return (int) request()->header('X-Store-Id');
}
return $user?->store_id;
}
}
+41
View File
@@ -0,0 +1,41 @@
<?php
namespace App\Traits;
use App\Models\User;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* 自动记录创建者/更新者
*/
trait HasCreator
{
public static function bootHasCreator(): void
{
static::creating(function ($model) {
if (auth()->check()) {
if ($model->isFillable('created_by') || in_array('created_by', $model->getFillable())) {
$model->created_by = $model->created_by ?? auth()->id();
}
}
});
static::updating(function ($model) {
if (auth()->check()) {
if ($model->isFillable('updated_by') || in_array('updated_by', $model->getFillable())) {
$model->updated_by = auth()->id();
}
}
});
}
public function creator(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by');
}
public function updater(): BelongsTo
{
return $this->belongsTo(User::class, 'updated_by');
}
}
+18
View File
@@ -0,0 +1,18 @@
#!/usr/bin/env php
<?php
use Illuminate\Foundation\Application;
use Symfony\Component\Console\Input\ArgvInput;
define('LARAVEL_START', microtime(true));
// Register the Composer autoloader...
require __DIR__.'/vendor/autoload.php';
// Bootstrap Laravel and handle the command...
/** @var Application $app */
$app = require_once __DIR__.'/bootstrap/app.php';
$status = $app->handleCommand(new ArgvInput);
exit($status);
+26
View File
@@ -0,0 +1,26 @@
<?php
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
api: __DIR__.'/../routes/api.php',
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
apiPrefix: 'api/v1',
)
->withMiddleware(function (Middleware $middleware): void {
$middleware->alias([
'store' => \App\Http\Middleware\StoreIsolation::class,
'permission' => \App\Http\Middleware\CheckPermission::class,
'oplog' => \App\Http\Middleware\OperationLog::class,
]);
$middleware->statefulApi();
})
->withExceptions(function (Exceptions $exceptions): void {
//
})->create();
+2
View File
@@ -0,0 +1,2 @@
*
!.gitignore
+7
View File
@@ -0,0 +1,7 @@
<?php
use App\Providers\AppServiceProvider;
return [
AppServiceProvider::class,
];
+87
View File
@@ -0,0 +1,87 @@
{
"$schema": "https://getcomposer.org/schema.json",
"name": "laravel/laravel",
"type": "project",
"description": "The skeleton application for the Laravel framework.",
"keywords": ["laravel", "framework"],
"license": "MIT",
"require": {
"php": "^8.2",
"laravel/framework": "^12.0",
"laravel/sanctum": "^4.3",
"laravel/tinker": "^2.10.1"
},
"require-dev": {
"fakerphp/faker": "^1.23",
"laravel/pail": "^1.2.2",
"laravel/pint": "^1.24",
"laravel/sail": "^1.41",
"mockery/mockery": "^1.6",
"nunomaduro/collision": "^8.6",
"phpunit/phpunit": "^11.5.50"
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"setup": [
"composer install",
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\"",
"@php artisan key:generate",
"@php artisan migrate --force",
"npm install",
"npm run build"
],
"dev": [
"Composer\\Config::disableProcessTimeout",
"npx concurrently -c \"#93c5fd,#c4b5fd,#fb7185,#fdba74\" \"php artisan serve\" \"php artisan queue:listen --tries=1 --timeout=0\" \"php artisan pail --timeout=0\" \"npm run dev\" --names=server,queue,logs,vite --kill-others"
],
"test": [
"@php artisan config:clear --ansi",
"@php artisan test"
],
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-update-cmd": [
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi",
"@php -r \"file_exists('database/database.sqlite') || touch('database/database.sqlite');\"",
"@php artisan migrate --graceful --ansi"
],
"pre-package-uninstall": [
"Illuminate\\Foundation\\ComposerScripts::prePackageUninstall"
]
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"php-http/discovery": true
}
},
"minimum-stability": "stable",
"prefer-stable": true
}
+8452
View File
File diff suppressed because it is too large Load Diff
+126
View File
@@ -0,0 +1,126 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Application Name
|--------------------------------------------------------------------------
|
| This value is the name of your application, which will be used when the
| framework needs to place the application's name in a notification or
| other UI elements where an application name needs to be displayed.
|
*/
'name' => env('APP_NAME', 'Laravel'),
/*
|--------------------------------------------------------------------------
| Application Environment
|--------------------------------------------------------------------------
|
| This value determines the "environment" your application is currently
| running in. This may determine how you prefer to configure various
| services the application utilizes. Set this in your ".env" file.
|
*/
'env' => env('APP_ENV', 'production'),
/*
|--------------------------------------------------------------------------
| Application Debug Mode
|--------------------------------------------------------------------------
|
| When your application is in debug mode, detailed error messages with
| stack traces will be shown on every error that occurs within your
| application. If disabled, a simple generic error page is shown.
|
*/
'debug' => (bool) env('APP_DEBUG', false),
/*
|--------------------------------------------------------------------------
| Application URL
|--------------------------------------------------------------------------
|
| This URL is used by the console to properly generate URLs when using
| the Artisan command line tool. You should set this to the root of
| the application so that it's available within Artisan commands.
|
*/
'url' => env('APP_URL', 'http://localhost'),
/*
|--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Here you may specify the default timezone for your application, which
| will be used by the PHP date and date-time functions. The timezone
| is set to "UTC" by default as it is suitable for most use cases.
|
*/
'timezone' => 'UTC',
/*
|--------------------------------------------------------------------------
| Application Locale Configuration
|--------------------------------------------------------------------------
|
| The application locale determines the default locale that will be used
| by Laravel's translation / localization methods. This option can be
| set to any locale for which you plan to have translation strings.
|
*/
'locale' => env('APP_LOCALE', 'en'),
'fallback_locale' => env('APP_FALLBACK_LOCALE', 'en'),
'faker_locale' => env('APP_FAKER_LOCALE', 'en_US'),
/*
|--------------------------------------------------------------------------
| Encryption Key
|--------------------------------------------------------------------------
|
| This key is utilized by Laravel's encryption services and should be set
| to a random, 32 character string to ensure that all encrypted values
| are secure. You should do this prior to deploying the application.
|
*/
'cipher' => 'AES-256-CBC',
'key' => env('APP_KEY'),
'previous_keys' => [
...array_filter(
explode(',', (string) env('APP_PREVIOUS_KEYS', ''))
),
],
/*
|--------------------------------------------------------------------------
| Maintenance Mode Driver
|--------------------------------------------------------------------------
|
| These configuration options determine the driver used to determine and
| manage Laravel's "maintenance mode" status. The "cache" driver will
| allow maintenance mode to be controlled across multiple machines.
|
| Supported drivers: "file", "cache"
|
*/
'maintenance' => [
'driver' => env('APP_MAINTENANCE_DRIVER', 'file'),
'store' => env('APP_MAINTENANCE_STORE', 'database'),
],
];
+117
View File
@@ -0,0 +1,117 @@
<?php
use App\Models\User;
return [
/*
|--------------------------------------------------------------------------
| Authentication Defaults
|--------------------------------------------------------------------------
|
| This option defines the default authentication "guard" and password
| reset "broker" for your application. You may change these values
| as required, but they're a perfect start for most applications.
|
*/
'defaults' => [
'guard' => env('AUTH_GUARD', 'web'),
'passwords' => env('AUTH_PASSWORD_BROKER', 'users'),
],
/*
|--------------------------------------------------------------------------
| Authentication Guards
|--------------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| which utilizes session storage plus the Eloquent user provider.
|
| All authentication guards have a user provider, which defines how the
| users are actually retrieved out of your database or other storage
| system used by the application. Typically, Eloquent is utilized.
|
| Supported: "session"
|
*/
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
],
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication guards have a user provider, which defines how the
| users are actually retrieved out of your database or other storage
| system used by the application. Typically, Eloquent is utilized.
|
| If you have multiple user tables or models you may configure multiple
| providers to represent the model / table. These providers may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => env('AUTH_MODEL', User::class),
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
/*
|--------------------------------------------------------------------------
| Resetting Passwords
|--------------------------------------------------------------------------
|
| These configuration options specify the behavior of Laravel's password
| reset functionality, including the table utilized for token storage
| and the user provider that is invoked to actually retrieve users.
|
| The expiry time is the number of minutes that each reset token will be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
| The throttle setting is the number of seconds a user must wait before
| generating more password reset tokens. This prevents the user from
| quickly generating a very large amount of password reset tokens.
|
*/
'passwords' => [
'users' => [
'provider' => 'users',
'table' => env('AUTH_PASSWORD_RESET_TOKEN_TABLE', 'password_reset_tokens'),
'expire' => 60,
'throttle' => 60,
],
],
/*
|--------------------------------------------------------------------------
| Password Confirmation Timeout
|--------------------------------------------------------------------------
|
| Here you may define the number of seconds before a password confirmation
| window expires and users are asked to re-enter their password via the
| confirmation screen. By default, the timeout lasts for three hours.
|
*/
'password_timeout' => env('AUTH_PASSWORD_TIMEOUT', 10800),
];
+117
View File
@@ -0,0 +1,117 @@
<?php
use Illuminate\Support\Str;
return [
/*
|--------------------------------------------------------------------------
| Default Cache Store
|--------------------------------------------------------------------------
|
| This option controls the default cache store that will be used by the
| framework. This connection is utilized if another isn't explicitly
| specified when running a cache operation inside the application.
|
*/
'default' => env('CACHE_STORE', 'database'),
/*
|--------------------------------------------------------------------------
| Cache Stores
|--------------------------------------------------------------------------
|
| Here you may define all of the cache "stores" for your application as
| well as their drivers. You may even define multiple stores for the
| same cache driver to group types of items stored in your caches.
|
| Supported drivers: "array", "database", "file", "memcached",
| "redis", "dynamodb", "octane",
| "failover", "null"
|
*/
'stores' => [
'array' => [
'driver' => 'array',
'serialize' => false,
],
'database' => [
'driver' => 'database',
'connection' => env('DB_CACHE_CONNECTION'),
'table' => env('DB_CACHE_TABLE', 'cache'),
'lock_connection' => env('DB_CACHE_LOCK_CONNECTION'),
'lock_table' => env('DB_CACHE_LOCK_TABLE'),
],
'file' => [
'driver' => 'file',
'path' => storage_path('framework/cache/data'),
'lock_path' => storage_path('framework/cache/data'),
],
'memcached' => [
'driver' => 'memcached',
'persistent_id' => env('MEMCACHED_PERSISTENT_ID'),
'sasl' => [
env('MEMCACHED_USERNAME'),
env('MEMCACHED_PASSWORD'),
],
'options' => [
// Memcached::OPT_CONNECT_TIMEOUT => 2000,
],
'servers' => [
[
'host' => env('MEMCACHED_HOST', '127.0.0.1'),
'port' => env('MEMCACHED_PORT', 11211),
'weight' => 100,
],
],
],
'redis' => [
'driver' => 'redis',
'connection' => env('REDIS_CACHE_CONNECTION', 'cache'),
'lock_connection' => env('REDIS_CACHE_LOCK_CONNECTION', 'default'),
],
'dynamodb' => [
'driver' => 'dynamodb',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
'table' => env('DYNAMODB_CACHE_TABLE', 'cache'),
'endpoint' => env('DYNAMODB_ENDPOINT'),
],
'octane' => [
'driver' => 'octane',
],
'failover' => [
'driver' => 'failover',
'stores' => [
'database',
'array',
],
],
],
/*
|--------------------------------------------------------------------------
| Cache Key Prefix
|--------------------------------------------------------------------------
|
| When utilizing the APC, database, memcached, Redis, and DynamoDB cache
| stores, there might be other applications using the same cache. For
| that reason, you may prefix every cache key to avoid collisions.
|
*/
'prefix' => env('CACHE_PREFIX', Str::slug((string) env('APP_NAME', 'laravel')).'-cache-'),
];
+34
View File
@@ -0,0 +1,34 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Cross-Origin Resource Sharing (CORS) Configuration
|--------------------------------------------------------------------------
|
| Here you may configure your settings for cross-origin resource sharing
| or "CORS". This determines what cross-origin operations may execute
| in web browsers. You are free to adjust these settings as needed.
|
| To learn more: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
|
*/
'paths' => ['api/*', 'sanctum/csrf-cookie'],
'allowed_methods' => ['*'],
'allowed_origins' => ['*'],
'allowed_origins_patterns' => [],
'allowed_headers' => ['*'],
'exposed_headers' => [],
'max_age' => 0,
'supports_credentials' => true,
];
+184
View File
@@ -0,0 +1,184 @@
<?php
use Illuminate\Support\Str;
use Pdo\Mysql;
return [
/*
|--------------------------------------------------------------------------
| Default Database Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the database connections below you wish
| to use as your default connection for database operations. This is
| the connection which will be utilized unless another connection
| is explicitly specified when you execute a query / statement.
|
*/
'default' => env('DB_CONNECTION', 'sqlite'),
/*
|--------------------------------------------------------------------------
| Database Connections
|--------------------------------------------------------------------------
|
| Below are all of the database connections defined for your application.
| An example configuration is provided for each database system which
| is supported by Laravel. You're free to add / remove connections.
|
*/
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'url' => env('DB_URL'),
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
'busy_timeout' => null,
'journal_mode' => null,
'synchronous' => null,
'transaction_mode' => 'DEFERRED',
],
'mysql' => [
'driver' => 'mysql',
'url' => env('DB_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'laravel'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => env('DB_CHARSET', 'utf8mb4'),
'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'),
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
(PHP_VERSION_ID >= 80500 ? Mysql::ATTR_SSL_CA : PDO::MYSQL_ATTR_SSL_CA) => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
'mariadb' => [
'driver' => 'mariadb',
'url' => env('DB_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'laravel'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => env('DB_CHARSET', 'utf8mb4'),
'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'),
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
(PHP_VERSION_ID >= 80500 ? Mysql::ATTR_SSL_CA : PDO::MYSQL_ATTR_SSL_CA) => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
'pgsql' => [
'driver' => 'pgsql',
'url' => env('DB_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'laravel'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => env('DB_CHARSET', 'utf8'),
'prefix' => '',
'prefix_indexes' => true,
'search_path' => 'public',
'sslmode' => env('DB_SSLMODE', 'prefer'),
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'url' => env('DB_URL'),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'laravel'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => env('DB_CHARSET', 'utf8'),
'prefix' => '',
'prefix_indexes' => true,
// 'encrypt' => env('DB_ENCRYPT', 'yes'),
// 'trust_server_certificate' => env('DB_TRUST_SERVER_CERTIFICATE', 'false'),
],
],
/*
|--------------------------------------------------------------------------
| Migration Repository Table
|--------------------------------------------------------------------------
|
| This table keeps track of all the migrations that have already run for
| your application. Using this information, we can determine which of
| the migrations on disk haven't actually been run on the database.
|
*/
'migrations' => [
'table' => 'migrations',
'update_date_on_publish' => true,
],
/*
|--------------------------------------------------------------------------
| Redis Databases
|--------------------------------------------------------------------------
|
| Redis is an open source, fast, and advanced key-value store that also
| provides a richer body of commands than a typical key-value system
| such as Memcached. You may define your connection settings here.
|
*/
'redis' => [
'client' => env('REDIS_CLIENT', 'phpredis'),
'options' => [
'cluster' => env('REDIS_CLUSTER', 'redis'),
'prefix' => env('REDIS_PREFIX', Str::slug((string) env('APP_NAME', 'laravel')).'-database-'),
'persistent' => env('REDIS_PERSISTENT', false),
],
'default' => [
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'username' => env('REDIS_USERNAME'),
'password' => env('REDIS_PASSWORD'),
'port' => env('REDIS_PORT', '6379'),
'database' => env('REDIS_DB', '0'),
'max_retries' => env('REDIS_MAX_RETRIES', 3),
'backoff_algorithm' => env('REDIS_BACKOFF_ALGORITHM', 'decorrelated_jitter'),
'backoff_base' => env('REDIS_BACKOFF_BASE', 100),
'backoff_cap' => env('REDIS_BACKOFF_CAP', 1000),
],
'cache' => [
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'username' => env('REDIS_USERNAME'),
'password' => env('REDIS_PASSWORD'),
'port' => env('REDIS_PORT', '6379'),
'database' => env('REDIS_CACHE_DB', '1'),
'max_retries' => env('REDIS_MAX_RETRIES', 3),
'backoff_algorithm' => env('REDIS_BACKOFF_ALGORITHM', 'decorrelated_jitter'),
'backoff_base' => env('REDIS_BACKOFF_BASE', 100),
'backoff_cap' => env('REDIS_BACKOFF_CAP', 1000),
],
],
];
+80
View File
@@ -0,0 +1,80 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Filesystem Disk
|--------------------------------------------------------------------------
|
| Here you may specify the default filesystem disk that should be used
| by the framework. The "local" disk, as well as a variety of cloud
| based disks are available to your application for file storage.
|
*/
'default' => env('FILESYSTEM_DISK', 'local'),
/*
|--------------------------------------------------------------------------
| Filesystem Disks
|--------------------------------------------------------------------------
|
| Below you may configure as many filesystem disks as necessary, and you
| may even configure multiple disks for the same driver. Examples for
| most supported storage drivers are configured here for reference.
|
| Supported drivers: "local", "ftp", "sftp", "s3"
|
*/
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app/private'),
'serve' => true,
'throw' => false,
'report' => false,
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => rtrim(env('APP_URL', 'http://localhost'), '/').'/storage',
'visibility' => 'public',
'throw' => false,
'report' => false,
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
'endpoint' => env('AWS_ENDPOINT'),
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
'throw' => false,
'report' => false,
],
],
/*
|--------------------------------------------------------------------------
| Symbolic Links
|--------------------------------------------------------------------------
|
| Here you may configure the symbolic links that will be created when the
| `storage:link` Artisan command is executed. The array keys should be
| the locations of the links and the values should be their targets.
|
*/
'links' => [
public_path('storage') => storage_path('app/public'),
],
];
+132
View File
@@ -0,0 +1,132 @@
<?php
use Monolog\Handler\NullHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\SyslogUdpHandler;
use Monolog\Processor\PsrLogMessageProcessor;
return [
/*
|--------------------------------------------------------------------------
| Default Log Channel
|--------------------------------------------------------------------------
|
| This option defines the default log channel that is utilized to write
| messages to your logs. The value provided here should match one of
| the channels present in the list of "channels" configured below.
|
*/
'default' => env('LOG_CHANNEL', 'stack'),
/*
|--------------------------------------------------------------------------
| Deprecations Log Channel
|--------------------------------------------------------------------------
|
| This option controls the log channel that should be used to log warnings
| regarding deprecated PHP and library features. This allows you to get
| your application ready for upcoming major versions of dependencies.
|
*/
'deprecations' => [
'channel' => env('LOG_DEPRECATIONS_CHANNEL', 'null'),
'trace' => env('LOG_DEPRECATIONS_TRACE', false),
],
/*
|--------------------------------------------------------------------------
| Log Channels
|--------------------------------------------------------------------------
|
| Here you may configure the log channels for your application. Laravel
| utilizes the Monolog PHP logging library, which includes a variety
| of powerful log handlers and formatters that you're free to use.
|
| Available drivers: "single", "daily", "slack", "syslog",
| "errorlog", "monolog", "custom", "stack"
|
*/
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => explode(',', (string) env('LOG_STACK', 'single')),
'ignore_exceptions' => false,
],
'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => env('LOG_LEVEL', 'debug'),
'replace_placeholders' => true,
],
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/laravel.log'),
'level' => env('LOG_LEVEL', 'debug'),
'days' => env('LOG_DAILY_DAYS', 14),
'replace_placeholders' => true,
],
'slack' => [
'driver' => 'slack',
'url' => env('LOG_SLACK_WEBHOOK_URL'),
'username' => env('LOG_SLACK_USERNAME', 'Laravel Log'),
'emoji' => env('LOG_SLACK_EMOJI', ':boom:'),
'level' => env('LOG_LEVEL', 'critical'),
'replace_placeholders' => true,
],
'papertrail' => [
'driver' => 'monolog',
'level' => env('LOG_LEVEL', 'debug'),
'handler' => env('LOG_PAPERTRAIL_HANDLER', SyslogUdpHandler::class),
'handler_with' => [
'host' => env('PAPERTRAIL_URL'),
'port' => env('PAPERTRAIL_PORT'),
'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'),
],
'processors' => [PsrLogMessageProcessor::class],
],
'stderr' => [
'driver' => 'monolog',
'level' => env('LOG_LEVEL', 'debug'),
'handler' => StreamHandler::class,
'handler_with' => [
'stream' => 'php://stderr',
],
'formatter' => env('LOG_STDERR_FORMATTER'),
'processors' => [PsrLogMessageProcessor::class],
],
'syslog' => [
'driver' => 'syslog',
'level' => env('LOG_LEVEL', 'debug'),
'facility' => env('LOG_SYSLOG_FACILITY', LOG_USER),
'replace_placeholders' => true,
],
'errorlog' => [
'driver' => 'errorlog',
'level' => env('LOG_LEVEL', 'debug'),
'replace_placeholders' => true,
],
'null' => [
'driver' => 'monolog',
'handler' => NullHandler::class,
],
'emergency' => [
'path' => storage_path('logs/laravel.log'),
],
],
];
+118
View File
@@ -0,0 +1,118 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Mailer
|--------------------------------------------------------------------------
|
| This option controls the default mailer that is used to send all email
| messages unless another mailer is explicitly specified when sending
| the message. All additional mailers can be configured within the
| "mailers" array. Examples of each type of mailer are provided.
|
*/
'default' => env('MAIL_MAILER', 'log'),
/*
|--------------------------------------------------------------------------
| Mailer Configurations
|--------------------------------------------------------------------------
|
| Here you may configure all of the mailers used by your application plus
| their respective settings. Several examples have been configured for
| you and you are free to add your own as your application requires.
|
| Laravel supports a variety of mail "transport" drivers that can be used
| when delivering an email. You may specify which one you're using for
| your mailers below. You may also add additional mailers if needed.
|
| Supported: "smtp", "sendmail", "mailgun", "ses", "ses-v2",
| "postmark", "resend", "log", "array",
| "failover", "roundrobin"
|
*/
'mailers' => [
'smtp' => [
'transport' => 'smtp',
'scheme' => env('MAIL_SCHEME'),
'url' => env('MAIL_URL'),
'host' => env('MAIL_HOST', '127.0.0.1'),
'port' => env('MAIL_PORT', 2525),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'local_domain' => env('MAIL_EHLO_DOMAIN', parse_url((string) env('APP_URL', 'http://localhost'), PHP_URL_HOST)),
],
'ses' => [
'transport' => 'ses',
],
'postmark' => [
'transport' => 'postmark',
// 'message_stream_id' => env('POSTMARK_MESSAGE_STREAM_ID'),
// 'client' => [
// 'timeout' => 5,
// ],
],
'resend' => [
'transport' => 'resend',
],
'sendmail' => [
'transport' => 'sendmail',
'path' => env('MAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -bs -i'),
],
'log' => [
'transport' => 'log',
'channel' => env('MAIL_LOG_CHANNEL'),
],
'array' => [
'transport' => 'array',
],
'failover' => [
'transport' => 'failover',
'mailers' => [
'smtp',
'log',
],
'retry_after' => 60,
],
'roundrobin' => [
'transport' => 'roundrobin',
'mailers' => [
'ses',
'postmark',
],
'retry_after' => 60,
],
],
/*
|--------------------------------------------------------------------------
| Global "From" Address
|--------------------------------------------------------------------------
|
| You may wish for all emails sent by your application to be sent from
| the same address. Here you may specify a name and address that is
| used globally for all emails that are sent by your application.
|
*/
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
'name' => env('MAIL_FROM_NAME', env('APP_NAME', 'Laravel')),
],
];
+129
View File
@@ -0,0 +1,129 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Queue Connection Name
|--------------------------------------------------------------------------
|
| Laravel's queue supports a variety of backends via a single, unified
| API, giving you convenient access to each backend using identical
| syntax for each. The default queue connection is defined below.
|
*/
'default' => env('QUEUE_CONNECTION', 'database'),
/*
|--------------------------------------------------------------------------
| Queue Connections
|--------------------------------------------------------------------------
|
| Here you may configure the connection options for every queue backend
| used by your application. An example configuration is provided for
| each backend supported by Laravel. You're also free to add more.
|
| Drivers: "sync", "database", "beanstalkd", "sqs", "redis",
| "deferred", "background", "failover", "null"
|
*/
'connections' => [
'sync' => [
'driver' => 'sync',
],
'database' => [
'driver' => 'database',
'connection' => env('DB_QUEUE_CONNECTION'),
'table' => env('DB_QUEUE_TABLE', 'jobs'),
'queue' => env('DB_QUEUE', 'default'),
'retry_after' => (int) env('DB_QUEUE_RETRY_AFTER', 90),
'after_commit' => false,
],
'beanstalkd' => [
'driver' => 'beanstalkd',
'host' => env('BEANSTALKD_QUEUE_HOST', 'localhost'),
'queue' => env('BEANSTALKD_QUEUE', 'default'),
'retry_after' => (int) env('BEANSTALKD_QUEUE_RETRY_AFTER', 90),
'block_for' => 0,
'after_commit' => false,
],
'sqs' => [
'driver' => 'sqs',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'),
'queue' => env('SQS_QUEUE', 'default'),
'suffix' => env('SQS_SUFFIX'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
'after_commit' => false,
],
'redis' => [
'driver' => 'redis',
'connection' => env('REDIS_QUEUE_CONNECTION', 'default'),
'queue' => env('REDIS_QUEUE', 'default'),
'retry_after' => (int) env('REDIS_QUEUE_RETRY_AFTER', 90),
'block_for' => null,
'after_commit' => false,
],
'deferred' => [
'driver' => 'deferred',
],
'background' => [
'driver' => 'background',
],
'failover' => [
'driver' => 'failover',
'connections' => [
'database',
'deferred',
],
],
],
/*
|--------------------------------------------------------------------------
| Job Batching
|--------------------------------------------------------------------------
|
| The following options configure the database and table that store job
| batching information. These options can be updated to any database
| connection and table which has been defined by your application.
|
*/
'batching' => [
'database' => env('DB_CONNECTION', 'sqlite'),
'table' => 'job_batches',
],
/*
|--------------------------------------------------------------------------
| Failed Queue Jobs
|--------------------------------------------------------------------------
|
| These options configure the behavior of failed queue job logging so you
| can control how and where failed jobs are stored. Laravel ships with
| support for storing failed jobs in a simple file or in a database.
|
| Supported drivers: "database-uuids", "dynamodb", "file", "null"
|
*/
'failed' => [
'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'),
'database' => env('DB_CONNECTION', 'sqlite'),
'table' => 'failed_jobs',
],
];
+38
View File
@@ -0,0 +1,38 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Third Party Services
|--------------------------------------------------------------------------
|
| This file is for storing the credentials for third party services such
| as Mailgun, Postmark, AWS and more. This file provides the de facto
| location for this type of information, allowing packages to have
| a conventional file to locate the various service credentials.
|
*/
'postmark' => [
'key' => env('POSTMARK_API_KEY'),
],
'resend' => [
'key' => env('RESEND_API_KEY'),
],
'ses' => [
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
],
'slack' => [
'notifications' => [
'bot_user_oauth_token' => env('SLACK_BOT_USER_OAUTH_TOKEN'),
'channel' => env('SLACK_BOT_USER_DEFAULT_CHANNEL'),
],
],
];
+217
View File
@@ -0,0 +1,217 @@
<?php
use Illuminate\Support\Str;
return [
/*
|--------------------------------------------------------------------------
| Default Session Driver
|--------------------------------------------------------------------------
|
| This option determines the default session driver that is utilized for
| incoming requests. Laravel supports a variety of storage options to
| persist session data. Database storage is a great default choice.
|
| Supported: "file", "cookie", "database", "memcached",
| "redis", "dynamodb", "array"
|
*/
'driver' => env('SESSION_DRIVER', 'database'),
/*
|--------------------------------------------------------------------------
| Session Lifetime
|--------------------------------------------------------------------------
|
| Here you may specify the number of minutes that you wish the session
| to be allowed to remain idle before it expires. If you want them
| to expire immediately when the browser is closed then you may
| indicate that via the expire_on_close configuration option.
|
*/
'lifetime' => (int) env('SESSION_LIFETIME', 120),
'expire_on_close' => env('SESSION_EXPIRE_ON_CLOSE', false),
/*
|--------------------------------------------------------------------------
| Session Encryption
|--------------------------------------------------------------------------
|
| This option allows you to easily specify that all of your session data
| should be encrypted before it's stored. All encryption is performed
| automatically by Laravel and you may use the session like normal.
|
*/
'encrypt' => env('SESSION_ENCRYPT', false),
/*
|--------------------------------------------------------------------------
| Session File Location
|--------------------------------------------------------------------------
|
| When utilizing the "file" session driver, the session files are placed
| on disk. The default storage location is defined here; however, you
| are free to provide another location where they should be stored.
|
*/
'files' => storage_path('framework/sessions'),
/*
|--------------------------------------------------------------------------
| Session Database Connection
|--------------------------------------------------------------------------
|
| When using the "database" or "redis" session drivers, you may specify a
| connection that should be used to manage these sessions. This should
| correspond to a connection in your database configuration options.
|
*/
'connection' => env('SESSION_CONNECTION'),
/*
|--------------------------------------------------------------------------
| Session Database Table
|--------------------------------------------------------------------------
|
| When using the "database" session driver, you may specify the table to
| be used to store sessions. Of course, a sensible default is defined
| for you; however, you're welcome to change this to another table.
|
*/
'table' => env('SESSION_TABLE', 'sessions'),
/*
|--------------------------------------------------------------------------
| Session Cache Store
|--------------------------------------------------------------------------
|
| When using one of the framework's cache driven session backends, you may
| define the cache store which should be used to store the session data
| between requests. This must match one of your defined cache stores.
|
| Affects: "dynamodb", "memcached", "redis"
|
*/
'store' => env('SESSION_STORE'),
/*
|--------------------------------------------------------------------------
| Session Sweeping Lottery
|--------------------------------------------------------------------------
|
| Some session drivers must manually sweep their storage location to get
| rid of old sessions from storage. Here are the chances that it will
| happen on a given request. By default, the odds are 2 out of 100.
|
*/
'lottery' => [2, 100],
/*
|--------------------------------------------------------------------------
| Session Cookie Name
|--------------------------------------------------------------------------
|
| Here you may change the name of the session cookie that is created by
| the framework. Typically, you should not need to change this value
| since doing so does not grant a meaningful security improvement.
|
*/
'cookie' => env(
'SESSION_COOKIE',
Str::slug((string) env('APP_NAME', 'laravel')).'-session'
),
/*
|--------------------------------------------------------------------------
| Session Cookie Path
|--------------------------------------------------------------------------
|
| The session cookie path determines the path for which the cookie will
| be regarded as available. Typically, this will be the root path of
| your application, but you're free to change this when necessary.
|
*/
'path' => env('SESSION_PATH', '/'),
/*
|--------------------------------------------------------------------------
| Session Cookie Domain
|--------------------------------------------------------------------------
|
| This value determines the domain and subdomains the session cookie is
| available to. By default, the cookie will be available to the root
| domain without subdomains. Typically, this shouldn't be changed.
|
*/
'domain' => env('SESSION_DOMAIN'),
/*
|--------------------------------------------------------------------------
| HTTPS Only Cookies
|--------------------------------------------------------------------------
|
| By setting this option to true, session cookies will only be sent back
| to the server if the browser has a HTTPS connection. This will keep
| the cookie from being sent to you when it can't be done securely.
|
*/
'secure' => env('SESSION_SECURE_COOKIE'),
/*
|--------------------------------------------------------------------------
| HTTP Access Only
|--------------------------------------------------------------------------
|
| Setting this value to true will prevent JavaScript from accessing the
| value of the cookie and the cookie will only be accessible through
| the HTTP protocol. It's unlikely you should disable this option.
|
*/
'http_only' => env('SESSION_HTTP_ONLY', true),
/*
|--------------------------------------------------------------------------
| Same-Site Cookies
|--------------------------------------------------------------------------
|
| This option determines how your cookies behave when cross-site requests
| take place, and can be used to mitigate CSRF attacks. By default, we
| will set this value to "lax" to permit secure cross-site requests.
|
| See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#samesitesamesite-value
|
| Supported: "lax", "strict", "none", null
|
*/
'same_site' => env('SESSION_SAME_SITE', 'lax'),
/*
|--------------------------------------------------------------------------
| Partitioned Cookies
|--------------------------------------------------------------------------
|
| Setting this value to true will tie the cookie to the top-level site for
| a cross-site context. Partitioned cookies are accepted by the browser
| when flagged "secure" and the Same-Site attribute is set to "none".
|
*/
'partitioned' => env('SESSION_PARTITIONED_COOKIE', false),
];
+1
View File
@@ -0,0 +1 @@
*.sqlite*
@@ -0,0 +1,45 @@
<?php
namespace Database\Factories;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
/**
* @extends Factory<User>
*/
class UserFactory extends Factory
{
/**
* The current password being used by the factory.
*/
protected static ?string $password;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => static::$password ??= Hash::make('password'),
'remember_token' => Str::random(10),
];
}
/**
* Indicate that the model's email address should be unverified.
*/
public function unverified(): static
{
return $this->state(fn (array $attributes) => [
'email_verified_at' => null,
]);
}
}
@@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('cache', function (Blueprint $table) {
$table->string('key')->primary();
$table->mediumText('value');
$table->integer('expiration')->index();
});
Schema::create('cache_locks', function (Blueprint $table) {
$table->string('key')->primary();
$table->string('owner');
$table->integer('expiration')->index();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('cache');
Schema::dropIfExists('cache_locks');
}
};
@@ -0,0 +1,59 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('jobs', function (Blueprint $table) {
$table->id();
$table->string('queue');
$table->longText('payload');
$table->unsignedTinyInteger('attempts');
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
$table->index(['queue', 'reserved_at', 'available_at']);
});
Schema::create('job_batches', function (Blueprint $table) {
$table->string('id')->primary();
$table->string('name');
$table->integer('total_jobs');
$table->integer('pending_jobs');
$table->integer('failed_jobs');
$table->longText('failed_job_ids');
$table->mediumText('options')->nullable();
$table->integer('cancelled_at')->nullable();
$table->integer('created_at');
$table->integer('finished_at')->nullable();
});
Schema::create('failed_jobs', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->text('connection');
$table->text('queue');
$table->longText('payload');
$table->longText('exception');
$table->timestamp('failed_at')->useCurrent();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('jobs');
Schema::dropIfExists('job_batches');
Schema::dropIfExists('failed_jobs');
}
};
@@ -0,0 +1,24 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('regions', function (Blueprint $table) {
$table->id();
$table->string('name', 50)->comment('区域名称');
$table->integer('sort')->default(0);
$table->tinyInteger('status')->default(1)->comment('1启用 0停用');
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('regions');
}
};
@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('stores', function (Blueprint $table) {
$table->id();
$table->foreignId('region_id')->constrained()->comment('所属区域');
$table->string('name', 100)->comment('门店名称');
$table->string('code', 20)->unique()->nullable()->comment('门店编码');
$table->string('address', 255)->nullable();
$table->string('phone', 20)->nullable();
$table->string('logo', 255)->nullable();
$table->tinyInteger('status')->default(1)->comment('1启用 0停用');
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('stores');
}
};
@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('departments', function (Blueprint $table) {
$table->id();
$table->foreignId('store_id')->constrained()->comment('所属门店');
$table->unsignedBigInteger('parent_id')->default(0)->comment('上级部门');
$table->string('name', 50)->comment('部门名称');
$table->integer('sort')->default(0);
$table->tinyInteger('status')->default(1)->comment('1启用 0停用');
$table->timestamps();
$table->index('store_id');
});
}
public function down(): void
{
Schema::dropIfExists('departments');
}
};
@@ -0,0 +1,24 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('positions', function (Blueprint $table) {
$table->id();
$table->foreignId('store_id')->constrained()->comment('所属门店');
$table->string('name', 50)->comment('职务名称');
$table->integer('sort')->default(0);
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('positions');
}
};
@@ -0,0 +1,37 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->foreignId('store_id')->constrained()->comment('所属门店');
$table->unsignedBigInteger('department_id')->nullable();
$table->unsignedBigInteger('position_id')->nullable();
$table->string('username', 50)->unique()->comment('登录名');
$table->string('password', 255);
$table->string('name', 50)->comment('真实姓名');
$table->string('phone', 20)->nullable();
$table->string('email', 100)->nullable();
$table->string('avatar', 255)->nullable();
$table->tinyInteger('status')->default(1)->comment('0待审核 1正常 2禁用');
$table->tinyInteger('is_super')->default(0)->comment('1超级管理员');
$table->timestamp('last_login_at')->nullable();
$table->timestamps();
$table->softDeletes();
$table->index('store_id');
$table->index('phone');
});
}
public function down(): void
{
Schema::dropIfExists('users');
}
};
@@ -0,0 +1,26 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('roles', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('store_id')->nullable()->comment('NULL=全局角色');
$table->string('name', 50)->comment('角色名称');
$table->string('code', 50)->unique()->comment('角色编码');
$table->string('description', 255)->nullable();
$table->tinyInteger('is_system')->default(0)->comment('1系统内置不可删');
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('roles');
}
};
@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('permissions', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('parent_id')->default(0)->comment('上级权限');
$table->string('name', 50)->comment('权限名称');
$table->string('code', 100)->unique()->comment('权限标识 如 crm.lead.create');
$table->string('module', 50)->nullable()->comment('所属模块');
$table->tinyInteger('type')->default(1)->comment('1菜单 2按钮 3接口');
$table->string('description', 255)->nullable();
$table->integer('sort')->default(0);
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('permissions');
}
};
@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('menus', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('parent_id')->default(0)->comment('上级菜单');
$table->string('name', 50)->comment('菜单名称');
$table->string('path', 255)->nullable()->comment('路由路径');
$table->string('component', 255)->nullable()->comment('组件路径');
$table->string('icon', 50)->nullable()->comment('图标');
$table->string('permission_code', 100)->nullable()->comment('关联权限标识');
$table->tinyInteger('type')->default(1)->comment('1目录 2菜单 3按钮');
$table->tinyInteger('visible')->default(1)->comment('1显示 0隐藏');
$table->integer('sort')->default(0);
$table->tinyInteger('status')->default(1)->comment('1启用 0停用');
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('menus');
}
};
@@ -0,0 +1,22 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('role_user', function (Blueprint $table) {
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->foreignId('role_id')->constrained()->onDelete('cascade');
$table->primary(['user_id', 'role_id']);
});
}
public function down(): void
{
Schema::dropIfExists('role_user');
}
};
@@ -0,0 +1,22 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('role_permission', function (Blueprint $table) {
$table->foreignId('role_id')->constrained()->onDelete('cascade');
$table->foreignId('permission_id')->constrained()->onDelete('cascade');
$table->primary(['role_id', 'permission_id']);
});
}
public function down(): void
{
Schema::dropIfExists('role_permission');
}
};
@@ -0,0 +1,37 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('operation_logs', function (Blueprint $table) {
$table->id();
$table->foreignId('store_id')->constrained();
$table->unsignedBigInteger('user_id');
$table->string('user_name', 50);
$table->string('module', 50)->comment('操作模块');
$table->string('action', 50)->comment('操作类型 create/update/delete');
$table->string('target', 100)->nullable()->comment('操作对象');
$table->unsignedBigInteger('target_id')->nullable();
$table->string('ip', 45)->nullable();
$table->string('method', 10)->nullable()->comment('HTTP方法');
$table->string('url', 500)->nullable()->comment('请求URL');
$table->json('before')->nullable()->comment('变更前数据');
$table->json('after')->nullable()->comment('变更后数据');
$table->timestamp('created_at')->nullable();
$table->index(['store_id', 'created_at']);
$table->index('user_id');
$table->index('module');
});
}
public function down(): void
{
Schema::dropIfExists('operation_logs');
}
};
@@ -0,0 +1,38 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('dictionaries', function (Blueprint $table) {
$table->id();
$table->string('name', 50)->comment('字典名称');
$table->string('code', 50)->unique()->comment('字典编码');
$table->string('description', 255)->nullable();
$table->tinyInteger('is_system')->default(0)->comment('系统内置不可删');
$table->timestamps();
});
Schema::create('dictionary_items', function (Blueprint $table) {
$table->id();
$table->foreignId('dictionary_id')->constrained()->onDelete('cascade');
$table->string('label', 100)->comment('显示文本');
$table->string('value', 100)->comment('值');
$table->integer('sort')->default(0);
$table->tinyInteger('status')->default(1)->comment('1启用 0停用');
$table->timestamps();
$table->index('dictionary_id');
});
}
public function down(): void
{
Schema::dropIfExists('dictionary_items');
Schema::dropIfExists('dictionaries');
}
};
@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('system_configs', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('store_id')->nullable()->comment('NULL=全局配置');
$table->string('group', 50)->default('general')->comment('配置分组');
$table->string('key', 100)->comment('配置键');
$table->text('value')->nullable()->comment('配置值');
$table->string('description', 255)->nullable();
$table->timestamps();
$table->unique(['store_id', 'key']);
});
}
public function down(): void
{
Schema::dropIfExists('system_configs');
}
};
@@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('personal_access_tokens', function (Blueprint $table) {
$table->id();
$table->morphs('tokenable');
$table->text('name');
$table->string('token', 64)->unique();
$table->text('abilities')->nullable();
$table->timestamp('last_used_at')->nullable();
$table->timestamp('expires_at')->nullable()->index();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('personal_access_tokens');
}
};
@@ -0,0 +1,25 @@
<?php
namespace Database\Seeders;
use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
use WithoutModelEvents;
/**
* Seed the application's database.
*/
public function run(): void
{
// User::factory(10)->create();
User::factory()->create([
'name' => 'Test User',
'email' => 'test@example.com',
]);
}
}
+266
View File
@@ -0,0 +1,266 @@
<?php
namespace Database\Seeders;
use App\Models\Department;
use App\Models\Menu;
use App\Models\Permission;
use App\Models\Region;
use App\Models\Role;
use App\Models\Store;
use App\Models\User;
use Illuminate\Database\Seeder;
class InitSeeder extends Seeder
{
public function run(): void
{
// 1. 创建默认区域
$region = Region::create(['name' => '默认区域', 'sort' => 0, 'status' => 1]);
// 2. 创建默认门店
$store = Store::create([
'region_id' => $region->id,
'name' => '宫中有喜总店',
'code' => 'HQ001',
'status' => 1,
]);
// 3. 创建默认部门
Department::create(['store_id' => $store->id, 'name' => '管理层', 'sort' => 0]);
// 4. 创建超级管理员
$admin = User::create([
'store_id' => $store->id,
'username' => 'admin',
'password' => 'admin123',
'name' => '超级管理员',
'status' => 1,
'is_super' => 1,
]);
// 5. 创建默认角色
$superRole = Role::create([
'name' => '超级管理员',
'code' => 'super_admin',
'description' => '系统最高权限',
'is_system' => 1,
]);
$storeAdmin = Role::create([
'store_id' => $store->id,
'name' => '门店管理员',
'code' => 'store_admin',
'description' => '门店最高权限',
'is_system' => 1,
]);
$admin->roles()->attach($superRole->id);
// 6. 创建权限
$this->createPermissions();
// 7. 创建菜单
$this->createMenus();
// 8. 门店管理员分配所有权限
$allPermissions = Permission::pluck('id')->toArray();
$storeAdmin->permissions()->sync($allPermissions);
}
private function createPermissions(): void
{
$modules = [
['name' => 'CRM管理', 'code' => 'crm', 'children' => [
['name' => '线索管理', 'code' => 'crm.lead', 'children' => [
['name' => '查看', 'code' => 'crm.lead.view', 'type' => 2],
['name' => '新建', 'code' => 'crm.lead.create', 'type' => 2],
['name' => '编辑', 'code' => 'crm.lead.update', 'type' => 2],
['name' => '删除', 'code' => 'crm.lead.delete', 'type' => 2],
]],
['name' => '客户管理', 'code' => 'crm.customer', 'children' => [
['name' => '查看', 'code' => 'crm.customer.view', 'type' => 2],
['name' => '新建', 'code' => 'crm.customer.create', 'type' => 2],
['name' => '编辑', 'code' => 'crm.customer.update', 'type' => 2],
['name' => '删除', 'code' => 'crm.customer.delete', 'type' => 2],
]],
['name' => '合同管理', 'code' => 'crm.contract', 'children' => [
['name' => '查看', 'code' => 'crm.contract.view', 'type' => 2],
['name' => '新建', 'code' => 'crm.contract.create', 'type' => 2],
['name' => '审批', 'code' => 'crm.contract.approve', 'type' => 2],
]],
]],
['name' => '房务管理', 'code' => 'room', 'children' => [
['name' => '房间管理', 'code' => 'room.room', 'children' => [
['name' => '查看', 'code' => 'room.room.view', 'type' => 2],
['name' => '编辑', 'code' => 'room.room.update', 'type' => 2],
]],
['name' => '预定管理', 'code' => 'room.reservation', 'children' => [
['name' => '查看', 'code' => 'room.reservation.view', 'type' => 2],
['name' => '新建', 'code' => 'room.reservation.create', 'type' => 2],
['name' => '操作', 'code' => 'room.reservation.operate', 'type' => 2],
]],
]],
['name' => '护理管理', 'code' => 'care', 'children' => [
['name' => '护理档案', 'code' => 'care.profile', 'children' => [
['name' => '查看', 'code' => 'care.profile.view', 'type' => 2],
['name' => '编辑', 'code' => 'care.profile.update', 'type' => 2],
]],
['name' => '护理记录', 'code' => 'care.record', 'children' => [
['name' => '查看', 'code' => 'care.record.view', 'type' => 2],
['name' => '新建', 'code' => 'care.record.create', 'type' => 2],
]],
]],
['name' => '月子餐管理', 'code' => 'meal', 'children' => [
['name' => '菜品管理', 'code' => 'meal.dish', 'children' => [
['name' => '查看', 'code' => 'meal.dish.view', 'type' => 2],
['name' => '编辑', 'code' => 'meal.dish.update', 'type' => 2],
]],
['name' => '排餐管理', 'code' => 'meal.plan', 'children' => [
['name' => '查看', 'code' => 'meal.plan.view', 'type' => 2],
['name' => '编辑', 'code' => 'meal.plan.update', 'type' => 2],
]],
]],
['name' => '服务产康', 'code' => 'service', 'children' => [
['name' => '服务项目', 'code' => 'service.item', 'children' => [
['name' => '查看', 'code' => 'service.item.view', 'type' => 2],
['name' => '编辑', 'code' => 'service.item.update', 'type' => 2],
]],
]],
['name' => '月嫂管理', 'code' => 'nanny', 'children' => [
['name' => '月嫂档案', 'code' => 'nanny.profile', 'children' => [
['name' => '查看', 'code' => 'nanny.profile.view', 'type' => 2],
['name' => '编辑', 'code' => 'nanny.profile.update', 'type' => 2],
]],
]],
['name' => '进销存', 'code' => 'stock', 'children' => [
['name' => '库存管理', 'code' => 'stock.inventory', 'children' => [
['name' => '查看', 'code' => 'stock.inventory.view', 'type' => 2],
['name' => '操作', 'code' => 'stock.inventory.operate', 'type' => 2],
]],
]],
['name' => '财务管理', 'code' => 'finance', 'children' => [
['name' => '收支管理', 'code' => 'finance.record', 'children' => [
['name' => '查看', 'code' => 'finance.record.view', 'type' => 2],
['name' => '新建', 'code' => 'finance.record.create', 'type' => 2],
['name' => '审核', 'code' => 'finance.record.approve', 'type' => 2],
]],
]],
['name' => '人事薪资', 'code' => 'hr', 'children' => [
['name' => '员工管理', 'code' => 'hr.employee', 'children' => [
['name' => '查看', 'code' => 'hr.employee.view', 'type' => 2],
['name' => '编辑', 'code' => 'hr.employee.update', 'type' => 2],
]],
]],
['name' => '办公协同', 'code' => 'office', 'children' => [
['name' => '审批管理', 'code' => 'office.approval', 'children' => [
['name' => '查看', 'code' => 'office.approval.view', 'type' => 2],
['name' => '审批', 'code' => 'office.approval.operate', 'type' => 2],
]],
]],
['name' => '统计报表', 'code' => 'report', 'children' => [
['name' => '查看报表', 'code' => 'report.view', 'type' => 2],
['name' => '导出报表', 'code' => 'report.export', 'type' => 2],
]],
['name' => '知识库', 'code' => 'kb', 'children' => [
['name' => '文章管理', 'code' => 'kb.article', 'children' => [
['name' => '查看', 'code' => 'kb.article.view', 'type' => 2],
['name' => '编辑', 'code' => 'kb.article.update', 'type' => 2],
]],
]],
['name' => '系统设置', 'code' => 'system', 'children' => [
['name' => '门店管理', 'code' => 'system.store', 'type' => 2],
['name' => '用户管理', 'code' => 'system.user', 'type' => 2],
['name' => '角色管理', 'code' => 'system.role', 'type' => 2],
['name' => '菜单管理', 'code' => 'system.menu', 'type' => 2],
['name' => '字典管理', 'code' => 'system.dict', 'type' => 2],
['name' => '操作日志', 'code' => 'system.log', 'type' => 2],
]],
];
$this->insertPermissions($modules);
}
private function insertPermissions(array $items, int $parentId = 0, int &$sort = 0): void
{
foreach ($items as $item) {
$children = $item['children'] ?? [];
unset($item['children']);
$item['parent_id'] = $parentId;
$item['type'] = $item['type'] ?? 1;
$item['module'] = explode('.', $item['code'])[0];
$item['sort'] = $sort++;
$permission = Permission::create($item);
if ($children) {
$this->insertPermissions($children, $permission->id, $sort);
}
}
}
private function createMenus(): void
{
$menus = [
['name' => '首页', 'path' => '/dashboard', 'component' => 'dashboard/index', 'icon' => 'HomeFilled', 'sort' => 0],
['name' => 'CRM管理', 'icon' => 'User', 'sort' => 1, 'permission_code' => 'crm', 'children' => [
['name' => '线索管理', 'path' => '/crm/leads', 'component' => 'crm/leads/index', 'permission_code' => 'crm.lead'],
['name' => '客户管理', 'path' => '/crm/customers', 'component' => 'crm/customers/index', 'permission_code' => 'crm.customer'],
['name' => '合同管理', 'path' => '/crm/contracts', 'component' => 'crm/contracts/index', 'permission_code' => 'crm.contract'],
]],
['name' => '房务管理', 'icon' => 'House', 'sort' => 2, 'permission_code' => 'room', 'children' => [
['name' => '房态看板', 'path' => '/room/board', 'component' => 'room/board/index', 'permission_code' => 'room.room'],
['name' => '预定管理', 'path' => '/room/reservations', 'component' => 'room/reservations/index', 'permission_code' => 'room.reservation'],
]],
['name' => '护理管理', 'icon' => 'FirstAidKit', 'sort' => 3, 'permission_code' => 'care', 'children' => [
['name' => '护理档案', 'path' => '/care/profiles', 'component' => 'care/profiles/index', 'permission_code' => 'care.profile'],
['name' => '护理记录', 'path' => '/care/records', 'component' => 'care/records/index', 'permission_code' => 'care.record'],
]],
['name' => '月子餐', 'icon' => 'Bowl', 'sort' => 4, 'permission_code' => 'meal', 'children' => [
['name' => '菜品管理', 'path' => '/meal/dishes', 'component' => 'meal/dishes/index', 'permission_code' => 'meal.dish'],
['name' => '排餐管理', 'path' => '/meal/plans', 'component' => 'meal/plans/index', 'permission_code' => 'meal.plan'],
]],
['name' => '服务产康', 'icon' => 'Promotion', 'sort' => 5, 'permission_code' => 'service'],
['name' => '月嫂管理', 'icon' => 'Avatar', 'sort' => 6, 'permission_code' => 'nanny'],
['name' => '进销存', 'icon' => 'Box', 'sort' => 7, 'permission_code' => 'stock'],
['name' => '财务管理', 'icon' => 'Money', 'sort' => 8, 'permission_code' => 'finance'],
['name' => '人事薪资', 'icon' => 'Stamp', 'sort' => 9, 'permission_code' => 'hr'],
['name' => '办公协同', 'icon' => 'ChatDotRound', 'sort' => 10, 'permission_code' => 'office'],
['name' => '统计报表', 'icon' => 'DataAnalysis', 'sort' => 11, 'permission_code' => 'report'],
['name' => '知识库', 'icon' => 'Reading', 'sort' => 12, 'permission_code' => 'kb'],
['name' => '系统设置', 'icon' => 'Setting', 'sort' => 99, 'permission_code' => 'system', 'children' => [
['name' => '门店管理', 'path' => '/system/stores', 'component' => 'system/stores/index', 'permission_code' => 'system.store'],
['name' => '部门管理', 'path' => '/system/departments', 'component' => 'system/departments/index', 'permission_code' => 'system.store'],
['name' => '职务管理', 'path' => '/system/positions', 'component' => 'system/positions/index', 'permission_code' => 'system.store'],
['name' => '用户管理', 'path' => '/system/users', 'component' => 'system/users/index', 'permission_code' => 'system.user'],
['name' => '角色管理', 'path' => '/system/roles', 'component' => 'system/roles/index', 'permission_code' => 'system.role'],
['name' => '菜单管理', 'path' => '/system/menus', 'component' => 'system/menus/index', 'permission_code' => 'system.menu'],
['name' => '字典管理', 'path' => '/system/dictionaries', 'component' => 'system/dictionaries/index', 'permission_code' => 'system.dict'],
['name' => '操作日志', 'path' => '/system/logs', 'component' => 'system/logs/index', 'permission_code' => 'system.log'],
]],
];
$this->insertMenus($menus);
}
private function insertMenus(array $items, int $parentId = 0): void
{
foreach ($items as $index => $item) {
$children = $item['children'] ?? [];
unset($item['children']);
$item['parent_id'] = $parentId;
$item['type'] = isset($item['component']) ? 2 : 1; // 有 component = 菜单,否则目录
$item['sort'] = $item['sort'] ?? $index;
$item['visible'] = 1;
$item['status'] = 1;
$menu = Menu::create($item);
if ($children) {
$this->insertMenus($children, $menu->id);
}
}
}
}
+17
View File
@@ -0,0 +1,17 @@
{
"$schema": "https://www.schemastore.org/package.json",
"private": true,
"type": "module",
"scripts": {
"build": "vite build",
"dev": "vite"
},
"devDependencies": {
"@tailwindcss/vite": "^4.0.0",
"axios": "^1.11.0",
"concurrently": "^9.0.1",
"laravel-vite-plugin": "^2.0.0",
"tailwindcss": "^4.0.0",
"vite": "^7.0.7"
}
}
+36
View File
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory>tests/Feature</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>app</directory>
</include>
</source>
<php>
<env name="APP_ENV" value="testing"/>
<env name="APP_MAINTENANCE_DRIVER" value="file"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="BROADCAST_CONNECTION" value="null"/>
<env name="CACHE_STORE" value="array"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
<env name="DB_URL" value=""/>
<env name="MAIL_MAILER" value="array"/>
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="PULSE_ENABLED" value="false"/>
<env name="TELESCOPE_ENABLED" value="false"/>
<env name="NIGHTWATCH_ENABLED" value="false"/>
</php>
</phpunit>
+25
View File
@@ -0,0 +1,25 @@
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Handle X-XSRF-Token Header
RewriteCond %{HTTP:x-xsrf-token} .
RewriteRule .* - [E=HTTP_X_XSRF_TOKEN:%{HTTP:X-XSRF-Token}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
View File
+20
View File
@@ -0,0 +1,20 @@
<?php
use Illuminate\Foundation\Application;
use Illuminate\Http\Request;
define('LARAVEL_START', microtime(true));
// Determine if the application is in maintenance mode...
if (file_exists($maintenance = __DIR__.'/../storage/framework/maintenance.php')) {
require $maintenance;
}
// Register the Composer autoloader...
require __DIR__.'/../vendor/autoload.php';
// Bootstrap Laravel and handle the request...
/** @var Application $app */
$app = require_once __DIR__.'/../bootstrap/app.php';
$app->handleRequest(Request::capture());
+2
View File
@@ -0,0 +1,2 @@
User-agent: *
Disallow:
+11
View File
@@ -0,0 +1,11 @@
@import 'tailwindcss';
@source '../../vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php';
@source '../../storage/framework/views/*.php';
@source '../**/*.blade.php';
@source '../**/*.js';
@theme {
--font-sans: 'Instrument Sans', ui-sans-serif, system-ui, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji',
'Segoe UI Symbol', 'Noto Color Emoji';
}
+1
View File
@@ -0,0 +1 @@
import './bootstrap';
+4
View File
@@ -0,0 +1,4 @@
import axios from 'axios';
window.axios = axios;
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
File diff suppressed because one or more lines are too long
+69
View File
@@ -0,0 +1,69 @@
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Admin\AuthController;
use App\Http\Controllers\Admin\System\StoreController;
use App\Http\Controllers\Admin\System\DepartmentController;
use App\Http\Controllers\Admin\System\PositionController;
use App\Http\Controllers\Admin\System\UserController;
use App\Http\Controllers\Admin\System\RoleController;
use App\Http\Controllers\Admin\System\MenuController;
use App\Http\Controllers\Admin\System\PermissionController;
use App\Http\Controllers\Admin\System\DictionaryController;
use App\Http\Controllers\Admin\System\OperationLogController;
/*
|--------------------------------------------------------------------------
| 后台管理 API 路由
|--------------------------------------------------------------------------
| 前缀: /api/v1/ ( bootstrap/app.php 中配置)
*/
// ===== 公开路由(无需认证) =====
Route::post('/auth/login', [AuthController::class, 'login']);
// ===== 需要认证的路由 =====
Route::middleware(['auth:sanctum', 'store', 'oplog'])->group(function () {
// --- 认证 ---
Route::post('/auth/logout', [AuthController::class, 'logout']);
Route::get('/auth/me', [AuthController::class, 'me']);
// --- 系统设置模块 ---
Route::prefix('system')->group(function () {
// 门店管理
Route::apiResource('stores', StoreController::class);
// 部门管理
Route::apiResource('departments', DepartmentController::class)->except(['show']);
// 职务管理
Route::apiResource('positions', PositionController::class)->except(['show']);
// 用户管理
Route::apiResource('users', UserController::class);
Route::put('users/{user}/status', [UserController::class, 'updateStatus']);
Route::put('users/{user}/password', [UserController::class, 'resetPassword']);
// 角色管理
Route::apiResource('roles', RoleController::class);
Route::put('roles/{role}/permissions', [RoleController::class, 'assignPermissions']);
// 菜单管理
Route::apiResource('menus', MenuController::class)->except(['show']);
// 权限管理
Route::apiResource('permissions', PermissionController::class)->except(['show']);
// 数据字典
Route::apiResource('dictionaries', DictionaryController::class)->except(['show', 'update']);
Route::get('dictionaries/{dictionary}/items', [DictionaryController::class, 'items']);
Route::post('dictionaries/{dictionary}/items', [DictionaryController::class, 'storeItem']);
Route::put('dictionary-items/{item}', [DictionaryController::class, 'updateItem']);
Route::delete('dictionary-items/{item}', [DictionaryController::class, 'destroyItem']);
// 操作日志
Route::get('operation-logs', [OperationLogController::class, 'index']);
});
});
+8
View File
@@ -0,0 +1,8 @@
<?php
use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan;
Artisan::command('inspire', function () {
$this->comment(Inspiring::quote());
})->purpose('Display an inspiring quote');
+7
View File
@@ -0,0 +1,7 @@
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
return view('welcome');
});
+4
View File
@@ -0,0 +1,4 @@
*
!private/
!public/
!.gitignore
+2
View File
@@ -0,0 +1,2 @@
*
!.gitignore
+2
View File
@@ -0,0 +1,2 @@
*
!.gitignore
+9
View File
@@ -0,0 +1,9 @@
compiled.php
config.php
down
events.scanned.php
maintenance.php
routes.php
routes.scanned.php
schedule-*
services.json
@@ -0,0 +1,3 @@
*
!data/
!.gitignore
@@ -0,0 +1,2 @@
*
!.gitignore
@@ -0,0 +1,2 @@
*
!.gitignore
@@ -0,0 +1,2 @@
*
!.gitignore
@@ -0,0 +1,2 @@
*
!.gitignore
+2
View File
@@ -0,0 +1,2 @@
*
!.gitignore
+19
View File
@@ -0,0 +1,19 @@
<?php
namespace Tests\Feature;
// use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*/
public function test_the_application_returns_a_successful_response(): void
{
$response = $this->get('/');
$response->assertStatus(200);
}
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace Tests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
//
}

Some files were not shown because too many files have changed in this diff Show More