post(); $result = validate('AppIcon')->check($data,[],''); if(true !== $result){ $this->error = validate('AppIcon')->getError(); return false; } $id = $data['id']; unset($data['id']); if($id > 0){ $ret = $this->allowField(true)->save($data,['id'=>$id]); }else{ $data['create_time'] = date('Y-m-d H:i:s'); $ret = $this->allowField(true)->save($data); } if(!$ret){ $this->error = '操作失败'; return false; } return true; } // 获取所有权限 public function getAllIconTree(){ $lists = Db::name('app_icon') ->where('enable',1) ->where('del',0) ->field('id,name,pid') ->order('sort desc,id asc') ->select(); $lists = $lists?$lists:[]; foreach ($lists as $k=>$v){ $pids = []; $pid = $v['pid']; while (true){ if($pid == 0){ break; }else{ $pids[] = 'sub_'.$pid; $cc = Db::name('app_icon') ->where('id',$pid) ->find(); if(!$cc){ break; } $pid = $cc['pid']; } } $lists[$k]['pids'] = $pids?implode(' ',$pids):''; } $tree = Phptree::makeTree(($lists), array( 'primary_key'=>'id', 'parent_key'=>'pid', 'expanded' => true, 'children_key' => 'children' )); return $tree; } // 获取某组织的所有APP权限 public function getOrgAllIconTree($orgId){ $auths = model('Org')->getOrgAuths($orgId,2); $lists = []; if($auths){ $lists = Db::name('app_icon') ->where('enable',1) ->where('id','in',$auths) ->field('id,name,pid') ->order('sort desc,id asc') ->select(); $lists = $lists?$lists:[]; foreach ($lists as $k=>$v){ $pids = []; $pid = $v['pid']; while (true){ if($pid == 0){ break; }else{ $pids[] = 'sub_'.$pid; $cc = Db::name('app_icon') ->where('id',$pid) ->find(); if(!$cc){ break; } $pid = $cc['pid']; } } $lists[$k]['pids'] = $pids?implode(' ',$pids):''; } } $tree = Phptree::makeTree(($lists), array( 'primary_key'=>'id', 'parent_key'=>'pid', 'expanded' => true, 'children_key' => 'children' )); return $tree; } }