Przeglądaj źródła

Merge branch 'develop'

wzq 5 lat temu
rodzic
commit
e44279f7a8

+ 70 - 0
app/Console/Commands/Tem/DelMemberRepeatTopic.php

@@ -0,0 +1,70 @@
+<?php
+namespace App\Console\Commands\Tem;
+
+
+use App\Models\MemberFollowTopic;
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\Log;
+
+class DelMemberRepeatTopic extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'topic:del_member_repeat_topic';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '删除重复用户话题';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct(MemberFollowTopic $memberFollowTopic)
+    {
+        parent::__construct();
+        $this->memberFollowTopic = $memberFollowTopic;
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        $this->line("开始删除重复用户话题");
+
+        $count = $this->memberFollowTopic->max('uid');
+        $bar = $this->output->createProgressBar($count);
+        $num = 0;
+        for($i=1;$i<=$count;$i++){
+            $topics = $this->memberFollowTopic->where('uid', $i)->get();
+            $ids = [];
+            foreach($topics as $topic){
+                if(in_array($topic->topic_id, $ids)){
+                    Log::info("删除重复用户话题uid{$topic->uid}topicId{$topic->topic_id}");
+                    $topic->delete();
+                }else{
+                    $ids[] = $topic->topic_id;
+                }
+            }
+            $bar->advance();
+            if($num>100){
+                usleep(50000);
+                $num = 0;
+            }
+            $num ++;
+        }
+        $bar->finish();
+        $this->line("\n删除重复用户话题结束");
+
+    }
+}

+ 2 - 0
app/Console/Kernel.php

@@ -10,6 +10,7 @@ use App\Console\Commands\ContentFeedDelete;
 use App\Console\Commands\DelPostNewReply;
 use App\Console\Commands\ExcellentResidents;
 use App\Console\Commands\RankingList;
+use App\Console\Commands\Tem\DelMemberRepeatTopic;
 use App\Console\Commands\Tem\DelPostNewComment;
 use Illuminate\Console\Scheduling\Schedule;
 use Laravel\Lumen\Console\Kernel as ConsoleKernel;
@@ -30,6 +31,7 @@ class Kernel extends ConsoleKernel
         ExcellentResidents::class,
         DelPostNewReply::class,
         DelPostNewComment::class,
+        DelMemberRepeatTopic::class,
         RankingList::class
     ];