validate()){ return $this->getModelError(); } if(is_array($this->user_id)){ foreach ($this->user_id as $user_id){ $res = $this->is_super_admin($user_id); if($res['code'] != 0){ return $res; } $model = User::findOne([ 'is_delete' => 0, 'status' => User::STATUS_NORMAL, 'id' => $user_id ]); if($model == null){ continue; } $model->status = User::STATUS_FORBIDDEN; if(!$model->save()){ return $this->getModelError($model); } } } else { $res = $this->is_super_admin($this->user_id); if($res['code'] != 0){ return $res; } $model = User::findOne([ 'is_delete' => 0, 'status' => User::STATUS_NORMAL, 'id' => $this->user_id ]); if($model == null){ return [ 'code' => 1, 'msg' => '用户不存在' ]; } $model->status = User::STATUS_FORBIDDEN; if(!$model->save()){ return $this->getModelError($model); } } return [ 'code' => 0, 'msg' => '操作成功' ]; } public function cancel_forbidden() { if(!$this->validate()){ return $this->getModelError(); } if(is_array($this->user_id)){ foreach ($this->user_id as $user_id){ $res = $this->is_super_admin($user_id); if($res['code'] != 0){ return $res; } $model = User::findOne([ 'is_delete' => 0, 'status' => User::STATUS_FORBIDDEN, 'id' => $user_id ]); if($model == null){ continue; } $model->status = User::STATUS_NORMAL; if(!$model->save()){ return $this->getModelError($model); } } } else { $res = $this->is_super_admin($this->user_id); if($res['code'] != 0){ return $res; } $model = User::findOne([ 'is_delete' => 0, 'status' => User::STATUS_FORBIDDEN, 'id' => $this->user_id ]); if($model == null){ return [ 'code' => 1, 'msg' => '用户不存在' ]; } $model->status = User::STATUS_NORMAL; if(!$model->save()){ return $this->getModelError($model); } } return [ 'code' => 0, 'msg' => '操作成功' ]; } public function hangup() { if(!$this->validate()){ return $this->getModelError(); } if(is_array($this->user_id)){ foreach ($this->user_id as $user_id){ $res = $this->is_super_admin($user_id); if($res['code'] != 0){ return $res; } $model = User::findOne([ 'is_delete' => 0, 'status' => User::STATUS_NORMAL, 'id' => $user_id ]); if($model == null){ continue; } $model->status = User::STATUS_HANGUP; if(!$model->save()){ return $this->getModelError($model); } } } else { $res = $this->is_super_admin($this->user_id); if($res['code'] != 0){ return $res; } $model = User::findOne([ 'is_delete' => 0, 'status' => User::STATUS_NORMAL, 'id' => $this->user_id ]); if($model == null){ return [ 'code' => 1, 'msg' => '用户不存在' ]; } $model->status = User::STATUS_HANGUP; if(!$model->save()){ return $this->getModelError($model); } } return [ 'code' => 0, 'msg' => '操作成功' ]; } public function cancel_hangup() { if(!$this->validate()){ return $this->getModelError(); } if(is_array($this->user_id)){ foreach ($this->user_id as $user_id){ $res = $this->is_super_admin($user_id); if($res['code'] != 0){ return $res; } $model = User::findOne([ 'is_delete' => 0, 'status' => User::STATUS_HANGUP, 'id' => $user_id ]); if($model == null){ continue; } $model->status = User::STATUS_NORMAL; if(!$model->save()){ return $this->getModelError($model); } } } else { $res = $this->is_super_admin($this->user_id); if($res['code'] != 0){ return $res; } $model = User::findOne([ 'is_delete' => 0, 'status' => User::STATUS_HANGUP, 'id' => $this->user_id ]); if($model == null){ return [ 'code' => 1, 'msg' => '用户不存在' ]; } $model->status = User::STATUS_NORMAL; if(!$model->save()){ return $this->getModelError($model); } } return [ 'code' => 0, 'msg' => '操作成功' ]; } public function account_logout() { if(!$this->validate()){ return $this->getModelError(); } if(is_array($this->user_id)){ foreach ($this->user_id as $user_id){ $res = $this->is_super_admin($user_id); if($res['code'] != 0){ return $res; } $t = \Yii::$app->db->beginTransaction(); $model = User::findOne([ 'is_delete' => 0, 'status' => [User::STATUS_FORBIDDEN, User::STATUS_HANGUP], 'id' => $user_id ]); if($model == null){ continue; } $model->status = User::STATUS_ACCOUNT_LOGOUT; $model->is_delete = 1; if(!$model->save()){ $t->rollBack(); return $this->getModelError($model); } $this->accountLogoutAfter($user_id); $t->commit(); } } else { $res = $this->is_super_admin($this->user_id); if($res['code'] != 0){ return $res; } $t = \Yii::$app->db->beginTransaction(); $model = User::findOne([ 'is_delete' => 0, 'status' => [User::STATUS_FORBIDDEN, User::STATUS_HANGUP], 'id' => $this->user_id ]); if($model == null){ return [ 'code' => 1, 'msg' => '用户不存在' ]; } $model->status = User::STATUS_ACCOUNT_LOGOUT; $model->is_delete = 1; if(!$model->save()){ $t->rollBack(); return $this->getModelError($model); } $this->accountLogoutAfter($this->user_id); $t->commit(); } return [ 'code' => 0, 'msg' => '操作成功' ]; } private function is_super_admin($user_id) { if($user_id == 1){ return [ 'code' => 1, 'msg' => '没有操作权限' ]; } return [ 'code' => 0, 'msg' => 'ok' ]; } /** * 账号注销后续操作 */ private function accountLogoutAfter($user_id) { //取消关联第三方登录 UserOauth::updateAll(['is_delete' => 1],[ 'is_delete' => 0, 'user_id' => $user_id ]); //Token UserToken::updateAll(['is_delete' => 1],[ 'is_delete' => 0, 'user_id' => $user_id ]); } /** * 账号注销后续操作 */ private function accountLogoutAfterStoreUser($user_id) { //取消关联第三方登录 StoreUser::updateAll(['is_delete' => 1],[ 'is_delete' => 0, 'user_id' => $user_id ]); } public function logout() { if(!$this->validate()){ return $this->getModelError(); } if(is_array($this->user_id)){ foreach ($this->user_id as $user_id){ $t = \Yii::$app->db->beginTransaction(); $review = UserLogoutReview::findOne(['id' => $user_id,'status' => 0,'is_delete' => 0]); if($review == null){ return ['code' => 1, 'msg' => '申请记录不存在']; } $review->status = 1; $review->status_time = time(); if(!$review->save()){ $t->rollBack(); return $this->getModelError($review); } $res = $this->is_super_admin($review->user_id); if($res['code'] != 0){ $t->rollBack(); return $res; } $model = User::findOne([ 'is_delete' => 0, 'id' => $review->user_id ]); if($model == null){ continue; } $model->status = User::STATUS_ACCOUNT_LOGOUT; $model->is_delete = 1; if(!$model->save()){ $t->rollBack(); return $this->getModelError($model); } $this->accountLogoutAfter($review->user_id); $this->accountLogoutAfterStoreUser($review->user_id); $t->commit(); } } else { $t = \Yii::$app->db->beginTransaction(); $review = UserLogoutReview::findOne(['id' => $this->user_id,'status' => 0,'is_delete' => 0]); if($review == null){ return ['code' => 1, 'msg' => '申请记录不存在']; } $review->status = 1; $review->status_time = time(); if(!$review->save()){ $t->rollBack(); return $this->getModelError($review); } $res = $this->is_super_admin($review->user_id); if($res['code'] != 0){ return $res; } $model = User::findOne([ 'is_delete' => 0, 'id' => $review->user_id ]); if($model == null){ return [ 'code' => 1, 'msg' => '用户不存在' ]; } $model->status = User::STATUS_ACCOUNT_LOGOUT; $model->is_delete = 1; if(!$model->save()){ $t->rollBack(); return $this->getModelError($model); } $this->accountLogoutAfter($review->user_id); $this->accountLogoutAfterStoreUser($review->user_id); $t->commit(); } return [ 'code' => 0, 'msg' => '操作成功' ]; } //注销记录驳回 public function account_logout_review() { if(!$this->validate()){ return $this->getModelError(); } if(is_array($this->user_id)){ foreach ($this->user_id as $user_id){ $review = UserLogoutReview::findOne(['id' => $user_id,'status' => 0,'is_delete' => 0]); if($review == null){ return ['code' => 1, 'msg' => '申请记录不存在']; } $review->status = 2; $review->status_time = time(); if(!$review->save()){ return $this->getModelError($review); } } } else { $review = UserLogoutReview::findOne(['id' => $this->user_id,'status' => 0,'is_delete' => 0]); if($review == null){ return ['code' => 1, 'msg' => '申请记录不存在']; } $review->status = 2; $review->status_time = time(); if(!$review->save()){ return $this->getModelError($review); } } return [ 'code' => 0, 'msg' => '操作成功' ]; } // 变更为为观看视频 public function actionEditIsView(){ User::updateAll([ 'is_view' => 0, ],[ 'id' => $this->user_id, ]); return [ 'code' => 0, 'msg' => '操作成功' ]; } }