SystemRole.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace app\admin\model;
  3. use support\Db;
  4. use support\Model;
  5. /**
  6. * 角色模型
  7. * Class Users
  8. * @package app\admin\model
  9. */
  10. class SystemRole extends Model
  11. {
  12. const ROLE_STATUS = 1;
  13. const IS_SHOW_YES = 1;
  14. const IS_SHOW_NO = 2;
  15. const ROLE_IS_SHOW = [
  16. self::IS_SHOW_YES => '启用',
  17. self::IS_SHOW_NO => '禁用'
  18. ];
  19. /**
  20. * The table associated with the model.
  21. *
  22. * @var string
  23. */
  24. protected $table = 'system_role';
  25. public $timestamps = false;
  26. /**
  27. * Notes:获取角色列表
  28. * @param string $keywords
  29. * @param int $page
  30. * @param int $limit
  31. * @return array
  32. * User: ZQ
  33. * Date: 2022/9/13
  34. */
  35. public static function getRoleList(int $page, int $limit, string $keywords)
  36. {
  37. $list = static::select('*')
  38. ->where(['role_status'=>static::ROLE_STATUS])
  39. ->when($keywords != '', function ($query) use ($keywords){
  40. $query->where('role_name', 'like', '%' . $keywords . '%');
  41. })
  42. ->orderBy('role_create_time','DESC')
  43. ->forPage($page, $limit)
  44. ->get();
  45. $count = static::where(['role_status'=>static::ROLE_STATUS])
  46. ->when($keywords != '', function ($query) use ($keywords){
  47. $query->where('role_name', 'like', '%' . $keywords . '%');
  48. })
  49. ->count();
  50. return [$list, $count];
  51. }
  52. /**
  53. * Notes:获取角色列表
  54. * @return array
  55. * User: ZQ
  56. * Date: 2022/9/19`
  57. */
  58. public static function getRoleAll()
  59. {
  60. $list = static::select(['role_id','role_name'])
  61. ->where(['role_status'=>static::ROLE_STATUS])
  62. ->orderBy('role_create_time','DESC')
  63. ->get();
  64. return $list;
  65. }
  66. /**
  67. * Notes:获取角色名称
  68. * @param string $account
  69. * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
  70. * User: ZQ
  71. * Date: 2022/9/19
  72. */
  73. public static function roleMation($admin_roles)
  74. {
  75. $where = [];
  76. $where['role_status'] = static::ROLE_STATUS;
  77. $mation = static::where($where)
  78. ->when($admin_roles != '', function ($query) use ($admin_roles){
  79. $query->whereIn('role_id', $admin_roles);
  80. })
  81. ->get('role_name');
  82. return $mation;
  83. }
  84. /**
  85. * Notes:获取身份列表
  86. * @param array $admin_roles
  87. * @return array
  88. * User: yym
  89. * Date: 2022/9/21
  90. */
  91. public static function getRuleList(array $admin_roles)
  92. {
  93. return static::where(['role_status' => static::ROLE_STATUS, 'role_is_show' => static::IS_SHOW_YES])
  94. ->whereIn('role_id', $admin_roles)
  95. ->get()
  96. ->toArray();
  97. }
  98. }