123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
- namespace app\common\model;
- use think\Db;
- use tools\Phptree;
- class AppIcon extends Base
- {
- protected $createTime = 'create_time';
- public function updates(){
- $data = request()->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;
- }
- public function getOrgAllIconTree_new($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):'';
- // }
- foreach ($lists as $k=>$v){
- $lists[$k]['title'] = $v['name'];
- }
- }
- $tree = Phptree::makeTree(($lists), array(
- 'primary_key'=>'id',
- 'parent_key'=>'pid',
- 'expanded' => true,
- 'children_key' => 'children'
- ));
- return $tree;
- }
- }
|