chore: 重写初始提交(清空历史,整理后全量提交)

This commit is contained in:
ywxapp
2026-08-16 16:54:14 +08:00
commit 6c1a106bc1
1808 changed files with 238144 additions and 0 deletions
+69
View File
@@ -0,0 +1,69 @@
<?php
// +----------------------------------------------------------------------
// | YwxApp [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2026-2036 http://ywxapp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: ywxapp<admin@ywxapp.cn>
// +----------------------------------------------------------------------
namespace ywxapp\model;
use think\model\concern\SoftDelete;
use ywxapp\model\BaseModel;
/**
* BackendRole 类
*
* @author ywxapp <admin@ywxapp.cn>
*/
class BackendRole extends BaseModel
{
use SoftDelete;
// 设置表名(think-orm 4.0name 不带前缀,自动拼 wxapp_
protected $name = 'backend_role';
// 设置主键
protected $pk = 'id';
// 自动时间戳
protected $autoWriteTimestamp = 'int';
protected $createTime = 'create_at';
protected $updateTime = 'update_at';
protected $deleteTime = 'delete_at';
// 隐藏字段
protected $hidden = ['password', 'delete_at'];
// 只读字段
protected $readonly = ['id'];
// 角色拥有的用户
public function admins()
{
return $this->belongsToMany(BackendAdmin::class, BackendRoleAccess::class, 'admin_id', 'role_id');
}
/**
* 角色 → 权限字符串(通过 role_permissions 表)
*/
public function powers()
{
// 返回的是 permission 字符串列表(不是 Menu 模型)
return $this->belongsToMany(BackendPower::class, BackendRolePower::class, 'power_id', 'role_id')->field('power_id');
}
// 【推荐】角色 → 菜单模型(通过中间表 role_permissions 关联 menus
public function menus()
{
return $this->belongsToMany(BackendPower::class, BackendRolePower::class, 'power_id', 'role_id', 'permission');
}
/**
* 表结构自愈:建表 + 关键列兜底(install.sql 为事实源)。
* 查询/写入前调用,避免老库缺表导致 1146。
*/
public static function ensureSchema(): void
{
BaseModel::ensureTableFromInstall(BaseModel::currentPrefix(), 'backend_role');
}
}