## 角色权限设置
>[info]功能:
1,显示数据:查询控制器中方法上面的注释 显示为账号权限
2,插入数据:新建权限 只需要在写好的方法上 标明注释
/*
*@desc 写入权限列表数据
*
*/
static public function ts(){
$fs = file::find(BASE.'/modules/doc')['file'];
foreach($fs as $f){
$fname = file::name($f);
if($fname == 'login.php' || $fname == 'admin_users.php' || $fname == 'yf_shop_base.php' || $fname == 'yf_goods_cat.php' || $fname == 'roles.php' || $fname == 'users.php' || $fname == 'logo.php' || $fname == 'configapi.php' || $fname == 'bind_shop.php' || $fname == 'users_bind.php' ){
continue;
}
$s1 = "doc/".substr($fname,0,strrpos($fname,'.'));
$line = file_get_contents($f);
preg_match('/desc(.*)\n/', $line, $matche);
preg_match_all('/desc(.*)\n+(.*\n?){0,5}public(.*)function(.*)\(/', $line, $matches);
if($matches){
$title = $matches[1];
$action = $matches[4];
$new[$s1]['top']['title'] = str_replace("\r"," " ,strip_tags($matche[1]));
$new[$s1]['top']['address'] = 'top';
foreach($title as $k=>$ti){
unset($out);
$out['address'] = trim($action[$k]);
$out['title'] = str_replace("\r","" ,strip_tags($ti));
$out['action'] = $s1."/".trim($action[$k]);
$new[$s1][] = $out;
}
}
}
if($new){
$list = acl::get()->toArray();
$role = new acl;
if(!$list){
foreach($new as $k=>$v){
$data['slug'] = $k;
$data['title'] = $v['top']['title'];
$pid = $role->insertGetId($data);
foreach($v as $k1=>$v1){
if($v1['address'] == 'top') continue;
$date['slug'] = $v1['action'];
$date['title'] = $v1['title'];
$date['pid'] = $pid;
$role->insert($date);
}
}
}else{
foreach($new as $k=>$v){
$a = $role->where('slug',$k)->first();
if(!$a){
$data['slug'] = $k;
$data['title'] = $v['top']['title'];
$pid = $role->insertGetId($data);
}else{
$data['slug'] = $k;
$data['title'] = $v['top']['title'];
$role->where('slug',$k)->update($data);
$pid = $a->id;
}
foreach($v as $k1=>$v1){
if($v1['address'] == 'top') continue;
$b = $role->where('slug',$v1['action'])->first();
if(!$b){
$date['slug'] = $v1['action'];
$date['title'] = $v1['title'];
$date['pid'] = $pid;
$role->insert($date);
}else{
$date['slug'] = $v1['action'];
$date['title'] = $v1['title'];
$date['pid'] = $pid;
$role->where('slug',$v1['action'])->update($date);
}
}
}
}
}
}
/*
*@desc 获取权限列表数据
*/
static public function qx(){
$list = self::where('pid',0)->get();
foreach($list as $k=>$v){
$list[$k]['list'] = $v->parent;
}
return $list;
}
>[info] 3,编辑数据:修改注释名称
`修改注释即可`
4,删除数据:删除权限
`删除注释即可`
5,关联`shop_users` `acl_roles` `roles`