Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }