1
0

Org.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace app\model;
  3. use think\Model;
  4. class Org extends Model
  5. {
  6. /**
  7. * 获取目录下到所有组织id
  8. */
  9. public function getClosetOrg($org_id)
  10. {
  11. // $path = self::where(['id'=>$org_id])->value('path');
  12. // $pathArr = explode('-', $path);
  13. // if(empty($pathArr[1])) return [];
  14. // $rootPath = $pathArr[0].'-'.$pathArr[1].'-';
  15. // $closetIdList = self::where([['path', 'like', $rootPath]])->column('id');
  16. $closetIdList = self::column('id');
  17. return $closetIdList;
  18. }
  19. /**
  20. * 获取关联子组织id
  21. */
  22. public function getChildOrg($org_id)
  23. {
  24. $path = self::where(['id'=>$org_id])->value('path');
  25. $childIdList = self::where([['path', 'like', $path.'%']])->column('id');
  26. return $childIdList;
  27. }
  28. /**
  29. * 获取关联每个节点的员工列表
  30. */
  31. public function employee()
  32. {
  33. return $this->hasMany(Employee::class);
  34. }
  35. public function employees()
  36. {
  37. return $this->hasMany(Employee::class, 'root_id');
  38. }
  39. public function company()
  40. {
  41. return $this->hasOne(Company::class, 'root_id');
  42. }
  43. }