Пример #1
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;
 }
Пример #2
0
 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;
 }
Пример #3
0
 /**
  * 最新收藏
  * @param string $username
  * @return string
  * @throws NotFoundHttpException
  */
 public function actionFavorite($username = '')
 {
     $user = $this->user($username);
     $dataProvider = new ActiveDataProvider(['query' => UserMeta::find()->where(['user_id' => $user->id, 'type' => 'favorite', 'target_type' => 'topic'])->orderBy(['created_at' => SORT_DESC])]);
     return $this->render('show', ['user' => $user, 'dataProvider' => $dataProvider]);
 }
Пример #4
0
 /**
  * @param $userId
  * @param $type
  * @param string $targetType
  * @return ActiveDataProvider
  */
 protected function userMeta($userId, $type, $targetType = 'topic')
 {
     return new ActiveDataProvider(['query' => UserMeta::find()->where(['user_id' => $userId, 'type' => $type, 'target_type' => $targetType])->orderBy(['created_at' => SORT_DESC])]);
 }