AuthGroup.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * ----------------------------------------------------------------------------
  4. * 行到水穷处,坐看云起时
  5. * 开发软件,找贵阳云起信息科技,官网地址:https://www.56q7.com/
  6. * ----------------------------------------------------------------------------
  7. * Author: 老成
  8. * email:85556713@qq.com
  9. */
  10. declare(strict_types=1);
  11. namespace app\common\model;
  12. use app\common\library\Tree;
  13. use think\Model;
  14. class AuthGroup extends Model{
  15. // 自动写入时间戳字段
  16. protected $autoWriteTimestamp = true;
  17. // 定义时间戳字段名
  18. protected $createTime = 'createtime';
  19. protected $updateTime = 'updatetime';
  20. protected $type = [
  21. 'updatetime' => 'timestamp:Y-m-d H:i',
  22. 'createtime' => 'timestamp:Y-m-d H:i',
  23. ];
  24. public static function getGroupListTree(mixed $groupids=''):array
  25. {
  26. if($groupids=='*'){
  27. $ruleList = self::field('id,pid,name,status')->order('id ASC')->select()->toArray();
  28. $rootid=0;
  29. }else{
  30. $ruleList = self::whereIn('id',$groupids)->field('id,pid,name,status')->order('id ASC')->select()->toArray();
  31. if(count($ruleList)===0){
  32. return [];
  33. }
  34. $rootid=$ruleList[0]['pid'];
  35. }
  36. Tree::instance()->init($ruleList);
  37. $list = Tree::instance()->getTreeArray($rootid);
  38. return $list;
  39. }
  40. }