AccessToken.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace common\models\oauth2;
  3. use Yii;
  4. use yii\behaviors\BlameableBehavior;
  5. use yii\db\ActiveRecord;
  6. use yii\behaviors\TimestampBehavior;
  7. use common\behaviors\MerchantBehavior;
  8. use common\models\base\User;
  9. /**
  10. * This is the model class for table "{{%oauth2_access_token}}".
  11. *
  12. * @property int $id
  13. * @property string $access_token 授权Token
  14. * @property int|null $merchant_id 商户id
  15. * @property string|null $auth_key 授权令牌
  16. * @property string $client_id 授权ID
  17. * @property string|null $member_id 用户ID
  18. * @property string $expires 有效期
  19. * @property string|null $scope 授权权限
  20. * @property string|null $grant_type 组别
  21. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  22. * @property int|null $created_at 创建时间
  23. * @property int|null $updated_at 修改时间
  24. */
  25. class AccessToken extends User
  26. {
  27. use MerchantBehavior;
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public static function tableName()
  32. {
  33. return '{{%oauth2_access_token}}';
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function rules()
  39. {
  40. return [
  41. [['merchant_id', 'status', 'created_at', 'updated_at'], 'integer'],
  42. [['access_token', 'client_id', 'expires'], 'required'],
  43. [['expires', 'scope'], 'safe'],
  44. [['access_token'], 'string', 'max' => 80],
  45. [['client_id'], 'string', 'max' => 64],
  46. [['member_id'], 'string', 'max' => 100],
  47. [['grant_type'], 'string', 'max' => 30],
  48. [['auth_key'], 'string', 'max' => 32],
  49. ];
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public function attributeLabels()
  55. {
  56. return [
  57. 'id' => 'ID',
  58. 'access_token' => '授权Token',
  59. 'merchant_id' => '商户id',
  60. 'auth_key' => '授权令牌',
  61. 'client_id' => '授权ID',
  62. 'member_id' => '用户ID',
  63. 'expires' => '有效期',
  64. 'scope' => '授权权限',
  65. 'grant_type' => '组别',
  66. 'status' => '状态',
  67. 'created_at' => '创建时间',
  68. 'updated_at' => '修改时间',
  69. ];
  70. }
  71. /**
  72. * @return \yii\db\ActiveQuery
  73. */
  74. public function getClient()
  75. {
  76. return $this->hasOne(Client::class, ['client_id' => 'client_id']);
  77. }
  78. /**
  79. * @return array
  80. */
  81. public function behaviors()
  82. {
  83. $merchant_id = Yii::$app->services->merchant->getNotNullId();
  84. return [
  85. [
  86. 'class' => TimestampBehavior::class,
  87. 'attributes' => [
  88. ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
  89. ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
  90. ],
  91. ],
  92. [
  93. 'class' => BlameableBehavior::class,
  94. 'attributes' => [
  95. ActiveRecord::EVENT_BEFORE_INSERT => ['merchant_id'],
  96. ],
  97. 'value' => $merchant_id,
  98. ]
  99. ];
  100. }
  101. }
粤ICP备19079148号