AuthRole.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * 厦门云联储网络科技有限公司
  4. * https://www.baokuaiyun.com
  5. * Copyright (c) 2023 爆块云 All rights reserved.
  6. */
  7. namespace app\models;
  8. use yii\db\ActiveRecord;
  9. use yii\behaviors\TimestampBehavior;
  10. /**
  11. * Class AuthRole
  12. * @package app\modules\common\models
  13. * @property string $id
  14. * @property string $name
  15. * @property string $data
  16. * @property string $edit_data
  17. * @property string $describe
  18. * @property integer $status
  19. * @property string $created_at
  20. * @property string $updated_at
  21. * @property integer $store_id
  22. */
  23. class AuthRole extends ActiveRecord
  24. {
  25. const STATUS_NORMAL = 1; // 正常
  26. const STATUS_DISABLE = 0; // 禁用
  27. public static function tableName()
  28. {
  29. return '{{%auth_role}}';
  30. }
  31. public function behaviors()
  32. {
  33. return [
  34. [
  35. // 自动更新创建和更新时间
  36. 'class' => TimestampBehavior::class,
  37. 'value' => date("Y-m-d H:i:s")
  38. ]
  39. ];
  40. }
  41. public function rules()
  42. {
  43. return [
  44. [['id', 'status', 'store_id'], 'integer'],
  45. [['name'], 'string', 'max' => 64],
  46. [['name', 'data'], 'required'],
  47. [['data', 'edit_data'], 'string'],
  48. [['describe'], 'string', 'max' => 255],
  49. [['create_at', 'update_at'], 'safe']
  50. ];
  51. }
  52. public function attributeLabels()
  53. {
  54. return [
  55. 'id' => 'ID',
  56. 'name' => '角色名称',
  57. 'create_at' => '创建时间',
  58. 'update_at' => '更新时间',
  59. 'data' => '角色数据',
  60. 'edit_data' => '角色数据',
  61. 'describe' => '简介',
  62. 'status' => '状态',
  63. 'store_id' => '商城id',
  64. ];
  65. }
  66. /**
  67. * 获取管理员
  68. * @return \yii\db\ActiveQuery
  69. * @throws \yii\base\InvalidConfigException
  70. */
  71. public function getAdmins()
  72. {
  73. return $this->hasMany(Admin::class, ['id' => 'admin_id'])
  74. ->where(['type' => 'staff', 'is_delete' => 0])
  75. ->viaTable('{{%admin_role}}', ['role_id' => 'id']);
  76. }
  77. }