/**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  *************************************************************
  * 创建USEINFO个人信息,而不再创建新用户
  *************************************************************
  * @return mixed
  */
 public function actionCreate($id)
 {
     $modelUser = $this->findModel($id);
     //var_export($modelUser->toArray());
     if (count($userinfo = UserInfo::find()->where(['username' => $modelUser->username])->all()) > 0) {
         exit('gaiyonhu esit');
     } else {
         $modelUserInfo = new UserInfo();
         $modelUserInfo->username = $modelUser->username;
         if ($modelUserInfo->save()) {
             return $this->render('create', ['model' => $modelUserInfo]);
         } else {
             return $modelUserInfo->save();
             // exit($modelUserInfo->username);
             //  return $this->render('create',['model'=>$modelUserInfo]);
         }
     }
     // if ($model->load(Yii::$app->request->post()) && $model->save()) {
     //     return $this->redirect(['view', 'id' => $model->id]);
     // } else {
     //     return $this->render('create', [
     //         'model' => $model,
     //     ]);
     // }
 }
Exemple #2
0
 public function actionUserInfo()
 {
     UserInfo::updateAll(['thanks_count' => 0, 'like_count' => 0, 'hate_count' => 0]);
     $meta = UserMeta::find()->all();
     foreach ($meta as $key => $value) {
         if (in_array($value->type, ['thanks', 'like', 'hate'])) {
             switch ($value->target_type) {
                 case 'topic':
                 case 'post':
                     $this->stdout("同步文章操作……\n");
                     $topic = Topic::findOne($value->target_id);
                     if (UserInfo::updateAllCounters([$value->type . '_count' => 1], ['user_id' => $topic->user_id])) {
                         $this->stdout("同步评论成功`(*∩_∩*)′\n");
                     } else {
                         $this->stdout("同步评论失败::>_<::\n");
                     }
                     break;
                 case 'comment':
                     $this->stdout("同步评论操作……\n");
                     $comment = PostComment::findOne($value->target_id);
                     if (UserInfo::updateAllCounters([$value->type . '_count' => 1], ['user_id' => $comment->user_id])) {
                         $this->stdout("同步评论成功`(*∩_∩*)′\n");
                     } else {
                         $this->stdout("同步评论失败::>_<:: \n");
                     }
                     break;
                 default:
                     # code...
                     break;
             }
         }
     }
     return;
 }
 /**
  * 创建评论
  * @param $id
  * @return PostComment|\yii\web\Response
  */
 public function actionCreate($id)
 {
     $post = Topic::findTopic($id);
     $model = new PostComment();
     if ($model->load(Yii::$app->request->post())) {
         $topService = new TopicService();
         if (!$topService->filterContent($model->comment)) {
             $this->flash('回复内容请勿回复无意义的内容,如你想收藏或赞等功能,请直接操作这篇帖子。', 'warning');
             return $this->redirect(['/topic/default/view', 'id' => $id]);
         }
         $model->user_id = Yii::$app->user->id;
         $model->post_id = $id;
         $model->ip = Yii::$app->getRequest()->getUserIP();
         $rawComment = $model->comment;
         $model->comment = $model->replace($rawComment);
         if ($model->save()) {
             (new UserMeta())->saveNewMeta('topic', $id, 'follow');
             (new NotificationService())->newReplyNotify(Yii::$app->user->identity, $post, $model, $rawComment);
             // 更新回复时间
             $post->lastCommentToUpdate(Yii::$app->user->identity->username);
             // 评论计数器
             Topic::updateAllCounters(['comment_count' => 1], ['id' => $post->id]);
             // 更新个人总统计
             UserInfo::updateAllCounters(['comment_count' => 1], ['user_id' => $model->user_id]);
             $this->flash("评论成功", 'success');
         } else {
             $this->flash(array_values($model->getFirstErrors())[0], 'warning');
         }
         return $this->redirect(['/topic/default/view', 'id' => $post->id]);
     }
     return $model;
 }
 /**
  * 修改个人资料
  * @return mixed
  */
 public function actionProfile()
 {
     $model = UserInfo::findOne(['user_id' => Yii::$app->user->id]);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $this->flash('更新成功', 'success');
         return $this->refresh();
     }
     return $this->render('profile', ['model' => $model]);
 }
 static function getUserInfoList()
 {
     $data = UserInfo::find()->all();
     $userInfoList = array();
     foreach ($data as $key => $value) {
         $userInfoList[$value['username']] = $value['name'];
     }
     return $userInfoList;
 }
 /**
  * Shows user's profile.
  * @param  string $username
  * @return \yii\web\Response
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionShow($username = '')
 {
     $user = $this->user($username);
     // 个人主页浏览次数
     $currentUserId = \Yii::$app->getUser()->getId();
     if (null != $currentUserId && $user->id != $currentUserId) {
         UserInfo::updateAllCounters(['view_count' => 1], ['user_id' => $user->id]);
     }
     return $this->render('show', ['user' => $user, 'dataProvider' => $this->comment($user->id)]);
 }
 public function actionSignup()
 {
     $model = new SignupForm();
     $modelInfo = new UserInfo();
     if ($model->load(Yii::$app->request->post()) && $modelInfo->load(Yii::$app->request->post())) {
         $modelInfo->username = $model->username;
         if (($user = $model->signup()) && $modelInfo->save()) {
             // if (Yii::$app->getUser()->login($user)) {
             //     return $this->goHome();
             // }
             return $this->render('hint', ['hint' => '注册成功,请联系信息技术中心激活账号,然后才能访问系统!']);
         } else {
             if ($user) {
                 $user->delete();
                 //  exit('注册失败,请联系管理员解决问题或者仔细检查输入信息');
             }
         }
     }
     return $this->render('signup', ['model' => $model, 'modelInfo' => $modelInfo]);
 }
Exemple #8
0
 /**
  * 登陆之后更新用户资料
  * @return bool
  */
 public function updateUserInfo()
 {
     $model = UserInfo::findOne(['user_id' => Yii::$app->user->getId()]);
     $model->login_count += 1;
     $model->prev_login_time = $model->last_login_time;
     $model->prev_login_ip = $model->last_login_ip;
     $model->last_login_time = time();
     $model->last_login_ip = Yii::$app->getRequest()->getUserIP();
     if ($model->save()) {
         return true;
     } else {
         return false;
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = UserInfo::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'idcard', $this->idcard])->andFilterWhere(['like', 'level', $this->level])->andFilterWhere(['like', 'graduation', $this->graduation])->andFilterWhere(['like', 'degree', $this->degree])->andFilterWhere(['like', 'intro', $this->intro]);
     return $dataProvider;
 }
 public function generateFakeData($num)
 {
     Console::startProgress(0, 100);
     $topic = new Topic();
     $comment = new PostComment();
     $node = new PostMeta();
     $faker = Faker\Factory::create('zh_CN');
     $nodeData = [['name' => '分享', 'alias' => '', 'parent' => 0], ['name' => '招聘', 'alias' => 'jobs', 'parent' => 1], ['name' => '瞎扯淡', 'alias' => 'booshit', 'parent' => 1], ['name' => '健康', 'alias' => 'health', 'parent' => 1], ['name' => '创业', 'alias' => 'startup', 'parent' => 1]];
     $transaction = Yii::$app->db->beginTransaction();
     try {
         for ($j = 0; $j < count($nodeData); $j++) {
             $_node = clone $node;
             $_node->setAttributes($nodeData[$j] + ['type' => 'topic_category']);
             $_node->save();
         }
         $this->execute("INSERT INTO {{%merit_template}} (`id`, `type`, `title`, `unique_id`, `method`, `event`, `action_type`, `rule_key`, `rule_value`, `increment`, `status`, `created_at`, `updated_at`) VALUES\n(1, 1, '登录', 'site/login', 2, 0, 2, 1, 1, 2, 1, 1458657160, 1458823425),\n(2, 1, '发帖', 'topic/default/create', 2, 0, 2, 0, NULL, 6, 1, 1458657218, 1458657218),\n(3, 1, '回复', 'topic/comment/create', 2, 0, 2, 0, NULL, 4, 1, 1458657251, 1458657251),\n(4, 1, '发动弹', 'tweet/default/create', 2, 0, 2, 0, NULL, 4, 1, 1458657296, 1468647701);\n");
         /** @var User $user */
         $user = User::find()->where(['role' => User::ROLE_SUPER_ADMIN])->one();
         Yii::$app->user->setIdentity($user);
         for ($i = 1; $i <= $num; $i++) {
             $_topic = clone $topic;
             $_topic->setAttributes(['type' => Topic::TYPE, 'title' => $faker->text(rand(10, 50)), 'post_meta_id' => rand(2, 4), 'status' => rand(1, 2), 'content' => $faker->text(rand(100, 2000)), 'user_id' => 1]);
             if (!$_topic->save()) {
                 throw new Exception(array_values($_topic->getFirstErrors())[0]);
             }
             for ($_i = 1; $_i <= rand(1, 20); $_i++) {
                 $_comment = clone $comment;
                 $_comment->setAttributes(['comment' => $faker->text(rand(100, 2000)), 'post_id' => $_topic->id, 'ip' => '127.0.0.1', 'user_id' => 1]);
                 if (!$_comment->save()) {
                     throw new Exception(array_values($_comment->getFirstErrors())[0]);
                 }
                 // 更新回复时间
                 $_topic->lastCommentToUpdate($user['username']);
                 // 评论计数器
                 Topic::updateAllCounters(['comment_count' => 1], ['id' => $_topic->id]);
                 // 更新个人总统计
                 UserInfo::updateAllCounters(['comment_count' => 1], ['user_id' => $_topic->user_id]);
             }
             Console::updateProgress($i / $num * 100, 100);
         }
         $transaction->commit();
     } catch (\Exception $e) {
         $transaction->rollBack();
         throw $e;
     }
     Console::endProgress();
 }
 public static function createRecord($model, $record)
 {
     $handleRecord = new Reqhandlerecord();
     $handleRecord->setAttributes($record);
     $handleRecord->reqform = $model->id;
     if ($name = UserInfo::getName(Yii::$app->user->identity->username)) {
         $handleRecord->handler = $name;
     } else {
         $handleRecord->handler = Yii::$app->user->identity->username;
     }
     $handleRecord->createtime = time();
     // $handleRecord->save();
     if ($handleRecord->save()) {
         return true;
     } else {
         var_export($handleRecord);
         exit('save error');
     }
 }
