mirror of
https://devops.lemonos.cn/lawson/FendxPHP.git
synced 2026-06-15 23:12:49 +08:00
feat(database): 添加用户角色权限系统及相关监控功能
- 创建用户表(users)包含基本信息和认证字段 - 创建角色表(roles)用于权限控制 - 创建权限表(permissions)定义系统权限 - 创建用户角色关联表(user_roles)建立用户与角色关系 - 创建角色权限关联表(role_permissions)建立角色与权限关系 - 创建迁移记录表(migrations)追踪数据库变更 - 添加AdminController提供管理员面板功能 - 实现系统监控、配置管理、缓存清理等功能 - 添加AOP切面编程支持的各种通知类型 - 实现告警管理AlertManager支持多渠道告警 - 添加文档注解接口规范
This commit is contained in:
106
app/Dao/UserDao.php
Normal file
106
app/Dao/UserDao.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Dao;
|
||||
|
||||
use Fendx\Core\Annotation\Dao;
|
||||
use App\Entity\User;
|
||||
use Fendx\Db\ORM\Model;
|
||||
|
||||
#[Dao]
|
||||
class UserDao
|
||||
{
|
||||
public function findById(int $id): ?User
|
||||
{
|
||||
return User::find($id);
|
||||
}
|
||||
|
||||
public function findByEmail(string $email): ?User
|
||||
{
|
||||
return User::where('email', $email)->first();
|
||||
}
|
||||
|
||||
public function findByUsername(string $username): ?User
|
||||
{
|
||||
return User::where('username', $username)->first();
|
||||
}
|
||||
|
||||
public function findAllActive(): array
|
||||
{
|
||||
return User::where('status', 1)->orderBy('created_at', 'desc')->get();
|
||||
}
|
||||
|
||||
public function findPaginated(int $page = 1, int $pageSize = 10): array
|
||||
{
|
||||
$offset = ($page - 1) * $pageSize;
|
||||
|
||||
$users = User::orderBy('created_at', 'desc')
|
||||
->limit($pageSize)
|
||||
->offset($offset)
|
||||
->get();
|
||||
|
||||
$total = User::count();
|
||||
|
||||
return [
|
||||
'users' => $users,
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'pageSize' => $pageSize,
|
||||
'totalPages' => ceil($total / $pageSize)
|
||||
];
|
||||
}
|
||||
|
||||
public function create(array $data): User
|
||||
{
|
||||
$data['created_at'] = date('Y-m-d H:i:s');
|
||||
$data['updated_at'] = date('Y-m-d H:i:s');
|
||||
|
||||
return User::create($data);
|
||||
}
|
||||
|
||||
public function update(int $id, array $data): bool
|
||||
{
|
||||
$data['updated_at'] = date('Y-m-d H:i:s');
|
||||
|
||||
return User::find($id)?->update($data) ?? false;
|
||||
}
|
||||
|
||||
public function delete(int $id): bool
|
||||
{
|
||||
return User::find($id)?->delete() ?? false;
|
||||
}
|
||||
|
||||
public function count(): int
|
||||
{
|
||||
return User::count();
|
||||
}
|
||||
|
||||
public function countActive(): int
|
||||
{
|
||||
return User::where('status', 1)->count();
|
||||
}
|
||||
|
||||
public function search(string $keyword, int $page = 1, int $pageSize = 10): array
|
||||
{
|
||||
$offset = ($page - 1) * $pageSize;
|
||||
|
||||
$users = User::where('username', 'LIKE', "%{$keyword}%")
|
||||
->orWhere('email', 'LIKE', "%{$keyword}%")
|
||||
->orderBy('created_at', 'desc')
|
||||
->limit($pageSize)
|
||||
->offset($offset)
|
||||
->get();
|
||||
|
||||
$total = User::where('username', 'LIKE', "%{$keyword}%")
|
||||
->orWhere('email', 'LIKE', "%{$keyword}%")
|
||||
->count();
|
||||
|
||||
return [
|
||||
'users' => $users,
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'pageSize' => $pageSize,
|
||||
'totalPages' => ceil($total / $pageSize)
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user