255], [['auth_key', 'wx_openid', 'mini_openid'], 'string', 'max' => 32], [['name', 'nickname', 'session_key'], 'string', 'max' => 120], [['phone'], 'string', 'max' => 13], [['unionid'], 'string', 'max' => 60], [['member_code'], 'string', 'max' => 20], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'id', 'username' => 'username', 'auth_key' => 'auth_key', 'password_hash' => 'password_hash', 'password_reset_token' => 'password_reset_token', 'name' => 'name', 'sex' => 'sex', 'phone' => '联系方式', 'email' => 'email', 'role' => 'role', 'status' => 'status', 'access_token' => 'access_token', 'expire_at' => 'expire_at', 'nickname' => 'nickname', 'avatar' => 'avatar', 'wx_openid' => '公众号openid', 'mini_openid' => '小程序openid', 'unionid' => 'unionid', 'session_key' => '小程序解密密钥', 'member_code' => '会员编号', 'exp_point' => '经验值', 'consume_point' => '消费积分', 'created_at' => '创建时间', 'updated_at' => '更新时间', ]; } /** * @author linyao * @email 602604991@qq.com * @created Nov 8, 2019 * * 行为存储创建时间和更新时间 */ public function behaviors() { return [ [ 'class' => TimestampBehavior::className(), 'createdAtAttribute' => 'created_at', 'updatedAtAttribute' => 'updated_at', 'value' => function () { return time(); }, ], ]; } /** * @inheritDoc */ public static function findIdentity($id) { return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]); } /** * @param mixed $token * @param null $type * @return array|\yii\db\ActiveRecord|IdentityInterface|null * @throws NotFoundHttpException * @throws UnauthorizedHttpException */ public static function findIdentityByAccessToken($token, $type = null) { $user = static::find() ->where(['access_token' => $token, 'status' => self::STATUS_ACTIVE]) ->one(); if (!$user) { throw new NotFoundHttpException('user not found'); } if ($user->expire_at < time()) { throw new UnauthorizedHttpException('access - token expired ', -1); } else { return $user; } } /** * @inheritDoc */ public function getId() { return $this->getPrimaryKey(); } /** * @inheritDoc */ public function getAuthKey() { return $this->auth_key; } /** * @inheritDoc */ public function validateAuthKey($authKey) { return $this->getAuthKey() === $authKey; } }