Exemple #12
0
 /**
  * 登陆之后更新用户资料
  * @return bool
  */
 public function updateUserInfo()
 {
     /** @var UserInfo $model */
     $model = UserInfo::findOne(['user_id' => Yii::$app->user->getId()]);
     $model->login_count += 1;
     $model->prev_login_time = $model->last_login_time;
     $model->prev_login_ip = $model->last_login_ip;
     $model->last_login_time = time();
     $model->last_login_ip = Yii::$app->getRequest()->getUserIP();
     if (!Yii::$app->session->isActive) {
         Yii::$app->session->open();
     }
     $model->session_id = Yii::$app->session->id;
     Yii::$app->session->close();
     if ($model->save()) {
         return true;
     } else {
         return false;
     }
 }
 public function generateFakeData($num)
 {
     Console::startProgress(0, 100);
     $topic = new Topic();
     $comment = new PostComment();
     $node = new PostMeta();
     $faker = Faker\Factory::create('zh_CN');
     $nodeData = [['name' => '分享', 'alias' => '', 'parent' => 0], ['name' => '招聘', 'alias' => 'recruit', 'parent' => 1], ['name' => '瞎扯淡', 'alias' => 'booshit', 'parent' => 1], ['name' => '健康', 'alias' => 'health', 'parent' => 1], ['name' => '创业', 'alias' => 'startup', 'parent' => 1]];
     for ($j = 0; $j < count($nodeData); $j++) {
         $_node = clone $node;
         $_node->setAttributes($nodeData[$j] + ['type' => 'topic_category']);
         $_node->save();
     }
     $user = User::find()->where(['role' => User::ROLE_SUPER_ADMIN])->one();
     for ($i = 1; $i <= $num; $i++) {
         $_topic = clone $topic;
         $_topic->setAttributes(['type' => Topic::TYPE, 'title' => $faker->text(rand(10, 50)), 'post_meta_id' => rand(2, 4), 'status' => rand(1, 2), 'content' => $faker->text(rand(100, 2000)), 'user_id' => 1]);
         if (!$_topic->save()) {
             throw new Exception(array_values($_topic->getFirstErrors())[0]);
         }
         for ($_i = 1; $_i <= rand(1, 20); $_i++) {
             $_comment = clone $comment;
             $_comment->setAttributes(['comment' => $faker->text(rand(100, 2000)), 'post_id' => $_topic->id, 'ip' => '127.0.0.1', 'user_id' => 1]);
             if (!$_comment->save()) {
                 throw new Exception(array_values($_comment->getFirstErrors())[0]);
             }
             // 更新回复时间
             $_topic->lastCommentToUpdate($user['username']);
             // 评论计数器
             Topic::updateAllCounters(['comment_count' => 1], ['id' => $_topic->id]);
             // 更新个人总统计
             UserInfo::updateAllCounters(['comment_count' => 1], ['user_id' => $_topic->user_id]);
         }
         Console::updateProgress($i / $num * 100, 100);
     }
     Console::endProgress();
 }
