UseScopeBaseModel.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Model;
  3. use App\Service\RangeService;
  4. use Illuminate\Database\Eloquent\Model;
  5. class UseScopeBaseModel extends Model
  6. {
  7. //可见范围
  8. const range_function = '';
  9. const is_check_function = '';
  10. public function __construct(array $attributes = [])
  11. {
  12. parent::__construct($attributes);
  13. }
  14. public function scopeKqClear($query, $user, $search)
  15. {
  16. //权限范围内的人
  17. $man_range = $user['man_range'] ?? [];
  18. $man_number = array_unique(array_column($man_range,'number'));
  19. //个人部门所有
  20. $auth_type = $this->getQx($search,$user);
  21. if($auth_type <= 0){
  22. //不需要分个人部门所有的数据
  23. if($auth_type == 0) $query->whereIn('number', $man_number);
  24. }else{
  25. if($auth_type == 1) { //我的
  26. $query->where('number',$user['number']);
  27. }elseif ($auth_type == 2 || $auth_type == 3){
  28. //自己权限范围内的部门 或 所有
  29. $query->whereIn('number', $man_number);
  30. }
  31. }
  32. }
  33. public function getQx($data, $user){
  34. if(empty($data['menu_authority_id'])) return 0;
  35. if($user['id'] == Employee::SPECIAL_ADMIN) return -1;
  36. if(! empty($user['role_authority'][$data['menu_authority_id']])) {
  37. //指定菜单 显示对应权限
  38. return $user['role_authority'][$data['menu_authority_id']];
  39. }else{
  40. return 1;
  41. }
  42. }
  43. function hasMethod($class, $methodName)
  44. {
  45. $reflection = new \ReflectionClass($class);
  46. return $reflection->hasMethod($methodName);
  47. }
  48. }