AppIcon.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 = [];
  58. if($lists){
  59. $tree = Phptree::makeTree(($lists), array(
  60. 'primary_key'=>'id',
  61. 'parent_key'=>'pid',
  62. 'expanded' => true
  63. ));
  64. }
  65. return $tree;
  66. }
  67. // 获取某组织的所有APP权限
  68. public function getOrgAllIconTree($orgId){
  69. $auths = model('Org')->getOrgAuths($orgId,2);
  70. $lists = [];
  71. if($auths){
  72. $lists = Db::name('app_icon')
  73. ->where('enable',1)
  74. ->where('id','in',$auths)
  75. ->field('id,name,pid')
  76. ->order('sort desc,id asc')
  77. ->select();
  78. $lists = $lists?$lists:[];
  79. foreach ($lists as $k=>$v){
  80. $pids = [];
  81. $pid = $v['pid'];
  82. while (true){
  83. if($pid == 0){
  84. break;
  85. }else{
  86. $pids[] = 'sub_'.$pid;
  87. $cc = Db::name('app_icon')
  88. ->where('id',$pid)
  89. ->find();
  90. if(!$cc){
  91. break;
  92. }
  93. $pid = $cc['pid'];
  94. }
  95. }
  96. $lists[$k]['pids'] = $pids?implode(' ',$pids):'';
  97. }
  98. }
  99. $tree = [];
  100. if(!empty($lists)){
  101. $tree = Phptree::makeTree(($lists), array(
  102. 'primary_key'=>'id',
  103. 'parent_key'=>'pid',
  104. 'expanded' => true,
  105. 'children_key' => 'children'
  106. ));
  107. }
  108. return $tree;
  109. }
  110. public function getOrgAllIconTree_new($orgId){
  111. $auths = model('Org')->getOrgAuths($orgId,2);
  112. $lists = [];
  113. if($auths){
  114. $lists = Db::name('app_icon')
  115. ->where('enable',1)
  116. ->where('id','in',$auths)
  117. ->field('id,name,pid')
  118. ->order('sort desc,id asc')
  119. ->select();
  120. $lists = $lists?$lists:[];
  121. // foreach ($lists as $k=>$v){
  122. // $pids = [];
  123. // $pid = $v['pid'];
  124. // while (true){
  125. // if($pid == 0){
  126. // break;
  127. // }else{
  128. // $pids[] = 'sub_'.$pid;
  129. // $cc = Db::name('app_icon')
  130. // ->where('id',$pid)
  131. // ->find();
  132. // if(!$cc){
  133. // break;
  134. // }
  135. // $pid = $cc['pid'];
  136. // }
  137. // }
  138. // $lists[$k]['pids'] = $pids?implode(' ',$pids):'';
  139. // }
  140. foreach ($lists as $k=>$v){
  141. $lists[$k]['title'] = $v['name'];
  142. }
  143. }
  144. $tree = [];
  145. if(!empty($lists)){
  146. $tree = Phptree::makeTree(($lists), array(
  147. 'primary_key'=>'id',
  148. 'parent_key'=>'pid',
  149. 'expanded' => true,
  150. 'children_key' => 'children'
  151. ));
  152. }
  153. return $tree;
  154. }
  155. }