12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace app\model;
- use think\Model;
- class Org extends Model
- {
- /**
- * 获取目录下到所有组织id
- */
- public function getClosetOrg($org_id)
- {
- // $path = self::where(['id'=>$org_id])->value('path');
- // $pathArr = explode('-', $path);
- // if(empty($pathArr[1])) return [];
- // $rootPath = $pathArr[0].'-'.$pathArr[1].'-';
- // $closetIdList = self::where([['path', 'like', $rootPath]])->column('id');
- $closetIdList = self::column('id');
- return $closetIdList;
- }
- /**
- * 获取关联子组织id
- */
- public function getChildOrg($org_id)
- {
- $path = self::where(['id'=>$org_id])->value('path');
- $childIdList = self::where([['path', 'like', $path.'%']])->column('id');
- return $childIdList;
- }
- /**
- * 获取关联每个节点的员工列表
- */
- public function employee()
- {
- return $this->hasMany(Employee::class);
- }
- public function employees()
- {
- return $this->hasMany(Employee::class, 'root_id');
- }
- public function company()
- {
- return $this->hasOne(Company::class, 'root_id');
- }
- }
|