AppIcon.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. use tools\Phptree;
  5. class AppIcon extends Base
  6. {
  7. protected $createTime = 'create_time';
  8. public function updates(){
  9. $data = request()->post();
  10. $result = validate('AppIcon')->check($data,[],'');
  11. if(true !== $result){
  12. $this->error = validate('AppIcon')->getError();
  13. return false;
  14. }
  15. $id = $data['id'];
  16. unset($data['id']);
  17. if($id > 0){
  18. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  19. }else{
  20. $data['create_time'] = date('Y-m-d H:i:s');
  21. $ret = $this->allowField(true)->save($data);
  22. }
  23. if(!$ret){
  24. $this->error = '操作失败';
  25. return false;
  26. }
  27. return true;
  28. }
  29. // 获取所有权限
  30. public function getAllIconTree(){
  31. $lists = Db::name('app_icon')
  32. ->where('enable',1)
  33. ->where('del',0)
  34. ->field('id,name,pid')
  35. ->order('sort desc,id asc')
  36. ->select();
  37. $lists = $lists?$lists:[];
  38. foreach ($lists as $k=>$v){
  39. $pids = [];
  40. $pid = $v['pid'];
  41. while (true){
  42. if($pid == 0){
  43. break;
  44. }else{
  45. $pids[] = 'sub_'.$pid;
  46. $cc = Db::name('app_icon')
  47. ->where('id',$pid)
  48. ->find();
  49. if(!$cc){
  50. break;
  51. }
  52. $pid = $cc['pid'];
  53. }
  54. }
  55. $lists[$k]['pids'] = $pids?implode(' ',$pids):'';
  56. }
  57. $tree = Phptree::makeTree(($lists), array(
  58. 'primary_key'=>'id',
  59. 'parent_key'=>'pid',
  60. 'expanded' => true,
  61. 'children_key' => 'children'
  62. ));
  63. return $tree;
  64. }
  65. // 获取某组织的所有APP权限
  66. public function getOrgAllIconTree($orgId){
  67. $auths = model('Org')->getOrgAuths($orgId,2);
  68. $lists = [];
  69. if($auths){
  70. $lists = Db::name('app_icon')
  71. ->where('enable',1)
  72. ->where('id','in',$auths)
  73. ->field('id,name,pid')
  74. ->order('sort desc,id asc')
  75. ->select();
  76. $lists = $lists?$lists:[];
  77. foreach ($lists as $k=>$v){
  78. $pids = [];
  79. $pid = $v['pid'];
  80. while (true){
  81. if($pid == 0){
  82. break;
  83. }else{
  84. $pids[] = 'sub_'.$pid;
  85. $cc = Db::name('app_icon')
  86. ->where('id',$pid)
  87. ->find();
  88. if(!$cc){
  89. break;
  90. }
  91. $pid = $cc['pid'];
  92. }
  93. }
  94. $lists[$k]['pids'] = $pids?implode(' ',$pids):'';
  95. }
  96. }
  97. $tree = Phptree::makeTree(($lists), array(
  98. 'primary_key'=>'id',
  99. 'parent_key'=>'pid',
  100. 'expanded' => true,
  101. 'children_key' => 'children'
  102. ));
  103. return $tree;
  104. }
  105. public function getOrgAllIconTree_new($orgId){
  106. $auths = model('Org')->getOrgAuths($orgId,2);
  107. $lists = [];
  108. if($auths){
  109. $lists = Db::name('app_icon')
  110. ->where('enable',1)
  111. ->where('id','in',$auths)
  112. ->field('id,name,pid')
  113. ->order('sort desc,id asc')
  114. ->select();
  115. $lists = $lists?$lists:[];
  116. // foreach ($lists as $k=>$v){
  117. // $pids = [];
  118. // $pid = $v['pid'];
  119. // while (true){
  120. // if($pid == 0){
  121. // break;
  122. // }else{
  123. // $pids[] = 'sub_'.$pid;
  124. // $cc = Db::name('app_icon')
  125. // ->where('id',$pid)
  126. // ->find();
  127. // if(!$cc){
  128. // break;
  129. // }
  130. // $pid = $cc['pid'];
  131. // }
  132. // }
  133. // $lists[$k]['pids'] = $pids?implode(' ',$pids):'';
  134. // }
  135. foreach ($lists as $k=>$v){
  136. $lists[$k]['title'] = $v['name'];
  137. }
  138. }
  139. $tree = Phptree::makeTree(($lists), array(
  140. 'primary_key'=>'id',
  141. 'parent_key'=>'pid',
  142. 'expanded' => true,
  143. 'children_key' => 'children'
  144. ));
  145. return $tree;
  146. }
  147. }