Example #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;
 }
Example #2
0
 public function run()
 {
     $tipsModel = ArrayHelper::map(RightLink::find()->where(['type' => RightLink::RIGHT_LINK_TYPE_TIPS])->all(), 'content', 'title');
     $tips = array_rand($tipsModel);
     $recommendResources = ArrayHelper::map(RightLink::find()->where(['type' => RightLink::RIGHT_LINK_TYPE_RSOURCES])->all(), 'title', 'url');
     $links = RightLink::find()->where(['type' => RightLink::RIGHT_LINK_TYPE_LINKS])->all();
     $sameTopics = [];
     if ($this->node) {
         $sameTopics = ArrayHelper::map(Topic::find()->where('status >= :status', [':status' => Topic::STATUS_ACTIVE])->andWhere(['post_meta_id' => $this->node->id, 'type' => 'topic'])->limit(200)->all(), 'title', function ($e) {
             return Url::to(['/topic/default/view', 'id' => $e->id]);
         });
         if (count($sameTopics) > 10) {
             $sameTopics = Arr::arrayRandomAssoc($sameTopics, 10);
         }
         if ($this->type == 'view' && (in_array($this->node->alias, params('donateNode')) || array_intersect(explode(',', $this->tags), params('donateTag')))) {
             $donate = Donate::findOne(['user_id' => Topic::findOne(['id' => request()->get('id')])->user_id, 'status' => Donate::STATUS_ACTIVE]);
         }
     }
     return $this->render('topicSidebar', ['category' => PostMeta::blogCategory(), 'config' => ['type' => $this->type, 'node' => $this->node], 'sameTopics' => $sameTopics, 'tips' => $tips, 'donate' => isset($donate) ? $donate : [], 'recommendResources' => $recommendResources, 'links' => $links]);
 }
 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;
 }