Role.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace App\Repositories\Models\Base;
  3. use Prettus\Repository\Contracts\Transformable;
  4. use Prettus\Repository\Traits\TransformableTrait;
  5. class Role extends \Spatie\Permission\Models\Role implements Transformable
  6. {
  7. use TransformableTrait;
  8. /**
  9. * @var string
  10. */
  11. protected $table = 'base_roles';
  12. protected $guarded = [];
  13. /**
  14. * The attributes excluded from the model's JSON form.
  15. *
  16. * @var array
  17. */
  18. protected $hidden = [];
  19. //全部权限
  20. const DATA_TYPE_ALL = 1;
  21. const DATA_MENU_ALL = 149;
  22. const DATA_MENU_SELF = 150;
  23. const DATA_MENU_EDIT_CHECK_STATUS = 151;
  24. //仅自己权限
  25. const DATA_TYPE_SELF = 2;
  26. //自定义
  27. const DATA_TYPE_CUSTOM = 3;
  28. // //自定义部门
  29. // const DATA_TYPE_DEPARTMENT = 3;
  30. // //自定义门店
  31. // const DATA_TYPE_SHOP = 4;
  32. // //自定义工厂
  33. // const DATA_TYPE_FACTORY = 5;
  34. /**
  35. * 检查关键字是否存在
  36. * @param $name
  37. * @param $ignore_id
  38. * @return bool
  39. */
  40. public static function checkNameIsUnique($name, $ignore_id = 0)
  41. {
  42. return self::query()->where('name', $name)->where('id', '<>', $ignore_id)->exists();
  43. }
  44. public function menus()
  45. {
  46. return $this->belongsToMany(Menu::class, 'base_roles_menus');
  47. }
  48. // public function departments()
  49. // {
  50. // return $this->belongsToMany(Department::class, 'base_roles_departments');
  51. // }
  52. // 自定义部门
  53. public function departments()
  54. {
  55. return $this->morphedByMany(Department::class, 'data', 'base_roles_data', 'role_id');
  56. }
  57. //自定义门店
  58. public function shops()
  59. {
  60. return $this->morphedByMany(Department::class, 'data', 'base_roles_data', 'role_id');
  61. }
  62. //自定义工厂
  63. public function factory()
  64. {
  65. return $this->morphedByMany(Department::class, 'data', 'base_roles_data', 'role_id');
  66. }
  67. }