Exemple #14
0
 public function getUserInfo()
 {
     return $this->hasOne(UserInfo::className(), ['user_id' => 'user_id']);
 }
 /**
  * Finds the UserInfo model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return UserInfo the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = UserInfo::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function actionSync()
 {
     UserInfo::updateAll(['thanks_count' => 0, 'like_count' => 0, 'hate_count' => 0]);
     $meta = UserMeta::find()->all();
     foreach ($meta as $key => $value) {
         if (in_array($value->type, ['thanks', 'like', 'hate'])) {
             switch ($value->target_type) {
                 case 'topic':
                 case 'post':
                     echo '同步文章操作</br>';
                     $topic = Topic::findOne($value->target_id);
                     UserInfo::updateAllCounters([$value->type . '_count' => 1], ['user_id' => $topic->user_id]);
                     break;
                 case 'comment':
                     echo '同步评论操作</br>';
                     $comment = PostComment::findOne($value->target_id);
                     UserInfo::updateAllCounters([$value->type . '_count' => 1], ['user_id' => $comment->user_id]);
                     break;
                 default:
                     # code...
                     break;
             }
         }
     }
     return;
 }
Exemple #17
0
 /** @inheritdoc */
 public function afterSave($insert, $changedAttributes)
 {
     if ($insert) {
         $time = time();
         $ip = isset(Yii::$app->request->userIP) ? Yii::$app->request->userIP : '127.0.0.1';
         $userInfo = Yii::createObject(['class' => UserInfo::className(), 'user_id' => $this->id, 'prev_login_time' => $time, 'prev_login_ip' => $ip, 'last_login_time' => $time, 'last_login_ip' => $ip, 'created_at' => $time, 'updated_at' => $time]);
         $userInfo->save();
     }
     parent::afterSave($insert, $changedAttributes);
 }
