SystemDept.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | saiadmin [ saiadmin快速开发框架 ]
  4. // +----------------------------------------------------------------------
  5. // | Author: sai <1430792918@qq.com>
  6. // +----------------------------------------------------------------------
  7. namespace plugin\saiadmin\app\model\system;
  8. use plugin\saiadmin\basic\BaseModel;
  9. /**
  10. * 部门模型
  11. */
  12. class SystemDept extends BaseModel
  13. {
  14. /**
  15. * 数据表主键
  16. * @var string
  17. */
  18. protected $pk = 'id';
  19. protected $table = 'sa_system_dept';
  20. /**
  21. * 权限范围
  22. */
  23. public function scopeAuth($query, $value)
  24. {
  25. if (!empty($value)) {
  26. $deptIds[] = $value['id'];
  27. $ids = static::whereRaw('FIND_IN_SET("'.$value['id'].'", level) > 0')->column('id');
  28. $deptIds = array_merge($deptIds, $ids);
  29. $query->whereIn('id', $deptIds);
  30. }
  31. }
  32. public function leader()
  33. {
  34. return $this->belongsToMany(SystemUser::class, SystemDeptLeader::class, 'user_id', 'dept_id');
  35. }
  36. }