初始化项目:添加后端代码、ThinkPHP框架、前端资源
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
class AuthGroup extends Model
|
||||
{
|
||||
|
||||
// 开启自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'int';
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
|
||||
// 表名
|
||||
protected $name = 'auth_group';
|
||||
|
||||
public function getNameAttr($value, $data)
|
||||
{
|
||||
return __($value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 检查权限设置初始化
|
||||
* @return void
|
||||
*/
|
||||
public static function checkAuthInitConfig($userId){
|
||||
$hasBasicGroup = self::where([
|
||||
'rules'=>'*',
|
||||
'basic'=>1,
|
||||
'uniacid'=>UNIACID
|
||||
])->find();
|
||||
|
||||
if($hasBasicGroup){
|
||||
$basicGroupId = $hasBasicGroup['id'];
|
||||
}else{
|
||||
$basicGroupId = self::insertGetId([
|
||||
'rules'=>'*',
|
||||
'basic'=>1,
|
||||
'uniacid'=>UNIACID,
|
||||
'pid'=>0,
|
||||
'name'=>'超级管理员',
|
||||
'remark'=>'拥有最高权限的店铺管理者',
|
||||
'createtime'=>time(),
|
||||
'updatetime'=>time(),
|
||||
'status'=>'normal'
|
||||
]);
|
||||
}
|
||||
|
||||
self::checkGroupAccess($userId,$basicGroupId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 检查权限组
|
||||
* @param $userId
|
||||
* @param $basicGroupId
|
||||
* @return void
|
||||
*/
|
||||
public static function checkGroupAccess($userId,$basicGroupId){
|
||||
$condition = [
|
||||
'group_id'=>$basicGroupId,
|
||||
'uid'=>$userId,
|
||||
'uniacid'=>UNIACID
|
||||
];
|
||||
|
||||
|
||||
$hasAuthGroupAccess = \app\admin\model\AuthGroupAccess::where($condition)->find();
|
||||
|
||||
|
||||
if(!$hasAuthGroupAccess){
|
||||
\app\admin\model\AuthGroupAccess::insert($condition);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user