Exemple #18
0
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     $post = $this->topic;
     (new UserMeta())->saveNewMeta('topic', $this->post_id, 'follow');
     (new NotificationService())->newReplyNotify(\Yii::$app->user->identity, $post, $this, $this->atUsers);
     // 更新回复时间
     $post->lastCommentToUpdate(\Yii::$app->user->identity->username);
     if ($insert) {
         // 评论计数器
         Topic::updateAllCounters(['comment_count' => 1], ['id' => $post->id]);
         // 更新个人总统计
         UserInfo::updateAllCounters(['comment_count' => 1], ['user_id' => $this->user_id]);
     }
     \Yii::$app->cache->set('comment' . $this->id, $this, 0);
 }
Exemple #19
0
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     if (isset(Yii::$app->params['setting']) && Yii::$app->params['setting']['xunsearch']) {
         if ($insert) {
             $search = new Search();
             $search->topic_id = $this->id;
             $search->status = self::STATUS_ACTIVE;
         } else {
             $search = Search::findOne($this->id);
             if (!$search) {
                 // 如果立即修改 会因为在 xunsearch 找不到而不能 save
                 return false;
             }
             $search->status = $this->status;
         }
         $search->title = $this->title;
         $search->content = $this->content;
         $search->updated_at = $this->updated_at;
         $search->save();
     }
     (new NotificationService())->newPostNotify(\Yii::$app->user->identity, $this, $this->atUsers);
     if ($insert) {
         // 保存 meta data
         (new UserMeta())->saveNewMeta('topic', $this->id, 'follow');
         // 更新个人总统计
         UserInfo::updateAllCounters(['post_count' => 1], ['user_id' => $this->user_id]);
     }
 }
