You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

107 lines
2.6 KiB

  1. <?php
  2. namespace common\models;
  3. use Yii;
  4. use yii\db\ActiveQuery;
  5. /**
  6. * This is the model class for table "base_user_auth".
  7. *
  8. * @property integer $id
  9. * @property integer $sys
  10. * @property string $auth_name
  11. * @property string $role_list
  12. * @property integer $main_corp
  13. */
  14. class BaseUserAuth extends \yii\db\ActiveRecord
  15. {
  16. const SYS_CS = 0; // 全权限
  17. const SYS_FO = 1; // 车系统
  18. const SYS_ADMIN = 1; //系统管理员
  19. const BUS_BD = 2; //巴士BD人员
  20. const BUS_OPERA_CUS = 3; //巴士运营客服人员
  21. const FINANCIAL_OFFICER = 4; //财务人员
  22. const HOTEL_OPERATOR = 5; //酒店运营人员
  23. const HOTEL_PURCHASE = 6; //酒店采购人员
  24. const HOTEL_CUSTOMER = 7; //酒店客服人员
  25. const BUS_OPERA_ADMIN = 8;//巴士运营管理人员
  26. const HOTEL_ADMIN = 9;//酒店管理人员
  27. const HOTEL_CUS_ADMIN = 10; //酒店客服管理人员
  28. const MAIN_CORP=16; // 运营主体管理账号
  29. /**
  30. * @inheritdoc
  31. */
  32. public static function tableName()
  33. {
  34. return 'base_user_auth';
  35. }
  36. /**
  37. * @inheritdoc
  38. */
  39. public function rules()
  40. {
  41. return [
  42. [['sys', 'main_corp'], 'integer'],
  43. [['role_list'], 'string'],
  44. [['auth_name'], 'required'],
  45. [['auth_name'], 'string', 'max' => 50],
  46. ];
  47. }
  48. public function getMainCorp()
  49. {
  50. return $this->hasOne(BaseMainCorporation::className(), ['id' => 'main_corp']);
  51. }
  52. /**
  53. * @inheritdoc
  54. */
  55. public function attributeLabels()
  56. {
  57. return [
  58. 'id' => 'ID',
  59. 'sys' => '系统,0:cs系统,1:车系统',
  60. 'auth_name' => '角色名称',
  61. 'role_list' => '权限列表',
  62. 'main_corp' => '运营主体'
  63. ];
  64. }
  65. /**
  66. * User: wangxj
  67. *
  68. * 函数作用
  69. *
  70. * @param $sys
  71. * @return ActiveQuery
  72. */
  73. public static function zFind($sys)
  74. {
  75. return parent::find()->where(['sys' => $sys]);
  76. }
  77. /**
  78. * 检查是否有权限
  79. * @param $route
  80. * @param $menu_permission
  81. * @return bool
  82. */
  83. public static function can($route)
  84. {
  85. $user = Yii::$app->user->identity;
  86. /* @var $user \common\models\User */
  87. $role = BaseRole::findOne(['ROLE_NAME' => $route]);
  88. if (!is_array($user->MENU_PERMISSION)) {
  89. $user->MENU_PERMISSION = explode(',', $user->MENU_PERMISSION);
  90. }
  91. if ($user->STATUS == 0 && $role != null && in_array($role->ID, $user->MENU_PERMISSION)) {
  92. return true;
  93. }
  94. return false;
  95. }
  96. }