64], [['password', 'auth_key', 'access_token'], 'string', 'max' => 128], [['nickname'], 'string', 'max' => 45], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => 'Mall ID', 'mch_id' => 'Mch ID', 'username' => 'Username', 'password' => 'Password', 'nickname' => 'Nickname', 'auth_key' => 'Auth Key', 'access_token' => 'Access Token', 'unionid' => 'Unionid', 'created_at' => 'Created At', 'updated_at' => 'Updated At', 'deleted_at' => 'Deleted At', 'is_delete' => 'Is Delete', ]; } /** * 根据给到的ID查询身份。 * * @param string|integer $id 被查询的ID * @return IdentityInterface|null 通过ID匹配到的身份对象 */ public static function findIdentity($id) { return static::findOne($id); } /** * 根据 token 查询身份。 * * @param string $token 被查询的 token * @return IdentityInterface|null 通过 token 得到的身份对象 */ public static function findIdentityByAccessToken($token, $type = null) { return static::findOne(['access_token' => $token]); } /** * @return int|string 当前用户ID */ public function getId() { return $this->id; } /** * @return string 当前用户的(cookie)认证密钥 */ public function getAuthKey() { return $this->auth_key; } /** * @param string $authKey * @return boolean if auth key is valid for current user */ public function validateAuthKey($authKey) { return $this->getAuthKey() === $authKey; } /** * 用户身份 * @return \yii\db\ActiveQuery */ public function getIdentity() { return $this->hasOne(UserIdentity::className(), ['user_id' => 'id']); } public function getAdminInfo() { return $this->hasOne(AdminInfo::className(), ['user_id' => 'id']); } public function getRole() { return $this->hasMany(AuthRole::className(), ['id' => 'role_id'])->andWhere(['is_delete' => 0]) ->viaTable(AuthRoleUser::tableName(), ['user_id' => 'id', 'is_delete' => 'is_delete']); } public function getUserInfo() { return $this->hasOne(UserInfo::className(), ['user_id' => 'id']); } public function getStore() { return $this->hasOne(Store::className(), ['id' => 'store_id']) ->viaTable(UserInfo::tableName(), ['user_id' => 'id', 'is_delete' => 'is_delete']); } public function getShare() { return $this->hasOne(Share::className(), ['user_id' => 'id']); } public function getParent() { return $this->hasOne(User::className(), ['id' => 'parent_id']) ->viaTable(UserInfo::tableName(), ['user_id' => 'id', 'is_delete' => 'is_delete']); } public function getNewParent() { return $this->hasOne(User::className(), ['id' => 'parent_id']); } public function getFormId() { return $this->hasMany(Formid::className(), ['user_id' => 'id']); } public function getOneFormId() { return $this->hasOne(Formid::className(), ['user_id' => 'id']); } public function setShare($val) { $this->share = $val; } public function getMall() { return $this->hasMany(Mall::className(), ['user_id' => 'id']); } public function getPlatform($platform) { switch ($platform) { case 'wxapp': $value = '微信'; break; case 'aliapp': $value = '支付宝'; break; case 'ttapp': $value = '头条'; break; case 'bdapp': $value = '百度'; break; default: $value = '未知'; break; } return $value; } public function getUserPlatform() { return $this->hasMany(UserPlatform::className(), ['user_id' => 'id']); } }