Exemple #20
0
 /**
  * 喝倒彩或者赞
  * @param User $user
  * @param Post $model
  * @param $action 动作
  * @return array
  */
 protected static function toggleType(User $user, Post $model, $action)
 {
     $data = ['target_id' => $model->id, 'target_type' => $model::TYPE, 'user_id' => $user->id, 'value' => '1'];
     if (!UserMeta::deleteOne($data + ['type' => $action])) {
         // 删除数据有行数则代表有数据,无行数则添加数据
         $userMeta = new UserMeta();
         $userMeta->setAttributes($data + ['type' => $action]);
         $result = $userMeta->save();
         if ($result) {
             // 如果是新增数据, 删除掉Hate的同类型数据
             $attributeName = $action == 'like' ? 'hate' : 'like';
             $attributes = [$action . '_count' => 1];
             if (UserMeta::deleteOne($data + ['type' => $attributeName])) {
                 // 如果有删除hate数据, hate_count也要-1
                 $attributes[$attributeName . '_count'] = -1;
             }
             //更新版块统计
             $model->updateCounters($attributes);
             // 更新个人总统计
             UserInfo::updateAllCounters($attributes, ['user_id' => $model->user_id]);
         }
         return [$result, $userMeta];
     }
     $model->updateCounters([$action . '_count' => -1]);
     UserInfo::updateAllCounters([$action . '_count' => -1], ['user_id' => $model->user_id]);
     return [true, null];
 }
Exemple #21
0
 /**
  * 新建话题
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Topic();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $topService = new TopicService();
         if (!$topService->filterContent($model->title) || !$topService->filterContent($model->content)) {
             $this->flash('请勿发表无意义的内容', 'warning');
             return $this->redirect('create');
         }
         $model->user_id = Yii::$app->user->id;
         $model->type = 'topic';
         if ($model->tags) {
             $model->addTags(explode(',', $model->tags));
         }
         $rawContent = $model->content;
         $model->content = TopicService::replace($rawContent);
         if ($model->save()) {
             (new UserMeta())->saveNewMeta('topic', $model->id, 'follow');
             (new NotificationService())->newPostNotify(Yii::$app->user->identity, $model, $rawContent);
             // 更新个人总统计
             UserInfo::updateAllCounters(['post_count' => 1], ['user_id' => $model->user_id]);
             $this->flash('发表文章成功!', 'success');
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }