Role.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace App\Http\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Database\Eloquent\Relations\BelongsToMany;
  5. use Illuminate\Database\Eloquent\SoftDeletes;
  6. class Role extends Model
  7. {
  8. use SoftDeletes;
  9. protected $table = 'roles';
  10. protected $guarded = [];
  11. /**
  12. * A role may be given various permissions.
  13. */
  14. public function permissions(): BelongsToMany
  15. {
  16. return $this->belongsToMany(
  17. Permission::class,
  18. 'role_has_permissions',
  19. 'role_id',
  20. 'permission_id'
  21. );
  22. }
  23. public function users()
  24. {
  25. return $this->hasMany(User::class, 'role_id', 'id');
  26. }
  27. public function projects(): BelongsToMany
  28. {
  29. return $this->belongsToMany(
  30. Project::class,
  31. 'role_has_projects',
  32. 'project_id',
  33. 'permission_id'
  34. );
  35. }
  36. const TYPE_CLIENT = -1; //客户
  37. const TYPE_SELLER = 1; //销售
  38. const TYPE_AE = 2; //采编AE人员
  39. const TYPE_LINK_PART = 3; //外链兼职
  40. const TYPE_ARTICLE_PART = 4;//软文兼职
  41. const TYPE_CUSTOMER = 5; //客户
  42. const TYPE_MANAGER = 6; //项目总控
  43. const TYPE_SERVER = 7; //客服
  44. const TYPE_CHANNEL_BOSS = 8; //渠道老板
  45. const TYPE_AGENT_BOSS = 9;//代理商老板
  46. const TYPE_LINK_PART_CHONGQING = 13;//重庆兼职人员
  47. const TYPE_WEB = 14;//前端
  48. const TYPE_PROPAGANDA = 15;//品宣部
  49. const TYPE_BID = 16; //竞价人员
  50. const TYPE_ARTICLE = 17; //软文部
  51. const TYPE_LINK = 18; //外链部
  52. const TYPE_AGENT_MANAGER = 19;//代理商经理
  53. const TYPE_AGENT_WORKER = 20;//代理商员工
  54. const TYPE_CHANNEL_MANAGER = 21;//渠道经理
  55. const TYPE_CHANNEL_WORKER = 22;//渠道员工
  56. const TYPE_TYPE_CUSTOMER_STAFF = 23;//客户员工
  57. const TYPE_MANAGE_LEADER = 24;//项目总监
  58. const TYPE_MANAGE_HELPER = 25;//项目经理
  59. const TYPE_OPTIMIZER = 26;//优化师
  60. const TYPE_DESIGNER = 27;//设计师
  61. const TYPE_financial = 28;//财务
  62. const TYPE_PLANNER = 29;//策划
  63. const TYPE_QUALITY = 30;//质检
  64. const TYPE_DESIGN_DIRECTOR = 31;//设计总监
  65. const TYPE_OPTIMIZATION_EDITING = 32;//优化采编
  66. const TYPE_HR = 33;//hr
  67. const TYPE_SOFT_TEXT_SEARCH = 34;//软文查找
  68. const TYPE_BIDDING_MANAGER = 35;//竞价经理
  69. const TYPE_CHONGQING_MANAGER = 36;//重庆主管
  70. const TYPE_CHONGQING_LINK = 37;//重庆外链
  71. public static function getUsers($type)
  72. {
  73. $role = self::query()->where(['id' => $type])->first();
  74. if (!$role) return collect([]);
  75. return $role->users()->where(['status' => 1])->select(['id', 'username', 'nickname'])->get();
  76. }
  77. }